| | |
| | | |
| | | -- How expensive is the generator? |
| | | -- Leaves room for upgrades lowering the power drain? |
| | | local digilines_path = minetest.get_modpath("digilines") |
| | | |
| | | local forcefield_power_drain = 10 |
| | | |
| | | local S = technic.getter |
| | |
| | | end |
| | | |
| | | local function set_forcefield_formspec(meta) |
| | | local formspec = "size[5,2.25]".. |
| | | local formspec |
| | | if digilines_path then |
| | | formspec = "size[5,3.25]".. |
| | | "field[0.3,3;5,1;channel;Digiline Channel;"..meta:get_string("channel").."]" |
| | | else |
| | | formspec = "size[5,2.25]" |
| | | end |
| | | formspec = formspec.. |
| | | "field[0.3,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 |
| | |
| | | update_forcefield(pos, meta, false) |
| | | end |
| | | if range then meta:set_int("range", range) end |
| | | if fields.shape0 then meta:set_int("shape", 0) end |
| | | if fields.shape1 then meta:set_int("shape", 1) end |
| | | if fields.enable then meta:set_int("enabled", 1) end |
| | | if fields.channel then meta:set_string("channel", fields.channel) end |
| | | if fields.shape0 then meta:set_int("shape", 0) end |
| | | if fields.shape1 then meta:set_int("shape", 1) 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 |
| | |
| | | minetest.get_meta(pos):set_int("mesecon_effect", 0) |
| | | end |
| | | } |
| | | } |
| | | |
| | | local digiline_def = { |
| | | receptor = {action = function() end}, |
| | | effector = { |
| | | action = function(pos, node, channel, msg) |
| | | local meta = minetest.get_meta(pos) |
| | | if channel ~= meta:get_string("channel") then |
| | | return |
| | | end |
| | | msg = msg:lower() |
| | | if msg == "get" then |
| | | digilines.receptor_send(pos, digilines.rules.default, channel, { |
| | | enabled = meta:get_int("enabled"), |
| | | range = meta:get_int("range"), |
| | | shape = meta:get_int("shape") |
| | | }) |
| | | return |
| | | elseif msg == "off" then |
| | | meta:set_int("enabled", 0) |
| | | elseif msg == "on" then |
| | | meta:set_int("enabled", 1) |
| | | elseif msg == "toggle" then |
| | | local onn = meta:get_int("enabled") |
| | | onn = 1-onn -- Mirror onn with pivot 0.5, so switch between 1 and 0. |
| | | meta:set_int("enabled", onn) |
| | | elseif msg:sub(1, 5) == "range" then |
| | | local range = tonumber(msg:sub(7)) |
| | | if not range then |
| | | return |
| | | end |
| | | range = math.max(range, 5) |
| | | range = math.min(range, 20) |
| | | update_forcefield(pos, meta, false) |
| | | meta:set_int("range", range) |
| | | elseif msg:sub(1, 5) == "shape" then |
| | | local shape = msg:sub(7):lower() |
| | | if shape == "sphere" then |
| | | shape = 0 |
| | | elseif shape == "cube" then |
| | | shape = 1 |
| | | end |
| | | shape = tonumber(shape) |
| | | if not shape then |
| | | return |
| | | end |
| | | update_forcefield(pos, meta, false) |
| | | meta:set_int("shape", shape) |
| | | else |
| | | return |
| | | end |
| | | set_forcefield_formspec(meta) |
| | | end |
| | | }, |
| | | } |
| | | |
| | | local function run(pos, node) |
| | |
| | | meta:set_int("enabled", 0) |
| | | meta:set_int("mesecon_mode", 0) |
| | | meta:set_int("mesecon_effect", 0) |
| | | if digilines_path then |
| | | meta:set_string("channel", "forcefield"..minetest.pos_to_string(pos)) |
| | | end |
| | | meta:set_string("infotext", S("%s Forcefield Emitter"):format("HV")) |
| | | set_forcefield_formspec(meta) |
| | | end, |
| | | mesecons = mesecons, |
| | | digiline = digiline_def, |
| | | technic_run = run, |
| | | }) |
| | | |
| | |
| | | update_forcefield(pos, meta, false) |
| | | end, |
| | | mesecons = mesecons, |
| | | digiline = digiline_def, |
| | | technic_run = run, |
| | | technic_on_disable = function (pos, node) |
| | | local meta = minetest.get_meta(pos) |