mirror of
https://github.com/minetest-mods/technic.git
synced 2024-11-14 14:30:44 +01:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
2a8feb6bf5
|
@ -1,26 +1,36 @@
|
||||||
-- Forcefield mod by ShadowNinja
|
--- Forcefield generator.
|
||||||
-- Modified by kpoppel
|
-- @author ShadowNinja
|
||||||
--
|
--
|
||||||
-- Forcefields are powerful barriers but they consume huge amounts of power.
|
-- Forcefields are powerful barriers but they consume huge amounts of power.
|
||||||
-- Forcefield Generator is a HV machine.
|
-- The forcefield Generator is an HV machine.
|
||||||
|
|
||||||
-- How expensive is the generator?
|
-- How expensive is the generator?
|
||||||
-- Leaves room for upgrades lowering the power drain?
|
-- Leaves room for upgrades lowering the power drain?
|
||||||
local forcefield_power_drain = 10
|
local forcefield_power_drain = 10
|
||||||
local forcefield_step_interval = 1
|
|
||||||
|
|
||||||
local S = technic.getter
|
local S = technic.getter
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'technic:forcefield_emitter_off',
|
output = "technic:forcefield_emitter_off",
|
||||||
recipe = {
|
recipe = {
|
||||||
{'default:mese', 'technic:motor', 'default:mese' },
|
{"default:mese", "technic:motor", "default:mese" },
|
||||||
{'technic:deployer_off', 'technic:machine_casing', 'technic:deployer_off'},
|
{"technic:deployer_off", "technic:machine_casing", "technic:deployer_off"},
|
||||||
{'default:mese', 'technic:hv_cable0', 'default:mese' },
|
{"default:mese", "technic:hv_cable0", "default:mese" },
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
local replaceable_cids = {}
|
||||||
|
|
||||||
|
minetest.after(0, function()
|
||||||
|
for name, ndef in pairs(minetest.registered_nodes) do
|
||||||
|
if ndef.buildable_to == true and name ~= "ignore" then
|
||||||
|
replaceable_cids[minetest.get_content_id(name)] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
-- Idea: Let forcefields have different colors by upgrade slot.
|
-- Idea: Let forcefields have different colors by upgrade slot.
|
||||||
-- Idea: Let forcefields add up by detecting if one hits another.
|
-- Idea: Let forcefields add up by detecting if one hits another.
|
||||||
-- ___ __
|
-- ___ __
|
||||||
|
@ -28,28 +38,28 @@ minetest.register_craft({
|
||||||
-- | |
|
-- | |
|
||||||
-- \___/\___/
|
-- \___/\___/
|
||||||
|
|
||||||
local function update_forcefield(pos, meta, active)
|
local function update_forcefield(pos, meta, active, first)
|
||||||
local shape = meta:get_int("shape")
|
local shape = meta:get_int("shape")
|
||||||
local range = meta:get_int("range")
|
local range = meta:get_int("range")
|
||||||
local vm = VoxelManip()
|
local vm = VoxelManip()
|
||||||
local p1 = {x = pos.x-range, y = pos.y-range, z = pos.z-range}
|
local MinEdge, MaxEdge = vm:read_from_map(vector.subtract(pos, range),
|
||||||
local p2 = {x = pos.x+range, y = pos.y+range, z = pos.z+range}
|
vector.add(pos, range))
|
||||||
local MinEdge, MaxEdge = vm:read_from_map(p1, p2)
|
|
||||||
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
|
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
|
||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
|
|
||||||
local c_air = minetest.get_content_id("air")
|
local c_air = minetest.get_content_id("air")
|
||||||
local c_field = minetest.get_content_id("technic:forcefield")
|
local c_field = minetest.get_content_id("technic:forcefield")
|
||||||
|
|
||||||
for z=-range, range do
|
for z = -range, range do
|
||||||
for y=-range, range do
|
for y = -range, range do
|
||||||
local vi = area:index(pos.x+(-range), pos.y+y, pos.z+z)
|
local vi = area:index(pos.x + (-range), pos.y + y, pos.z + z)
|
||||||
for x=-range, range do
|
for x = -range, range do
|
||||||
local relevant
|
local relevant
|
||||||
if shape == 0 then
|
if shape == 0 then
|
||||||
|
local squared = x * x + y * y + z * z
|
||||||
relevant =
|
relevant =
|
||||||
x*x+y*y+z*z <= range * range + range and
|
squared <= range * range + range and
|
||||||
x*x+y*y+z*z >= (range-1) * (range-1) + (range-1)
|
squared >= (range - 1) * (range - 1) + (range - 1)
|
||||||
else
|
else
|
||||||
relevant =
|
relevant =
|
||||||
x == -range or x == range or
|
x == -range or x == range or
|
||||||
|
@ -57,9 +67,10 @@ local function update_forcefield(pos, meta, active)
|
||||||
z == -range or z == range
|
z == -range or z == range
|
||||||
end
|
end
|
||||||
if relevant then
|
if relevant then
|
||||||
if active and data[vi] == c_air then
|
local cid = data[vi]
|
||||||
|
if active and replaceable_cids[cid] then
|
||||||
data[vi] = c_field
|
data[vi] = c_field
|
||||||
elseif not active and data[vi] == c_field then
|
elseif not active and cid == c_field then
|
||||||
data[vi] = c_air
|
data[vi] = c_air
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -71,7 +82,11 @@ local function update_forcefield(pos, meta, active)
|
||||||
vm:set_data(data)
|
vm:set_data(data)
|
||||||
vm:update_liquids()
|
vm:update_liquids()
|
||||||
vm:write_to_map()
|
vm:write_to_map()
|
||||||
vm:update_map()
|
-- update_map is very slow, but if we don't call it we'll
|
||||||
|
-- get phantom blocks on the client.
|
||||||
|
if not active or first then
|
||||||
|
vm:update_map()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_forcefield_formspec(meta)
|
local function set_forcefield_formspec(meta)
|
||||||
|
@ -135,7 +150,7 @@ local mesecons = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local run = function(pos, node, active_object_count, active_object_count_wider)
|
local function run(pos, node)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local eu_input = meta:get_int("HV_EU_input")
|
local eu_input = meta:get_int("HV_EU_input")
|
||||||
local enabled = meta:get_int("enabled") ~= 0 and (meta:get_int("mesecon_mode") == 0 or meta:get_int("mesecon_effect") ~= 0)
|
local enabled = meta:get_int("enabled") ~= 0 and (meta:get_int("mesecon_mode") == 0 or meta:get_int("mesecon_effect") ~= 0)
|
||||||
|
@ -167,11 +182,13 @@ local run = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
technic.swap_node(pos, "technic:forcefield_emitter_off")
|
technic.swap_node(pos, "technic:forcefield_emitter_off")
|
||||||
end
|
end
|
||||||
elseif eu_input >= power_requirement then
|
elseif eu_input >= power_requirement then
|
||||||
|
local first = false
|
||||||
if node.name == "technic:forcefield_emitter_off" then
|
if node.name == "technic:forcefield_emitter_off" then
|
||||||
|
first = true
|
||||||
technic.swap_node(pos, "technic:forcefield_emitter_on")
|
technic.swap_node(pos, "technic:forcefield_emitter_on")
|
||||||
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
||||||
end
|
end
|
||||||
update_forcefield(pos, meta, true)
|
update_forcefield(pos, meta, true, first)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -128,36 +128,43 @@ minetest.register_alias("technic:diamond", "default:diamond")
|
||||||
minetest.register_alias("technic:mineral_diamond", "default:stone_with_diamond")
|
minetest.register_alias("technic:mineral_diamond", "default:stone_with_diamond")
|
||||||
|
|
||||||
local function for_each_registered_node(action)
|
local function for_each_registered_node(action)
|
||||||
local already_reg = {}
|
|
||||||
for k, _ in pairs(minetest.registered_nodes) do
|
|
||||||
table.insert(already_reg, k)
|
|
||||||
end
|
|
||||||
local really_register_node = minetest.register_node
|
local really_register_node = minetest.register_node
|
||||||
minetest.register_node = function(name, def)
|
minetest.register_node = function(name, def)
|
||||||
really_register_node(name, def)
|
really_register_node(name, def)
|
||||||
action(string.gsub(name, "^:", ""))
|
action(name:gsub("^:", ""), def)
|
||||||
end
|
end
|
||||||
for _, name in ipairs(already_reg) do
|
for name, def in pairs(minetest.registered_nodes) do
|
||||||
action(name)
|
action(name, def)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for_each_registered_node(function(node_name)
|
for_each_registered_node(function(node_name, node_def)
|
||||||
local node_def = minetest.registered_nodes[node_name]
|
if node_name ~= "default:steelblock" and
|
||||||
if node_name ~= "default:steelblock" and string.find(node_name, "steelblock") and string.find(node_def.description, "Steel") then
|
node_name:find("steelblock", 1, true) and
|
||||||
minetest.override_item(node_name, { description = string.gsub(node_def.description, "Steel", S("Wrought Iron")) })
|
node_def.description:find("Steel", 1, true) then
|
||||||
|
minetest.override_item(node_name, {
|
||||||
|
description = node_def.description:gsub("Steel", S("Wrought Iron")),
|
||||||
|
})
|
||||||
end
|
end
|
||||||
if node_def.tiles or node_def.tile_images then
|
local tiles = node_def.tiles or node_def.tile_images
|
||||||
local tn = node_def.tiles and "tiles" or "tile_images"
|
if tiles then
|
||||||
local tl = {}
|
local new_tiles = {}
|
||||||
local ca = false
|
local do_override = false
|
||||||
for i, t in ipairs(node_def[tn]) do
|
if type(tiles) == "string" then
|
||||||
|
tiles = {tiles}
|
||||||
|
end
|
||||||
|
for i, t in ipairs(tiles) do
|
||||||
if type(t) == "string" and t == "default_steel_block.png" then
|
if type(t) == "string" and t == "default_steel_block.png" then
|
||||||
ca = true
|
do_override = true
|
||||||
t = "technic_wrought_iron_block.png"
|
t = "technic_wrought_iron_block.png"
|
||||||
end
|
end
|
||||||
table.insert(tl, t)
|
table.insert(new_tiles, t)
|
||||||
|
end
|
||||||
|
if do_override then
|
||||||
|
minetest.override_item(node_name, {
|
||||||
|
tiles = new_tiles
|
||||||
|
})
|
||||||
end
|
end
|
||||||
if ca then minetest.override_item(node_name, { [tn] = tl }) end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user