From 3dd6c80f18faa8f9617576e377587214bbfc2f9d Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sun, 6 Jun 2021 10:41:32 +0200 Subject: [PATCH] Prepare for lib 'networks' --- basis/command.lua | 2 +- power/powerswitch.lua | 31 ++++++++++++++++++++++++++----- power/powerswitchbox_legacy.lua | 21 +++------------------ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/basis/command.lua b/basis/command.lua index 37c4aca..435818b 100644 --- a/basis/command.lua +++ b/basis/command.lua @@ -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 diff --git a/power/powerswitch.lua b/power/powerswitch.lua index c5b056e..6f91abd 100644 --- a/power/powerswitch.lua +++ b/power/powerswitch.lua @@ -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 diff --git a/power/powerswitchbox_legacy.lua b/power/powerswitchbox_legacy.lua index 5b144b0..60dab1e 100644 --- a/power/powerswitchbox_legacy.lua +++ b/power/powerswitchbox_legacy.lua @@ -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 -}) \ No newline at end of file