Prepare for lib 'networks'
parent
f6ec65bd9a
commit
3dd6c80f18
|
@ -26,7 +26,7 @@ local techage_use_sqlite = minetest.settings:get_bool('techage_use_sqlite', fals
|
|||
local string_split = string.split
|
||||
local NodeDef = techage.NodeDef
|
||||
local Tube = techage.Tube
|
||||
local is_cart_available = minecart.is_cart_available
|
||||
local is_cart_available = minecart.is_nodecart_available
|
||||
|
||||
-------------------------------------------------------------------
|
||||
-- Database
|
||||
|
|
|
@ -29,15 +29,36 @@ local Param2ToDir = {
|
|||
[5] = 3,
|
||||
}
|
||||
|
||||
local function get_param2(meta)
|
||||
if meta:get_int("tl2_param2") then
|
||||
meta:set_int("netw_param2", meta:get_int("tl2_param2"))
|
||||
meta:set_string("tl2_param2", "")
|
||||
end
|
||||
if meta:get_int("tl2_param2_copy") then
|
||||
meta:set_int("netw_param2_copy", meta:get_int("tl2_param2_copy"))
|
||||
meta:set_string("tl2_param2_copy", "")
|
||||
end
|
||||
return meta:get_int("netw_param2")
|
||||
end
|
||||
|
||||
-- The switchbox can be open or hidden
|
||||
local function legacy_switchbox(pos)
|
||||
local meta = M(pos)
|
||||
local name = networks.hidden_name(pos)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
if name == "techage:powerswitch_box" then
|
||||
local meta = M(pos)
|
||||
meta:set_int("networks_param2_copy", meta:get_int("tl2_param2_copy"))
|
||||
if meta:get_int("networks_param2_copy") == 0 then
|
||||
meta:set_string("networks_nodename", "techage:powerswitch_box_off")
|
||||
local param2 = get_param2(meta)
|
||||
if param2 == 0 then
|
||||
meta:set_string("netw_name", "techage:powerswitch_box_off")
|
||||
else
|
||||
meta:set_string("networks_nodename", "techage:powerswitch_box_on")
|
||||
meta:set_string("netw_node", "techage:powerswitch_box_on")
|
||||
end
|
||||
elseif node.name == "techage:powerswitch_box" then
|
||||
local param2 = get_param2(meta)
|
||||
if param2 == 0 then
|
||||
minetest.swap_node(pos, {name = "techage:powerswitch_box_off", param2 = node.param2})
|
||||
else
|
||||
minetest.swap_node(pos, {name = "techage:powerswitch_box_on", param2 = node.param2})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,12 +45,13 @@ minetest.register_node("techage:powerswitch_box", {
|
|||
node_box = node_box,
|
||||
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
local node = minetest.get_node(pos)
|
||||
minetest.swap_node(pos, {name = "techage:powerswitch_box_on", param2 = node.param2})
|
||||
|
||||
if not Cable:after_place_tube(pos, placer, pointed_thing) then
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
end
|
||||
local node = minetest.get_node(pos)
|
||||
minetest.swap_node(pos, {name = "techage:powerswitch_box_on", param2 = node.param2})
|
||||
return false
|
||||
end,
|
||||
|
||||
|
@ -68,19 +69,3 @@ minetest.register_node("techage:powerswitch_box", {
|
|||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "[techage] legacy Power Switch Box",
|
||||
name = "techage:powerswitch_box",
|
||||
nodenames = {"techage:powerswitch_box"},
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
if M(pos):get_int("tl2_param2") == 0 then
|
||||
minetest.swap_node(pos, {name = "techage:powerswitch_box_off", param2 = node.param2})
|
||||
M(pos):set_int("networks_param2", 0)
|
||||
else
|
||||
minetest.swap_node(pos, {name = "techage:powerswitch_box_on", param2 = node.param2})
|
||||
M(pos):set_int("networks_param2", M(pos):get_int("tl2_param2"))
|
||||
end
|
||||
end
|
||||
})
|
Loading…
Reference in New Issue