mirror of
https://github.com/minetest-mods/technic.git
synced 2024-08-20 21:44:14 +02:00
Merge pull request #315 from cheapie/master
Only update the associated network(s) when placing/digging nodes
This commit is contained in:
commit
ff6675ef28
@ -11,8 +11,19 @@ function technic.get_cable_tier(name)
|
|||||||
return cable_tier[name]
|
return cable_tier[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function clear_networks()
|
local function clear_networks(pos)
|
||||||
technic.networks = {}
|
local positions = {
|
||||||
|
{x=pos.x+1, y=pos.y, z=pos.z},
|
||||||
|
{x=pos.x-1, y=pos.y, z=pos.z},
|
||||||
|
{x=pos.x, y=pos.y+1, z=pos.z},
|
||||||
|
{x=pos.x, y=pos.y-1, z=pos.z},
|
||||||
|
{x=pos.x, y=pos.y, z=pos.z+1},
|
||||||
|
{x=pos.x, y=pos.y, z=pos.z-1}}
|
||||||
|
for _,connected_pos in pairs(positions) do
|
||||||
|
if technic.cables[minetest.hash_node_position(connected_pos)] then
|
||||||
|
technic.networks[technic.cables[minetest.hash_node_position(connected_pos)]] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function technic.register_cable(tier, size)
|
function technic.register_cable(tier, size)
|
||||||
@ -55,7 +66,7 @@ end
|
|||||||
local function clear_nets_if_machine(pos, node)
|
local function clear_nets_if_machine(pos, node)
|
||||||
for tier, machine_list in pairs(technic.machines) do
|
for tier, machine_list in pairs(technic.machines) do
|
||||||
if machine_list[node.name] ~= nil then
|
if machine_list[node.name] ~= nil then
|
||||||
return clear_networks()
|
return clear_networks(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,6 +59,7 @@ minetest.register_node("technic:supply_converter", {
|
|||||||
meta:set_float("active", false)
|
meta:set_float("active", false)
|
||||||
end,
|
end,
|
||||||
technic_run = run,
|
technic_run = run,
|
||||||
|
technic_on_disable = run,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
-- This way the supplies are separated per network.
|
-- This way the supplies are separated per network.
|
||||||
|
|
||||||
technic.networks = {}
|
technic.networks = {}
|
||||||
|
technic.cables = {}
|
||||||
|
|
||||||
local S = technic.getter
|
local S = technic.getter
|
||||||
|
|
||||||
@ -64,7 +65,8 @@ minetest.register_node("technic:switching_station",{
|
|||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
-- Add a wire node to the LV/MV/HV network
|
-- Add a wire node to the LV/MV/HV network
|
||||||
local add_new_cable_node = function(nodes, pos)
|
local add_new_cable_node = function(nodes, pos, network_id)
|
||||||
|
technic.cables[minetest.hash_node_position(pos)] = network_id
|
||||||
-- Ignore if the node has already been added
|
-- Ignore if the node has already been added
|
||||||
for i = 1, #nodes do
|
for i = 1, #nodes do
|
||||||
if pos.x == nodes[i].x and
|
if pos.x == nodes[i].x and
|
||||||
@ -78,31 +80,31 @@ local add_new_cable_node = function(nodes, pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Generic function to add found connected nodes to the right classification array
|
-- Generic function to add found connected nodes to the right classification array
|
||||||
local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, from_below)
|
local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, from_below, network_id)
|
||||||
technic.get_or_load_node(pos)
|
technic.get_or_load_node(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local name = minetest.get_node(pos).name
|
local name = minetest.get_node(pos).name
|
||||||
|
|
||||||
if technic.is_tier_cable(name, tier) then
|
if technic.is_tier_cable(name, tier) then
|
||||||
add_new_cable_node(all_nodes, pos)
|
add_new_cable_node(all_nodes, pos,network_id)
|
||||||
elseif machines[name] then
|
elseif machines[name] then
|
||||||
--dprint(name.." is a "..machines[name])
|
--dprint(name.." is a "..machines[name])
|
||||||
if machines[name] == technic.producer then
|
if machines[name] == technic.producer then
|
||||||
add_new_cable_node(PR_nodes, pos)
|
add_new_cable_node(PR_nodes, pos, network_id)
|
||||||
elseif machines[name] == technic.receiver then
|
elseif machines[name] == technic.receiver then
|
||||||
add_new_cable_node(RE_nodes, pos)
|
add_new_cable_node(RE_nodes, pos, network_id)
|
||||||
elseif machines[name] == technic.producer_receiver then
|
elseif machines[name] == technic.producer_receiver then
|
||||||
add_new_cable_node(PR_nodes, pos)
|
add_new_cable_node(PR_nodes, pos, network_id)
|
||||||
add_new_cable_node(RE_nodes, pos)
|
add_new_cable_node(RE_nodes, pos, network_id)
|
||||||
elseif machines[name] == "SPECIAL" and
|
elseif machines[name] == "SPECIAL" and
|
||||||
(pos.x ~= sw_pos.x or pos.y ~= sw_pos.y or pos.z ~= sw_pos.z) and
|
(pos.x ~= sw_pos.x or pos.y ~= sw_pos.y or pos.z ~= sw_pos.z) and
|
||||||
from_below then
|
from_below then
|
||||||
-- Another switching station -> disable it
|
-- Another switching station -> disable it
|
||||||
add_new_cable_node(SP_nodes, pos)
|
add_new_cable_node(SP_nodes, pos, network_id)
|
||||||
meta:set_int("active", 0)
|
meta:set_int("active", 0)
|
||||||
meta:set_string("active_pos", minetest.serialize(sw_pos))
|
meta:set_string("active_pos", minetest.serialize(sw_pos))
|
||||||
elseif machines[name] == technic.battery then
|
elseif machines[name] == technic.battery then
|
||||||
add_new_cable_node(BA_nodes, pos)
|
add_new_cable_node(BA_nodes, pos, network_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
meta:set_int(tier.."_EU_timeout", 2) -- Touch node
|
meta:set_int(tier.."_EU_timeout", 2) -- Touch node
|
||||||
@ -110,7 +112,7 @@ local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nod
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Traverse a network given a list of machines and a cable type name
|
-- Traverse a network given a list of machines and a cable type name
|
||||||
local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, i, machines, tier, sw_pos)
|
local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, i, machines, tier, sw_pos, network_id)
|
||||||
local pos = all_nodes[i]
|
local pos = all_nodes[i]
|
||||||
local positions = {
|
local positions = {
|
||||||
{x=pos.x+1, y=pos.y, z=pos.z},
|
{x=pos.x+1, y=pos.y, z=pos.z},
|
||||||
@ -121,7 +123,7 @@ local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_no
|
|||||||
{x=pos.x, y=pos.y, z=pos.z-1}}
|
{x=pos.x, y=pos.y, z=pos.z-1}}
|
||||||
--print("ON")
|
--print("ON")
|
||||||
for i, cur_pos in pairs(positions) do
|
for i, cur_pos in pairs(positions) do
|
||||||
check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, cur_pos, machines, tier, sw_pos, i == 3)
|
check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, cur_pos, machines, tier, sw_pos, i == 3, network_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -153,7 +155,7 @@ local get_network = function(sw_pos, pos1, tier)
|
|||||||
local all_nodes = {pos1}
|
local all_nodes = {pos1}
|
||||||
repeat
|
repeat
|
||||||
traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes,
|
traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes,
|
||||||
i, technic.machines[tier], tier, sw_pos)
|
i, technic.machines[tier], tier, sw_pos, minetest.hash_node_position(pos1))
|
||||||
i = i + 1
|
i = i + 1
|
||||||
until all_nodes[i] == nil
|
until all_nodes[i] == nil
|
||||||
technic.networks[minetest.hash_node_position(pos1)] = {tier = tier, PR_nodes = PR_nodes,
|
technic.networks[minetest.hash_node_position(pos1)] = {tier = tier, PR_nodes = PR_nodes,
|
||||||
|
Loading…
Reference in New Issue
Block a user