Remove disconnected machines after cable is destructed

This commit is contained in:
2023-11-14 20:49:05 +01:00
parent 42130c90a7
commit 5ea9002630
2 changed files with 71 additions and 50 deletions

View File

@@ -21,15 +21,29 @@ cable.onConstruct=function(pos)
local connections=industrialtest.api.getConnections(pos)
for _,conn in ipairs(connections) do
local meta=minetest.get_meta(conn)
local networks=industrialtest.api.isAttachedToNetwork(meta)
if networks then
for _,network in ipairs(networks) do
industrialtest.api.createNetworkMapForNode(network)
if industrialtest.api.isNetworkMaster(meta) then
industrialtest.api.createNetworkMapForNode(conn)
else
local networks=industrialtest.api.isAttachedToNetwork(meta)
if networks then
for _,network in ipairs(networks) do
industrialtest.api.createNetworkMapForNode(network)
end
end
end
end
end
cable.onDestruct=function(pos)
local meta=minetest.get_meta(pos)
local networks=industrialtest.api.isAttachedToNetwork(meta)
if networks then
for _,network in ipairs(networks) do
industrialtest.api.createNetworkMapForNode(network,pos)
end
end
end
local function registerCable(name,displayName,size,flow,registerInsulated)
local definition={
description=S(displayName.." Cable"),
@@ -104,6 +118,7 @@ local function registerCable(name,displayName,size,flow,registerInsulated)
"group:_industrialtest_cable"
},
on_construct=cable.onConstruct,
on_destruct=cable.onDestruct,
_industrialtest_cableFlow=flow
}
if industrialtest.mtgAvailable then