From b131e3f3439ad0f3c3cb2ca3ebd05cd4ca127ca6 Mon Sep 17 00:00:00 2001 From: SX Date: Sun, 20 Sep 2020 16:01:47 +0300 Subject: [PATCH] Do not activate new switch if another is active already --- technic/machines/switching_station.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua index afe5fd6..d54274b 100644 --- a/technic/machines/switching_station.lua +++ b/technic/machines/switching_station.lua @@ -66,7 +66,17 @@ minetest.register_node("technic:switching_station",{ on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("infotext", S("Switching Station")) - meta:set_string("active", 1) + local network_id = technic.sw_pos2network(pos) + local net_sw_pos = network_id and technic.network2sw_pos(network_id) + local net_sw_node = net_sw_pos and minetest.get_node(net_sw_pos) + if net_sw_node and net_sw_node.name == "technic:switching_station" then + -- There's already network with same id, check if it already has active switching station + -- set active to 0 for this switch if there's already another active + local net_sw_meta = minetest.get_meta(net_sw_pos) + meta:set_string("active", net_sw_meta:get_int("active") == 1 and 0 or 1) + else + meta:set_string("active", 1) + end meta:set_string("channel", "switching_station"..minetest.pos_to_string(pos)) meta:set_string("formspec", "field[channel;Channel;${channel}]") local poshash = minetest.hash_node_position(pos) @@ -216,6 +226,10 @@ local function traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_node end end +function technic.sw_pos2network(pos) + return pos and technic.cables[minetest.hash_node_position({x=pos.x,y=pos.y-1,z=pos.z})] +end + function technic.pos2network(pos) return pos and technic.cables[minetest.hash_node_position(pos)] end