From 2e95bf20d1cc669c63c3d1e9a5af4b720cb9841a Mon Sep 17 00:00:00 2001 From: SomeName42 <> Date: Sat, 16 Nov 2024 16:01:48 +0100 Subject: [PATCH 1/8] Fixed power multiplication bug. Resolves #277. The cause of the bug was that machines can be a part of multiple networks and generate power for each of the networks. This was fixed by checking if machine is already part of an other network and not making it a part of the current one. When network times out the network meta string value is cleared and the clear_networks function is used to try to connect the machine to a different network. --- technic/machines/register/cables.lua | 13 +++++++------ technic/machines/switching_station.lua | 22 +++++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/technic/machines/register/cables.lua b/technic/machines/register/cables.lua index 70da6d65..dcb7f3c4 100644 --- a/technic/machines/register/cables.lua +++ b/technic/machines/register/cables.lua @@ -43,7 +43,7 @@ local function check_connections(pos) return connections end -local function clear_networks(pos) +function technic.clear_networks(pos) local node = minetest.get_node(pos) local meta = minetest.get_meta(pos) local placed = node.name ~= "air" @@ -77,6 +77,7 @@ local function clear_networks(pos) -- Found a machine local eu_type = technic.machines[tier][node.name] meta:set_string(tier.."_network", string.format("%.20g", network_id)) + meta:set_int(tier.."_EU_timeout", 2) if eu_type == technic.producer then table.insert(network.PR_nodes, pos) elseif eu_type == technic.receiver then @@ -169,8 +170,8 @@ function technic.register_cable(tier, size) node_box = node_box, connects_to = {"group:technic_"..ltier.."_cable", "group:technic_"..ltier, "group:technic_all_tiers"}, - on_construct = clear_networks, - on_destruct = clear_networks, + on_construct = technic.clear_networks, + on_destruct = technic.clear_networks, }) local xyz = { @@ -209,8 +210,8 @@ function technic.register_cable(tier, size) node_box = table.copy(node_box), connects_to = {"group:technic_"..ltier.."_cable", "group:technic_"..ltier, "group:technic_all_tiers"}, - on_construct = clear_networks, - on_destruct = clear_networks, + on_construct = technic.clear_networks, + on_destruct = technic.clear_networks, } def.node_box.fixed = { {-size, -size, -size, size, size, size}, @@ -295,7 +296,7 @@ end local function clear_nets_if_machine(pos, node) for tier, machine_list in pairs(technic.machines) do if machine_list[node.name] ~= nil then - return clear_networks(pos) + return technic.clear_networks(pos) end end end diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua index 521e2f82..0aef49f4 100644 --- a/technic/machines/switching_station.lua +++ b/technic/machines/switching_station.lua @@ -136,7 +136,17 @@ local check_node_subp = function(network, pos, machines, sw_pos, from_below, net local meta = minetest.get_meta(pos) -- Normal tostring() does not have enough precision, neither does meta:set_int() -- Lua 5.1 bug: Cannot use hexadecimal notation for compression (see LuaJIT #911) - meta:set_string(network.tier.."_network", string.format("%.20g", network_id)) + local network_str = string.format("%.20g", network_id) + local network_key = network.tier.."_network" + local m_network_str = meta:get_string(network_key) + + if m_network_str == "" then + meta:set_string(network_key, network_str) + else + if m_network_str ~= network_str then + return + end + end if eu_type == technic.producer then add_network_node(network.PR_nodes, pos, network_id) @@ -171,7 +181,7 @@ local traverse_network = function(network, pos, machines, sw_pos, network_id, qu end end -local touch_nodes = function(list, tier) +local touch_nodes = function(list, tier, network_id) for _, pos in ipairs(list) do local meta = minetest.get_meta(pos) meta:set_int(tier.."_EU_timeout", 2) -- Touch node @@ -183,9 +193,9 @@ local get_network = function(sw_pos, cable_pos, tier) local cached = technic.networks[network_id] if cached and cached.tier == tier then -- Re-use cached system data - touch_nodes(cached.PR_nodes, tier) - touch_nodes(cached.BA_nodes, tier) - touch_nodes(cached.RE_nodes, tier) + touch_nodes(cached.PR_nodes, tier, network_id) + touch_nodes(cached.BA_nodes, tier, network_id) + touch_nodes(cached.RE_nodes, tier, network_id) for _, pos in ipairs(cached.SP_nodes) do -- Disable all other switching stations (again) local meta = minetest.get_meta(pos) @@ -455,6 +465,7 @@ local function switching_station_timeout_count(pos, tier) local meta = minetest.get_meta(pos) local timeout = meta:get_int(tier.."_EU_timeout") if timeout <= 0 then + meta:set_string(tier.."_network", "") meta:set_int(tier.."_EU_input", 0) -- Not needed anymore <-- actually, it is for supply converter return true else @@ -482,6 +493,7 @@ minetest.register_abm({ if nodedef and nodedef.technic_on_disable then nodedef.technic_on_disable(pos, node) end + technic.clear_networks(pos) end end end, From 7f83b627af207c34fc99f3d9c11c6aa64e429b41 Mon Sep 17 00:00:00 2001 From: SomeName42 <> Date: Sat, 16 Nov 2024 16:04:35 +0100 Subject: [PATCH 2/8] Removed unnecessarily added network_id parameter from touch_nodes --- technic/machines/switching_station.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua index 0aef49f4..604ee2ce 100644 --- a/technic/machines/switching_station.lua +++ b/technic/machines/switching_station.lua @@ -181,7 +181,7 @@ local traverse_network = function(network, pos, machines, sw_pos, network_id, qu end end -local touch_nodes = function(list, tier, network_id) +local touch_nodes = function(list, tier) for _, pos in ipairs(list) do local meta = minetest.get_meta(pos) meta:set_int(tier.."_EU_timeout", 2) -- Touch node @@ -193,9 +193,9 @@ local get_network = function(sw_pos, cable_pos, tier) local cached = technic.networks[network_id] if cached and cached.tier == tier then -- Re-use cached system data - touch_nodes(cached.PR_nodes, tier, network_id) - touch_nodes(cached.BA_nodes, tier, network_id) - touch_nodes(cached.RE_nodes, tier, network_id) + touch_nodes(cached.PR_nodes, tier) + touch_nodes(cached.BA_nodes, tier) + touch_nodes(cached.RE_nodes, tier) for _, pos in ipairs(cached.SP_nodes) do -- Disable all other switching stations (again) local meta = minetest.get_meta(pos) From 77f01bc9d72078773cddae24c45f0f3d8cc7af86 Mon Sep 17 00:00:00 2001 From: SomeName42 <> Date: Sat, 16 Nov 2024 17:40:21 +0100 Subject: [PATCH 3/8] Fixed machines sometimes incorrectly being treated as cables. --- technic/machines/register/cables.lua | 3 +-- technic/machines/switching_station.lua | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/technic/machines/register/cables.lua b/technic/machines/register/cables.lua index dcb7f3c4..44980296 100644 --- a/technic/machines/register/cables.lua +++ b/technic/machines/register/cables.lua @@ -68,10 +68,9 @@ function technic.clear_networks(pos) -- Actually add it to the (cached) network -- !! IMPORTANT: ../switching_station.lua -> check_node_subp() must be kept in sync - technic.cables[minetest.hash_node_position(pos)] = network_id pos.visited = 1 if technic.is_tier_cable(node.name, tier) then - -- Found a cable + technic.cables[minetest.hash_node_position(pos)] = network_id table.insert(network.all_nodes,pos) elseif technic.machines[tier][node.name] then -- Found a machine diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua index 604ee2ce..adf9d3cf 100644 --- a/technic/machines/switching_station.lua +++ b/technic/machines/switching_station.lua @@ -100,9 +100,11 @@ end -- Add a wire node to the LV/MV/HV network -- Returns: indicator whether the cable is new in the network local hash_node_position = minetest.hash_node_position -local function add_network_node(nodes, pos, network_id) +local function add_network_node(nodes, pos, network_id, cable) local node_id = hash_node_position(pos) - technic.cables[node_id] = network_id + if cable then + technic.cables[node_id] = network_id + end if nodes[node_id] then return false end @@ -111,7 +113,7 @@ local function add_network_node(nodes, pos, network_id) end local function add_cable_node(nodes, pos, network_id, queue) - if add_network_node(nodes, pos, network_id) then + if add_network_node(nodes, pos, network_id, true) then queue[#queue + 1] = pos end end @@ -149,18 +151,18 @@ local check_node_subp = function(network, pos, machines, sw_pos, from_below, net end if eu_type == technic.producer then - add_network_node(network.PR_nodes, pos, network_id) + add_network_node(network.PR_nodes, pos, network_id, false) elseif eu_type == technic.receiver then - add_network_node(network.RE_nodes, pos, network_id) + add_network_node(network.RE_nodes, pos, network_id, false) elseif eu_type == technic.producer_receiver then - add_network_node(network.PR_nodes, pos, network_id) - add_network_node(network.RE_nodes, pos, network_id) + add_network_node(network.PR_nodes, pos, network_id, false) + add_network_node(network.RE_nodes, pos, network_id, false) elseif eu_type == technic.battery then - add_network_node(network.BA_nodes, pos, network_id) + add_network_node(network.BA_nodes, pos, network_id, false) elseif eu_type == "SPECIAL" and from_below and not vector.equals(pos, sw_pos) then -- Another switching station -> disable it - add_network_node(network.SP_nodes, pos, network_id) + add_network_node(network.SP_nodes, pos, network_id, false) meta:set_int("active", 0) end From 8a575357ef776fde1caf469063c82b6b8e63abcc Mon Sep 17 00:00:00 2001 From: SomeName42 <> Date: Sun, 17 Nov 2024 17:04:05 +0100 Subject: [PATCH 4/8] Small improvement to add_network_node function and function comment improved clear_networks function fixed network not being cleared in some cases. Moved new network finding for machines to when network is cleared instead of on timeout. --- technic/machines/register/cables.lua | 155 ++++++++++++++----------- technic/machines/switching_station.lua | 24 ++-- 2 files changed, 100 insertions(+), 79 deletions(-) diff --git a/technic/machines/register/cables.lua b/technic/machines/register/cables.lua index 44980296..d5a596dd 100644 --- a/technic/machines/register/cables.lua +++ b/technic/machines/register/cables.lua @@ -43,84 +43,107 @@ local function check_connections(pos) return connections end +local function clear_network(net) + for _,v in pairs(technic.networks[net].all_nodes) do + local pos1 = minetest.hash_node_position(v) + technic.cables[pos1] = nil + end + local network_bckup = technic.networks[net] + technic.networks[net] = nil + + for _,n_pos in pairs(network_bckup.PR_nodes) do + technic.clear_networks(n_pos) + end + for _,n_pos in pairs(network_bckup.RE_nodes) do + technic.clear_networks(n_pos) + end + for _,n_pos in pairs(network_bckup.BA_nodes) do + technic.clear_networks(n_pos) + end +end + function technic.clear_networks(pos) local node = minetest.get_node(pos) + core.log(node.name) local meta = minetest.get_meta(pos) local placed = node.name ~= "air" local positions = check_connections(pos) + if #positions < 1 then return end - local dead_end = #positions == 1 - for _,connected_pos in pairs(positions) do - local net = technic.cables[minetest.hash_node_position(connected_pos)] - if net and technic.networks[net] then - if dead_end and placed then - -- Dead end placed, add it to the network - -- Get the network - local network_id = technic.cables[minetest.hash_node_position(positions[1])] - if not network_id then - -- We're evidently not on a network, nothing to add ourselves to - return - end - local sw_pos = minetest.get_position_from_hash(network_id) - sw_pos.y = sw_pos.y + 1 - local network = technic.networks[network_id] - local tier = network.tier - -- Actually add it to the (cached) network - -- !! IMPORTANT: ../switching_station.lua -> check_node_subp() must be kept in sync - pos.visited = 1 - if technic.is_tier_cable(node.name, tier) then - technic.cables[minetest.hash_node_position(pos)] = network_id - table.insert(network.all_nodes,pos) - elseif technic.machines[tier][node.name] then - -- Found a machine - local eu_type = technic.machines[tier][node.name] - meta:set_string(tier.."_network", string.format("%.20g", network_id)) - meta:set_int(tier.."_EU_timeout", 2) - if eu_type == technic.producer then - table.insert(network.PR_nodes, pos) - elseif eu_type == technic.receiver then - table.insert(network.RE_nodes, pos) - elseif eu_type == technic.producer_receiver then - table.insert(network.PR_nodes, pos) - table.insert(network.RE_nodes, pos) - elseif eu_type == technic.battery then - table.insert(network.BA_nodes, pos) - end - -- Note: SPECIAL (i.e. switching station) is not traversed! - end - elseif dead_end and not placed then - -- Dead end removed, remove it from the network - -- Get the network - local network_id = technic.cables[minetest.hash_node_position(positions[1])] - if not network_id then - -- We're evidently not on a network, nothing to add ourselves to - return + if #positions == 1 then + if placed then + -- Dead end placed, add it to the network + -- Get the network + local network_id = technic.cables[minetest.hash_node_position(positions[1])] + if not network_id then + -- We're evidently not on a network, nothing to add ourselves to + return + end + local network = technic.networks[network_id] + local tier = network.tier + + -- Actually add it to the (cached) network + -- !! IMPORTANT: ../switching_station.lua -> check_node_subp() must be kept in sync + pos.visited = 1 + if technic.is_tier_cable(node.name, tier) then + technic.cables[minetest.hash_node_position(pos)] = network_id + table.insert(network.all_nodes,pos) + elseif technic.machines[tier][node.name] then + -- Found a machine + local eu_type = technic.machines[tier][node.name] + meta:set_string(tier.."_network", string.format("%.20g", network_id)) + meta:set_int(tier.."_EU_timeout", 2) + if eu_type == technic.producer then + table.insert(network.PR_nodes, pos) + elseif eu_type == technic.receiver then + table.insert(network.RE_nodes, pos) + elseif eu_type == technic.producer_receiver then + table.insert(network.PR_nodes, pos) + table.insert(network.RE_nodes, pos) + elseif eu_type == technic.battery then + table.insert(network.BA_nodes, pos) end - local network = technic.networks[network_id] + -- Note: SPECIAL (i.e. switching station) is not traversed! + end + else + -- Dead end removed, remove it from the network + -- Get the network + local network_id = technic.cables[minetest.hash_node_position(positions[1])] + if not network_id then + -- We're evidently not on a network, nothing to add ourselves to + return + end + local network = technic.networks[network_id] - -- Search for and remove machine - technic.cables[minetest.hash_node_position(pos)] = nil - for tblname,table in pairs(network) do - if tblname ~= "tier" then - for machinenum,machine in pairs(table) do - if machine.x == pos.x - and machine.y == pos.y - and machine.z == pos.z then - table[machinenum] = nil - end + -- Search for and remove machine + technic.cables[minetest.hash_node_position(pos)] = nil + for tblname,table in pairs(network) do + if tblname ~= "tier" then + for machinenum,machine in pairs(table) do + if machine.x == pos.x + and machine.y == pos.y + and machine.z == pos.z then + table[machinenum] = nil end end end - else - -- Not a dead end, so the whole network needs to be recalculated - for _,v in pairs(technic.networks[net].all_nodes) do - local pos1 = minetest.hash_node_position(v) - technic.cables[pos1] = nil - end - technic.networks[net] = nil end end + return + end + + local net = technic.cables[minetest.hash_node_position(pos)] + if net and technic.networks[net] then + clear_network(net) + end + + for _,connected_pos in pairs(positions) do + local net = technic.cables[minetest.hash_node_position(connected_pos)] + if net and technic.networks[net] then + -- Not a dead end, so the whole network needs to be recalculated + clear_network(net) + end end end @@ -170,7 +193,7 @@ function technic.register_cable(tier, size) connects_to = {"group:technic_"..ltier.."_cable", "group:technic_"..ltier, "group:technic_all_tiers"}, on_construct = technic.clear_networks, - on_destruct = technic.clear_networks, + after_destruct = technic.clear_networks, }) local xyz = { @@ -210,7 +233,7 @@ function technic.register_cable(tier, size) connects_to = {"group:technic_"..ltier.."_cable", "group:technic_"..ltier, "group:technic_all_tiers"}, on_construct = technic.clear_networks, - on_destruct = technic.clear_networks, + after_destruct = technic.clear_networks, } def.node_box.fixed = { {-size, -size, -size, size, size, size}, diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua index adf9d3cf..3f649201 100644 --- a/technic/machines/switching_station.lua +++ b/technic/machines/switching_station.lua @@ -97,12 +97,12 @@ local function flatten(map) return list end --- Add a wire node to the LV/MV/HV network --- Returns: indicator whether the cable is new in the network +-- Add a node to the LV/MV/HV network +-- Returns: indicator whether the node is new in the network local hash_node_position = minetest.hash_node_position -local function add_network_node(nodes, pos, network_id, cable) +local function add_network_node(nodes, pos, network_id) local node_id = hash_node_position(pos) - if cable then + if network_id then technic.cables[node_id] = network_id end if nodes[node_id] then @@ -113,7 +113,7 @@ local function add_network_node(nodes, pos, network_id, cable) end local function add_cable_node(nodes, pos, network_id, queue) - if add_network_node(nodes, pos, network_id, true) then + if add_network_node(nodes, pos, network_id) then queue[#queue + 1] = pos end end @@ -151,18 +151,18 @@ local check_node_subp = function(network, pos, machines, sw_pos, from_below, net end if eu_type == technic.producer then - add_network_node(network.PR_nodes, pos, network_id, false) + add_network_node(network.PR_nodes, pos) elseif eu_type == technic.receiver then - add_network_node(network.RE_nodes, pos, network_id, false) + add_network_node(network.RE_nodes, pos) elseif eu_type == technic.producer_receiver then - add_network_node(network.PR_nodes, pos, network_id, false) - add_network_node(network.RE_nodes, pos, network_id, false) + add_network_node(network.PR_nodes, pos) + add_network_node(network.RE_nodes, pos) elseif eu_type == technic.battery then - add_network_node(network.BA_nodes, pos, network_id, false) + add_network_node(network.BA_nodes, pos) elseif eu_type == "SPECIAL" and from_below and not vector.equals(pos, sw_pos) then -- Another switching station -> disable it - add_network_node(network.SP_nodes, pos, network_id, false) + add_network_node(network.SP_nodes, pos) meta:set_int("active", 0) end @@ -205,7 +205,6 @@ local get_network = function(sw_pos, cable_pos, tier) end return cached.PR_nodes, cached.BA_nodes, cached.RE_nodes end - local machines = technic.machines[tier] local network = { tier = tier, @@ -495,7 +494,6 @@ minetest.register_abm({ if nodedef and nodedef.technic_on_disable then nodedef.technic_on_disable(pos, node) end - technic.clear_networks(pos) end end end, From ee4529670487ceffa9782397fc6bd58f75f3612e Mon Sep 17 00:00:00 2001 From: SomeName42 <> Date: Sun, 17 Nov 2024 17:09:59 +0100 Subject: [PATCH 5/8] Removed accidentally included logging. --- technic/machines/register/cables.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/technic/machines/register/cables.lua b/technic/machines/register/cables.lua index d5a596dd..f52af8f4 100644 --- a/technic/machines/register/cables.lua +++ b/technic/machines/register/cables.lua @@ -64,7 +64,6 @@ end function technic.clear_networks(pos) local node = minetest.get_node(pos) - core.log(node.name) local meta = minetest.get_meta(pos) local placed = node.name ~= "air" local positions = check_connections(pos) From 27df5e553f6879ec0e3f60f3722788a703248f2f Mon Sep 17 00:00:00 2001 From: SomeName42 <> Date: Sun, 17 Nov 2024 17:29:43 +0100 Subject: [PATCH 6/8] Made clear_networks function local again. --- technic/machines/register/cables.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/technic/machines/register/cables.lua b/technic/machines/register/cables.lua index f52af8f4..04c0cc4d 100644 --- a/technic/machines/register/cables.lua +++ b/technic/machines/register/cables.lua @@ -52,17 +52,17 @@ local function clear_network(net) technic.networks[net] = nil for _,n_pos in pairs(network_bckup.PR_nodes) do - technic.clear_networks(n_pos) + clear_networks(n_pos) end for _,n_pos in pairs(network_bckup.RE_nodes) do - technic.clear_networks(n_pos) + clear_networks(n_pos) end for _,n_pos in pairs(network_bckup.BA_nodes) do - technic.clear_networks(n_pos) + clear_networks(n_pos) end end -function technic.clear_networks(pos) +local function clear_networks(pos) local node = minetest.get_node(pos) local meta = minetest.get_meta(pos) local placed = node.name ~= "air" @@ -191,8 +191,8 @@ function technic.register_cable(tier, size) node_box = node_box, connects_to = {"group:technic_"..ltier.."_cable", "group:technic_"..ltier, "group:technic_all_tiers"}, - on_construct = technic.clear_networks, - after_destruct = technic.clear_networks, + on_construct = clear_networks, + after_destruct = clear_networks, }) local xyz = { @@ -231,8 +231,8 @@ function technic.register_cable(tier, size) node_box = table.copy(node_box), connects_to = {"group:technic_"..ltier.."_cable", "group:technic_"..ltier, "group:technic_all_tiers"}, - on_construct = technic.clear_networks, - after_destruct = technic.clear_networks, + on_construct = clear_networks, + after_destruct = clear_networks, } def.node_box.fixed = { {-size, -size, -size, size, size, size}, @@ -317,7 +317,7 @@ end local function clear_nets_if_machine(pos, node) for tier, machine_list in pairs(technic.machines) do if machine_list[node.name] ~= nil then - return technic.clear_networks(pos) + return clear_networks(pos) end end end From 234a9e9c006ae1f9764fe006e489e2e49e0ec899 Mon Sep 17 00:00:00 2001 From: SomeName42 <> Date: Sun, 17 Nov 2024 17:33:26 +0100 Subject: [PATCH 7/8] Defined clear_networks before clear_network because it is needed in the function. --- technic/machines/register/cables.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/technic/machines/register/cables.lua b/technic/machines/register/cables.lua index 04c0cc4d..48cf836c 100644 --- a/technic/machines/register/cables.lua +++ b/technic/machines/register/cables.lua @@ -43,6 +43,8 @@ local function check_connections(pos) return connections end +local clear_networks + local function clear_network(net) for _,v in pairs(technic.networks[net].all_nodes) do local pos1 = minetest.hash_node_position(v) @@ -62,7 +64,7 @@ local function clear_network(net) end end -local function clear_networks(pos) +clear_networks = function(pos) local node = minetest.get_node(pos) local meta = minetest.get_meta(pos) local placed = node.name ~= "air" From 67c7441c797d87a53f28bf862cfe88927ddb34bf Mon Sep 17 00:00:00 2001 From: SomeName42 <> Date: Thu, 21 Nov 2024 20:20:27 +0100 Subject: [PATCH 8/8] Renamed net variable to network_id in multiple places, removed unneccesarily checking technic.network[network_id] for nil, moved network_id nil checking inside clear_network function --- technic/machines/register/cables.lua | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/technic/machines/register/cables.lua b/technic/machines/register/cables.lua index 48cf836c..a87a3a84 100644 --- a/technic/machines/register/cables.lua +++ b/technic/machines/register/cables.lua @@ -45,13 +45,17 @@ end local clear_networks -local function clear_network(net) - for _,v in pairs(technic.networks[net].all_nodes) do +local function clear_network(network_id) + if not network_id then + return + end + + for _,v in pairs(technic.networks[network_id].all_nodes) do local pos1 = minetest.hash_node_position(v) technic.cables[pos1] = nil end - local network_bckup = technic.networks[net] - technic.networks[net] = nil + local network_bckup = technic.networks[network_id] + technic.networks[network_id] = nil for _,n_pos in pairs(network_bckup.PR_nodes) do clear_networks(n_pos) @@ -86,7 +90,6 @@ clear_networks = function(pos) -- Actually add it to the (cached) network -- !! IMPORTANT: ../switching_station.lua -> check_node_subp() must be kept in sync - pos.visited = 1 if technic.is_tier_cable(node.name, tier) then technic.cables[minetest.hash_node_position(pos)] = network_id table.insert(network.all_nodes,pos) @@ -134,17 +137,12 @@ clear_networks = function(pos) return end - local net = technic.cables[minetest.hash_node_position(pos)] - if net and technic.networks[net] then - clear_network(net) - end + clear_network(technic.cables[minetest.hash_node_position(pos)]) for _,connected_pos in pairs(positions) do - local net = technic.cables[minetest.hash_node_position(connected_pos)] - if net and technic.networks[net] then - -- Not a dead end, so the whole network needs to be recalculated - clear_network(net) - end + local network_id = technic.cables[minetest.hash_node_position(connected_pos)] + -- Not a dead end, so the whole network needs to be recalculated + clear_network(network_id) end end