Attach new machines and cables to touched networks

This commit is contained in:
mrkubax10 2023-11-14 11:46:30 +01:00
parent c3b49b68e1
commit 340c46bf48
3 changed files with 35 additions and 16 deletions

View File

@ -15,6 +15,20 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
local S=minetest.get_translator("industrialtest") local S=minetest.get_translator("industrialtest")
local cable={}
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)
end
end
end
end
local function registerCable(name,displayName,size,flow,registerInsulated) local function registerCable(name,displayName,size,flow,registerInsulated)
local definition={ local definition={
@ -88,7 +102,8 @@ local function registerCable(name,displayName,size,flow,registerInsulated)
"group:_industrialtest_hasPowerInput", "group:_industrialtest_hasPowerInput",
"group:_industrialtest_hasPowerOutput", "group:_industrialtest_hasPowerOutput",
"group:_industrialtest_cable" "group:_industrialtest_cable"
} },
on_construct=cable.onConstruct
} }
if industrialtest.mtgAvailable then if industrialtest.mtgAvailable then
definition.groups={ definition.groups={

View File

@ -65,25 +65,30 @@ machine.onConstruct=function(pos,config)
industrialtest.api.addPowerStorage(meta,config.capacity,config.flow,config.ioConfig) industrialtest.api.addPowerStorage(meta,config.capacity,config.flow,config.ioConfig)
meta:set_string("formspec",machine.getFormspec(pos,config)) meta:set_string("formspec",machine.getFormspec(pos,config))
if config.groups and config.groups._industrialtest_hasPowerInput then if config.groups then
local connections=industrialtest.api.getConnections(pos) if config.groups._industrialtest_hasPowerInput then
for _,conn in ipairs(connections) do local connections=industrialtest.api.getConnections(pos)
local connectionMeta=minetest.get_meta(conn) for _,conn in ipairs(connections) do
if industrialtest.api.isNetworkMaster(connectionMeta) then local connectionMeta=minetest.get_meta(conn)
industrialtest.api.createNetworkMapForNode(conn) if industrialtest.api.isNetworkMaster(connectionMeta) then
else industrialtest.api.createNetworkMapForNode(conn)
local def=minetest.registered_nodes[minetest.get_node(conn).name] else
if def.groups._industrialtest_cable then local def=minetest.registered_nodes[minetest.get_node(conn).name]
local networks=industrialtest.api.isAttachedToNetwork(connectionMeta) if def.groups._industrialtest_cable then
if networks then local networks=industrialtest.api.isAttachedToNetwork(connectionMeta)
for _,network in ipairs(networks) do if networks then
industrialtest.api.createNetworkMapForNode(network) for _,network in ipairs(networks) do
minetest.get_node_timer(network):start(industrialtest.updateDelay) industrialtest.api.createNetworkMapForNode(network)
minetest.get_node_timer(network):start(industrialtest.updateDelay)
end
end end
end end
end end
end end
end end
if config.groups._industrialtest_hasPowerOutput then
meta:set_string("industrialtest.network",minetest.serialize(industrialtest.api.createNetworkMap(pos)))
end
end end
if config.onConstruct then if config.onConstruct then

View File

@ -55,7 +55,6 @@ generator.onConstruct=function(pos,meta,inv)
inv:set_size("fuel",1) inv:set_size("fuel",1)
meta:set_int("fuelTime",0) meta:set_int("fuelTime",0)
meta:set_int("maxFuelTime",1) meta:set_int("maxFuelTime",1)
meta:set_string("industrialtest.network",minetest.serialize(industrialtest.api.createNetworkMap(pos)))
end end
generator.onTimer=function(pos,elapsed,meta,inv) generator.onTimer=function(pos,elapsed,meta,inv)