2013-07-17 21:34:35 +02:00
|
|
|
-- Forcefield mod by ShadowNinja
|
|
|
|
-- Modified by kpoppel
|
|
|
|
--
|
|
|
|
-- Forcefields are powerful barriers but they consume huge amounts of power.
|
|
|
|
-- Forcefield Generator is a HV machine.
|
|
|
|
|
|
|
|
-- How expensive is the generator?
|
|
|
|
-- Leaves room for upgrades lowering the power drain?
|
|
|
|
local forcefield_power_drain = 10
|
|
|
|
local forcefield_step_interval = 1
|
|
|
|
|
2013-10-30 18:45:32 +01:00
|
|
|
local S = technic.getter
|
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
minetest.register_craft({
|
|
|
|
output = 'technic:forcefield_emitter_off',
|
|
|
|
recipe = {
|
2014-07-06 18:13:11 +02:00
|
|
|
{'default:mese', 'technic:motor', 'default:mese' },
|
|
|
|
{'technic:deployer_off', 'technic:machine_casing', 'technic:deployer_off'},
|
2014-07-06 19:45:16 +02:00
|
|
|
{'default:mese', 'technic:hv_cable0', 'default:mese' },
|
2013-07-17 21:34:35 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- Idea: Let forcefields have different colors by upgrade slot.
|
|
|
|
-- Idea: Let forcefields add up by detecting if one hits another.
|
|
|
|
-- ___ __
|
|
|
|
-- / \/ \
|
|
|
|
-- | |
|
|
|
|
-- \___/\___/
|
|
|
|
|
|
|
|
local function update_forcefield(pos, range, active)
|
|
|
|
local vm = VoxelManip()
|
|
|
|
local p1 = {x = pos.x-range, y = pos.y-range, z = pos.z-range}
|
|
|
|
local p2 = {x = pos.x+range, y = pos.y+range, z = pos.z+range}
|
|
|
|
local MinEdge, MaxEdge = vm:read_from_map(p1, p2)
|
|
|
|
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
|
|
|
|
local data = vm:get_data()
|
|
|
|
|
|
|
|
local c_air = minetest.get_content_id("air")
|
|
|
|
local c_field = minetest.get_content_id("technic:forcefield")
|
|
|
|
|
|
|
|
for z=-range, range do
|
|
|
|
for y=-range, range do
|
|
|
|
local vi = area:index(pos.x+(-range), pos.y+y, pos.z+z)
|
|
|
|
for x=-range, range do
|
|
|
|
if x*x+y*y+z*z <= range * range + range and
|
|
|
|
x*x+y*y+z*z >= (range-1) * (range-1) + (range-1) then
|
|
|
|
if active and data[vi] == c_air then
|
|
|
|
data[vi] = c_field
|
|
|
|
elseif not active and data[vi] == c_field then
|
|
|
|
data[vi] = c_air
|
|
|
|
end
|
|
|
|
end
|
|
|
|
vi = vi + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
vm:set_data(data)
|
|
|
|
vm:update_liquids()
|
|
|
|
vm:write_to_map()
|
|
|
|
vm:update_map()
|
|
|
|
end
|
|
|
|
|
2014-07-03 00:59:53 +02:00
|
|
|
local function set_forcefield_formspec(meta)
|
2014-07-16 00:42:27 +02:00
|
|
|
local formspec = "size[5,2.25]"..
|
|
|
|
"field[2,0.5;2,1;range;"..S("Range")..";"..meta:get_int("range").."]"
|
|
|
|
-- The names for these toggle buttons are explicit about which
|
|
|
|
-- state they'll switch to, so that multiple presses (arising
|
|
|
|
-- from the ambiguity between lag and a missed press) only make
|
|
|
|
-- the single change that the user expects.
|
2014-07-14 15:58:59 +02:00
|
|
|
if meta:get_int("mesecon_mode") == 0 then
|
2014-07-16 00:42:27 +02:00
|
|
|
formspec = formspec.."button[0,1;5,1;mesecon_mode_1;"..S("Ignoring Mesecon Signal").."]"
|
2014-07-14 15:58:59 +02:00
|
|
|
else
|
2014-07-16 00:42:27 +02:00
|
|
|
formspec = formspec.."button[0,1;5,1;mesecon_mode_0;"..S("Controlled by Mesecon Signal").."]"
|
2014-07-14 15:58:59 +02:00
|
|
|
end
|
2014-07-03 00:59:53 +02:00
|
|
|
if meta:get_int("enabled") == 0 then
|
2014-07-16 00:42:27 +02:00
|
|
|
formspec = formspec.."button[0,1.75;5,1;enable;"..S("%s Disabled"):format(S("%s Forcefield Emitter"):format("HV")).."]"
|
2014-07-03 00:59:53 +02:00
|
|
|
else
|
2014-07-16 00:42:27 +02:00
|
|
|
formspec = formspec.."button[0,1.75;5,1;disable;"..S("%s Enabled"):format(S("%s Forcefield Emitter"):format("HV")).."]"
|
2014-07-03 00:59:53 +02:00
|
|
|
end
|
|
|
|
meta:set_string("formspec", formspec)
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local forcefield_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2014-07-03 00:59:53 +02:00
|
|
|
if fields.range then
|
|
|
|
local range = tonumber(fields.range) or 0
|
|
|
|
-- Smallest field is 5. Anything less is asking for trouble.
|
|
|
|
-- Largest is 20. It is a matter of pratical node handling.
|
|
|
|
-- At the maximim range updating the forcefield takes about 0.2s
|
|
|
|
range = math.max(range, 5)
|
|
|
|
range = math.min(range, 20)
|
|
|
|
if meta:get_int("range") ~= range then
|
|
|
|
update_forcefield(pos, meta:get_int("range"), false)
|
|
|
|
meta:set_int("range", range)
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
end
|
2014-07-03 00:59:53 +02:00
|
|
|
if fields.enable then meta:set_int("enabled", 1) end
|
|
|
|
if fields.disable then meta:set_int("enabled", 0) end
|
2014-07-14 15:58:59 +02:00
|
|
|
if fields.mesecon_mode_0 then meta:set_int("mesecon_mode", 0) end
|
|
|
|
if fields.mesecon_mode_1 then meta:set_int("mesecon_mode", 1) end
|
2014-07-03 00:59:53 +02:00
|
|
|
set_forcefield_formspec(meta)
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local mesecons = {
|
|
|
|
effector = {
|
|
|
|
action_on = function(pos, node)
|
2014-07-14 15:58:59 +02:00
|
|
|
minetest.get_meta(pos):set_int("mesecon_effect", 1)
|
2013-07-17 21:34:35 +02:00
|
|
|
end,
|
|
|
|
action_off = function(pos, node)
|
2014-07-14 15:58:59 +02:00
|
|
|
minetest.get_meta(pos):set_int("mesecon_effect", 0)
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-11 11:00:46 +02:00
|
|
|
local run = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local eu_input = meta:get_int("HV_EU_input")
|
|
|
|
local eu_demand = meta:get_int("HV_EU_demand")
|
2014-07-16 00:42:27 +02:00
|
|
|
local enabled = meta:get_int("enabled") ~= 0 and (meta:get_int("mesecon_mode") == 0 or meta:get_int("mesecon_effect") ~= 0)
|
2014-07-11 11:00:46 +02:00
|
|
|
local machine_name = S("%s Forcefield Emitter"):format("HV")
|
|
|
|
|
|
|
|
local power_requirement = math.floor(
|
|
|
|
4 * math.pi * math.pow(meta:get_int("range"), 2)
|
|
|
|
) * forcefield_power_drain
|
|
|
|
|
2014-07-14 15:58:59 +02:00
|
|
|
if not enabled then
|
2014-07-11 11:00:46 +02:00
|
|
|
if node.name == "technic:forcefield_emitter_on" then
|
|
|
|
meta:set_int("HV_EU_demand", 0)
|
|
|
|
update_forcefield(pos, meta:get_int("range"), false)
|
|
|
|
technic.swap_node(pos, "technic:forcefield_emitter_off")
|
|
|
|
meta:set_string("infotext", S("%s Disabled"):format(machine_name))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
elseif eu_input < power_requirement then
|
|
|
|
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
|
|
|
if node.name == "technic:forcefield_emitter_on" then
|
|
|
|
update_forcefield(pos, meta:get_int("range"), false)
|
|
|
|
technic.swap_node(pos, "technic:forcefield_emitter_off")
|
|
|
|
end
|
|
|
|
elseif eu_input >= power_requirement then
|
|
|
|
if node.name == "technic:forcefield_emitter_off" then
|
|
|
|
technic.swap_node(pos, "technic:forcefield_emitter_on")
|
|
|
|
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
|
|
|
end
|
|
|
|
update_forcefield(pos, meta:get_int("range"), true)
|
|
|
|
end
|
|
|
|
meta:set_int("HV_EU_demand", power_requirement)
|
|
|
|
end
|
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
minetest.register_node("technic:forcefield_emitter_off", {
|
Rationalise machine terminology
All electrically-powered machines now consistently indicate their
tier (supply voltage) in their names. As this implies that they are
electrically powered, the furnaces no longer have "Electric" in their
names. The fuel-fired equivalents of electric machines, which exist
for alloy furnace and furnace, now say "Fuel-Fired" to distinguish them.
(The fuel-fired alloy furnace used to say "Coal", which was inaccurate
because it uses any fuel. The fuel-fired furnace, from the default mod,
used to just be called "Furnace", which is ambiguous.)
Electric power generators now consistently indicate their tier and have
the word "Generator" in their names. This makes their purpose much
clearer, and makes obvious craft guide searches produce useful results.
The fuel-fired generators, previously just (ambiguously) called
"Generator", are now explicitly "Fuel-Fired".
2014-06-20 17:58:52 +02:00
|
|
|
description = S("%s Forcefield Emitter"):format("HV"),
|
2013-07-17 21:34:35 +02:00
|
|
|
tiles = {"technic_forcefield_emitter_off.png"},
|
2014-07-11 11:00:46 +02:00
|
|
|
groups = {cracky = 1, technic_machine = 1},
|
2013-07-17 21:34:35 +02:00
|
|
|
on_receive_fields = forcefield_receive_fields,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_int("HV_EU_input", 0)
|
|
|
|
meta:set_int("HV_EU_demand", 0)
|
|
|
|
meta:set_int("range", 10)
|
|
|
|
meta:set_int("enabled", 0)
|
2014-07-14 15:58:59 +02:00
|
|
|
meta:set_int("mesecon_mode", 0)
|
|
|
|
meta:set_int("mesecon_effect", 0)
|
Rationalise machine terminology
All electrically-powered machines now consistently indicate their
tier (supply voltage) in their names. As this implies that they are
electrically powered, the furnaces no longer have "Electric" in their
names. The fuel-fired equivalents of electric machines, which exist
for alloy furnace and furnace, now say "Fuel-Fired" to distinguish them.
(The fuel-fired alloy furnace used to say "Coal", which was inaccurate
because it uses any fuel. The fuel-fired furnace, from the default mod,
used to just be called "Furnace", which is ambiguous.)
Electric power generators now consistently indicate their tier and have
the word "Generator" in their names. This makes their purpose much
clearer, and makes obvious craft guide searches produce useful results.
The fuel-fired generators, previously just (ambiguously) called
"Generator", are now explicitly "Fuel-Fired".
2014-06-20 17:58:52 +02:00
|
|
|
meta:set_string("infotext", S("%s Forcefield Emitter"):format("HV"))
|
2014-07-03 00:59:53 +02:00
|
|
|
set_forcefield_formspec(meta)
|
2013-07-17 21:34:35 +02:00
|
|
|
end,
|
2014-07-11 11:00:46 +02:00
|
|
|
mesecons = mesecons,
|
|
|
|
technic_run = run,
|
2013-07-17 21:34:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("technic:forcefield_emitter_on", {
|
Rationalise machine terminology
All electrically-powered machines now consistently indicate their
tier (supply voltage) in their names. As this implies that they are
electrically powered, the furnaces no longer have "Electric" in their
names. The fuel-fired equivalents of electric machines, which exist
for alloy furnace and furnace, now say "Fuel-Fired" to distinguish them.
(The fuel-fired alloy furnace used to say "Coal", which was inaccurate
because it uses any fuel. The fuel-fired furnace, from the default mod,
used to just be called "Furnace", which is ambiguous.)
Electric power generators now consistently indicate their tier and have
the word "Generator" in their names. This makes their purpose much
clearer, and makes obvious craft guide searches produce useful results.
The fuel-fired generators, previously just (ambiguously) called
"Generator", are now explicitly "Fuel-Fired".
2014-06-20 17:58:52 +02:00
|
|
|
description = S("%s Forcefield Emitter"):format("HV"),
|
2013-07-17 21:34:35 +02:00
|
|
|
tiles = {"technic_forcefield_emitter_on.png"},
|
2014-07-11 11:00:46 +02:00
|
|
|
groups = {cracky = 1, technic_machine = 1, not_in_creative_inventory=1},
|
2013-07-17 21:34:35 +02:00
|
|
|
drop = "technic:forcefield_emitter_off",
|
|
|
|
on_receive_fields = forcefield_receive_fields,
|
|
|
|
on_destruct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
update_forcefield(pos, meta:get_int("range"), false)
|
|
|
|
end,
|
2014-07-11 11:00:46 +02:00
|
|
|
mesecons = mesecons,
|
|
|
|
technic_run = run,
|
2014-08-01 18:30:21 +02:00
|
|
|
technic_on_disable = function (pos, node)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
update_forcefield(pos, meta:get_int("range"), false)
|
|
|
|
technic.swap_node(pos, "technic:forcefield_emitter_off")
|
|
|
|
end,
|
2013-07-17 21:34:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("technic:forcefield", {
|
Rationalise machine terminology
All electrically-powered machines now consistently indicate their
tier (supply voltage) in their names. As this implies that they are
electrically powered, the furnaces no longer have "Electric" in their
names. The fuel-fired equivalents of electric machines, which exist
for alloy furnace and furnace, now say "Fuel-Fired" to distinguish them.
(The fuel-fired alloy furnace used to say "Coal", which was inaccurate
because it uses any fuel. The fuel-fired furnace, from the default mod,
used to just be called "Furnace", which is ambiguous.)
Electric power generators now consistently indicate their tier and have
the word "Generator" in their names. This makes their purpose much
clearer, and makes obvious craft guide searches produce useful results.
The fuel-fired generators, previously just (ambiguously) called
"Generator", are now explicitly "Fuel-Fired".
2014-06-20 17:58:52 +02:00
|
|
|
description = S("%s Forcefield"):format("HV"),
|
2013-07-17 21:34:35 +02:00
|
|
|
sunlight_propagates = true,
|
|
|
|
drawtype = "glasslike",
|
|
|
|
groups = {not_in_creative_inventory=1, unbreakable=1},
|
|
|
|
paramtype = "light",
|
|
|
|
light_source = 15,
|
|
|
|
drop = '',
|
|
|
|
tiles = {{
|
|
|
|
name = "technic_forcefield_animated.png",
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 16,
|
|
|
|
aspect_h = 16,
|
|
|
|
length = 1.0,
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
})
|
2014-07-11 11:00:46 +02:00
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
|
|
|
|
if minetest.get_modpath("mesecons_mvps") then
|
|
|
|
mesecon:register_mvps_stopper("technic:forcefield")
|
|
|
|
end
|
|
|
|
|
|
|
|
technic.register_machine("HV", "technic:forcefield_emitter_on", technic.receiver)
|
|
|
|
technic.register_machine("HV", "technic:forcefield_emitter_off", technic.receiver)
|
|
|
|
|