Attach new machines and cables to touched networks
This commit is contained in:
parent
c3b49b68e1
commit
340c46bf48
17
cables.lua
17
cables.lua
|
@ -15,6 +15,20 @@
|
|||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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={
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue