diff --git a/technic/machines/HV/nuclear_reactor.lua b/technic/machines/HV/nuclear_reactor.lua index c221c7e..ac42037 100644 --- a/technic/machines/HV/nuclear_reactor.lua +++ b/technic/machines/HV/nuclear_reactor.lua @@ -490,11 +490,10 @@ minetest.register_node("technic:hv_nuclear_reactor_core_active", { timer:start(1) end, on_timer = function(pos, node) - local meta = minetest.get_meta(pos) - -- Connected back? - if meta:get_int("HV_EU_timeout") > 0 then return false end + if technic.get_timeout("HV", pos) > 0 then return false end + local meta = minetest.get_meta(pos) local burn_time = meta:get_int("burn_time") or 0 if burn_time >= burn_ticks or burn_time == 0 then diff --git a/technic/machines/power_monitor.lua b/technic/machines/power_monitor.lua index f25e8f7..51eeeee 100644 --- a/technic/machines/power_monitor.lua +++ b/technic/machines/power_monitor.lua @@ -101,7 +101,7 @@ minetest.register_abm({ local sw_pos = get_swpos(pos) local timeout = 0 for tier in pairs(technic.machines) do - timeout = math.max(meta:get_int(tier.."_EU_timeout"),timeout) + timeout = math.max(technic.get_timeout(tier, pos),timeout) end if timeout > 0 and sw_pos then local sw_meta = minetest.get_meta(sw_pos) diff --git a/technic/machines/register/generator.lua b/technic/machines/register/generator.lua index 9120e29..91a942e 100644 --- a/technic/machines/register/generator.lua +++ b/technic/machines/register/generator.lua @@ -206,12 +206,12 @@ function technic.register_generator(data) timer:start(1) end, on_timer = function(pos, node) + -- Connected back? + if technic.get_timeout(tier, pos) > 0 then return false end + local meta = minetest.get_meta(pos) local node = minetest.get_node(pos) - -- Connected back? - if meta:get_int(tier.."_EU_timeout") > 0 then return false end - local burn_time = meta:get_int("burn_time") or 0 if burn_time <= 0 then diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua index 6479fcc..6dacfec 100644 --- a/technic/machines/switching_station.lua +++ b/technic/machines/switching_station.lua @@ -10,6 +10,12 @@ local reset_overloaded = function(network_id) local remaining = math.max(0, overloaded_networks[network_id] - minetest.get_us_time()) if remaining == 0 then -- Clear cache, remove overload and restart network + local cables = technic.cables + for pos_hash,cable_net_id in pairs(cables) do + if cable_net_id == network_id then + cables[pos_hash] = nil + end + end overloaded_networks[network_id] = nil technic.networks[network_id] = nil end @@ -163,7 +169,8 @@ local function check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes overloaded_networks[net_id_new] = overloaded_networks[net_id_old] -- delete caches for conflicting network technic.networks[net_id_old] = nil - technic.cables[pos] = net_id_new + technic.networks[net_id_new] = nil + technic.cables[pos_hash] = net_id_new meta:set_string("infotext",S("Network Overloaded")) return false end @@ -185,7 +192,7 @@ local function check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes add_network_node(BA_nodes, pos, network_id) end - meta:set_int(tier.."_EU_timeout", 2) -- Touch node + technic.touch_node(tier, pos, 2) -- Touch node end return true end @@ -207,10 +214,32 @@ local function traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_node return true end +technic.node_timeout = {} + +technic.pos2network = function(pos) + return technic.cables[minetest.hash_node_position(pos)] +end + +technic.get_timeout = function(tier, pos) + if technic.node_timeout[tier] == nil then + -- it is normal that some multi tier nodes always drop here when checking all LV, MV and HV tiers + return 0 + end + return technic.node_timeout[tier][minetest.hash_node_position(pos)] or 0 +end + +technic.touch_node = function(tier, pos, timeout) + if technic.node_timeout[tier] == nil then + -- this should get built up during registration + technic.node_timeout[tier] = {} + end + technic.node_timeout[tier][minetest.hash_node_position(pos)] = timeout or 2 +end + local function touch_nodes(list, tier) + local touch_node = technic.touch_node for _, pos in ipairs(list) do - local meta = minetest.get_meta(pos) - meta:set_int(tier.."_EU_timeout", 2) -- Touch node + touch_node(tier, pos, 2) -- Touch node end end @@ -224,7 +253,7 @@ local function get_network(network_id, sw_pos, pos1, tier) local meta = minetest.get_meta(pos) meta:set_int("active", 0) meta:set_string("active_pos", minetest.serialize(sw_pos)) - meta:set_int(tier.."_EU_timeout", 2) -- Touch node + technic.touch_node(tier, pos, 2) -- Touch node end return cached.PR_nodes, cached.BA_nodes, cached.RE_nodes end @@ -524,13 +553,13 @@ end -- Timeout for a node in case it was disconnected from the network -- A node must be touched by the station continuously in order to function local function switching_station_timeout_count(pos, tier) - local meta = minetest.get_meta(pos) - local timeout = meta:get_int(tier.."_EU_timeout") + local timeout = technic.get_timeout(tier, pos) if timeout <= 0 then + local meta = minetest.get_meta(pos) meta:set_int(tier.."_EU_input", 0) -- Not needed anymore <-- actually, it is for supply converter return true else - meta:set_int(tier.."_EU_timeout", timeout - 1) + technic.touch_node(tier, pos, timeout - 1) return false end end