| | |
| | | minetest.register_craft({ |
| | | output = 'technic:forcefield_emitter_off', |
| | | recipe = { |
| | | {'default:mese', 'technic:deployer_off', 'default:mese' }, |
| | | {'technic:deployer_off', 'technic:motor', 'technic:deployer_off'}, |
| | | {'default:mese', 'technic:deployer_off', 'default:mese' }, |
| | | {'default:mese', 'technic:motor', 'default:mese' }, |
| | | {'technic:deployer_off', 'technic:machine_casing', 'technic:deployer_off'}, |
| | | {'default:mese', 'technic:hv_cable0', 'default:mese' }, |
| | | } |
| | | }) |
| | | |
| | |
| | | end |
| | | |
| | | local function set_forcefield_formspec(meta) |
| | | local formspec = "size[5,1.5]".. |
| | | local formspec = "size[5,2.25]".. |
| | | "field[2,0.5;2,1;range;"..S("Range")..";"..meta:get_int("range").."]" |
| | | if meta:get_int("enabled") == 0 then |
| | | formspec = formspec.."button[0,1;5,1;enable;"..S("%s Disabled"):format(S("%s Forcefield Emitter"):format("HV")).."]" |
| | | -- 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. |
| | | if meta:get_int("mesecon_mode") == 0 then |
| | | formspec = formspec.."button[0,1;5,1;mesecon_mode_1;"..S("Ignoring Mesecon Signal").."]" |
| | | else |
| | | formspec = formspec.."button[0,1;5,1;disable;"..S("%s Enabled"):format(S("%s Forcefield Emitter"):format("HV")).."]" |
| | | formspec = formspec.."button[0,1;5,1;mesecon_mode_0;"..S("Controlled by Mesecon Signal").."]" |
| | | end |
| | | if meta:get_int("enabled") == 0 then |
| | | formspec = formspec.."button[0,1.75;5,1;enable;"..S("%s Disabled"):format(S("%s Forcefield Emitter"):format("HV")).."]" |
| | | else |
| | | formspec = formspec.."button[0,1.75;5,1;disable;"..S("%s Enabled"):format(S("%s Forcefield Emitter"):format("HV")).."]" |
| | | end |
| | | meta:set_string("formspec", formspec) |
| | | end |
| | |
| | | end |
| | | if fields.enable then meta:set_int("enabled", 1) end |
| | | if fields.disable then meta:set_int("enabled", 0) end |
| | | 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 |
| | | set_forcefield_formspec(meta) |
| | | end |
| | | |
| | | local mesecons = { |
| | | effector = { |
| | | action_on = function(pos, node) |
| | | minetest.get_meta(pos):set_int("enabled", 0) |
| | | minetest.get_meta(pos):set_int("mesecon_effect", 1) |
| | | end, |
| | | action_off = function(pos, node) |
| | | minetest.get_meta(pos):set_int("enabled", 1) |
| | | minetest.get_meta(pos):set_int("mesecon_effect", 0) |
| | | end |
| | | } |
| | | } |
| | | |
| | | 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") |
| | | local enabled = meta:get_int("enabled") ~= 0 and (meta:get_int("mesecon_mode") == 0 or meta:get_int("mesecon_effect") ~= 0) |
| | | 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 |
| | | |
| | | if not enabled then |
| | | 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 |
| | | |
| | | minetest.register_node("technic:forcefield_emitter_off", { |
| | | description = S("%s Forcefield Emitter"):format("HV"), |
| | | tiles = {"technic_forcefield_emitter_off.png"}, |
| | | groups = {cracky = 1}, |
| | | groups = {cracky = 1, technic_machine = 1}, |
| | | on_receive_fields = forcefield_receive_fields, |
| | | on_construct = function(pos) |
| | | local meta = minetest.get_meta(pos) |
| | |
| | | meta:set_int("HV_EU_demand", 0) |
| | | meta:set_int("range", 10) |
| | | meta:set_int("enabled", 0) |
| | | meta:set_int("mesecon_mode", 0) |
| | | meta:set_int("mesecon_effect", 0) |
| | | meta:set_string("infotext", S("%s Forcefield Emitter"):format("HV")) |
| | | set_forcefield_formspec(meta) |
| | | end, |
| | | mesecons = mesecons |
| | | mesecons = mesecons, |
| | | technic_run = run, |
| | | }) |
| | | |
| | | minetest.register_node("technic:forcefield_emitter_on", { |
| | | description = S("%s Forcefield Emitter"):format("HV"), |
| | | tiles = {"technic_forcefield_emitter_on.png"}, |
| | | groups = {cracky = 1, not_in_creative_inventory=1}, |
| | | groups = {cracky = 1, technic_machine = 1, not_in_creative_inventory=1}, |
| | | drop = "technic:forcefield_emitter_off", |
| | | on_receive_fields = forcefield_receive_fields, |
| | | on_construct = function(pos) |
| | | local meta = minetest.get_meta(pos) |
| | | local range = meta:get_int("range") |
| | | meta:set_string("formspec", get_forcefield_formspec(range)) |
| | | end, |
| | | on_destruct = function(pos) |
| | | local meta = minetest.get_meta(pos) |
| | | update_forcefield(pos, meta:get_int("range"), false) |
| | | end, |
| | | mesecons = mesecons |
| | | mesecons = mesecons, |
| | | technic_run = run, |
| | | 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, |
| | | }) |
| | | |
| | | minetest.register_node("technic:forcefield", { |
| | |
| | | }, |
| | | }}, |
| | | }) |
| | | minetest.register_abm({ |
| | | nodenames = {"technic:forcefield_emitter_on", "technic:forcefield_emitter_off"}, |
| | | interval = 1, |
| | | chance = 1, |
| | | action = 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") |
| | | local enabled = meta:get_int("enabled") |
| | | local machine_name = S("%s Forcefield Emitter"):format("HV") |
| | | -- Power off automatically if no longer connected to a switching station |
| | | technic.switching_station_timeout_count(pos, "HV") |
| | | |
| | | local power_requirement = math.floor( |
| | | 4 * math.pi * math.pow(meta:get_int("range"), 2) |
| | | ) * forcefield_power_drain |
| | | |
| | | if meta:get_int("enabled") == 0 then |
| | | 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 |
| | | }) |
| | | |
| | | if minetest.get_modpath("mesecons_mvps") then |
| | | mesecon:register_mvps_stopper("technic:forcefield") |
| | | end |
| | | -- TODO: Register a stopper for frames |
| | | |
| | | technic.register_machine("HV", "technic:forcefield_emitter_on", technic.receiver) |
| | | technic.register_machine("HV", "technic:forcefield_emitter_off", technic.receiver) |