diff --git a/cables.lua b/cables.lua index 83850bb..a8be0c1 100644 --- a/cables.lua +++ b/cables.lua @@ -15,6 +15,20 @@ -- along with this program. If not, see . 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 definition={ @@ -88,7 +102,8 @@ local function registerCable(name,displayName,size,flow,registerInsulated) "group:_industrialtest_hasPowerInput", "group:_industrialtest_hasPowerOutput", "group:_industrialtest_cable" - } + }, + on_construct=cable.onConstruct } if industrialtest.mtgAvailable then definition.groups={ diff --git a/machines/common.lua b/machines/common.lua index 138e5cd..a8f26d5 100644 --- a/machines/common.lua +++ b/machines/common.lua @@ -65,25 +65,30 @@ machine.onConstruct=function(pos,config) industrialtest.api.addPowerStorage(meta,config.capacity,config.flow,config.ioConfig) meta:set_string("formspec",machine.getFormspec(pos,config)) - if config.groups and config.groups._industrialtest_hasPowerInput then - local connections=industrialtest.api.getConnections(pos) - for _,conn in ipairs(connections) do - local connectionMeta=minetest.get_meta(conn) - if industrialtest.api.isNetworkMaster(connectionMeta) then - industrialtest.api.createNetworkMapForNode(conn) - else - local def=minetest.registered_nodes[minetest.get_node(conn).name] - if def.groups._industrialtest_cable then - local networks=industrialtest.api.isAttachedToNetwork(connectionMeta) - if networks then - for _,network in ipairs(networks) do - industrialtest.api.createNetworkMapForNode(network) - minetest.get_node_timer(network):start(industrialtest.updateDelay) + if config.groups then + if config.groups._industrialtest_hasPowerInput then + local connections=industrialtest.api.getConnections(pos) + for _,conn in ipairs(connections) do + local connectionMeta=minetest.get_meta(conn) + if industrialtest.api.isNetworkMaster(connectionMeta) then + industrialtest.api.createNetworkMapForNode(conn) + else + local def=minetest.registered_nodes[minetest.get_node(conn).name] + if def.groups._industrialtest_cable then + local networks=industrialtest.api.isAttachedToNetwork(connectionMeta) + if networks then + for _,network in ipairs(networks) do + industrialtest.api.createNetworkMapForNode(network) + minetest.get_node_timer(network):start(industrialtest.updateDelay) + 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 if config.onConstruct then diff --git a/machines/generator.lua b/machines/generator.lua index 4d9eaaa..5cdc291 100644 --- a/machines/generator.lua +++ b/machines/generator.lua @@ -55,7 +55,6 @@ generator.onConstruct=function(pos,meta,inv) inv:set_size("fuel",1) meta:set_int("fuelTime",0) meta:set_int("maxFuelTime",1) - meta:set_string("industrialtest.network",minetest.serialize(industrialtest.api.createNetworkMap(pos))) end generator.onTimer=function(pos,elapsed,meta,inv)