forked from minetest-mods/technic
Make forcefield controlable with digilines.
This commit is contained in:
parent
6c4e90d39c
commit
ef8bb38bfd
@ -6,6 +6,8 @@
|
||||
|
||||
-- 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
|
||||
@ -90,7 +92,14 @@ local function update_forcefield(pos, meta, active, first)
|
||||
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
|
||||
@ -130,6 +139,7 @@ local forcefield_receive_fields = function(pos, formname, fields, sender)
|
||||
update_forcefield(pos, meta, false)
|
||||
end
|
||||
if range then meta:set_int("range", range) 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
|
||||
@ -150,6 +160,60 @@ local mesecons = {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local eu_input = meta:get_int("HV_EU_input")
|
||||
@ -205,10 +269,14 @@ minetest.register_node("technic:forcefield_emitter_off", {
|
||||
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,
|
||||
})
|
||||
|
||||
@ -224,6 +292,7 @@ minetest.register_node("technic:forcefield_emitter_on", {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user