Fix some machines locking sometimes

This commit is contained in:
2023-11-15 21:44:02 +01:00
parent 659e8ad5ed
commit 8724b563c4
7 changed files with 46 additions and 56 deletions

View File

@@ -72,6 +72,7 @@ machine.onConstruct=function(pos,config)
local connectionMeta=minetest.get_meta(conn)
if industrialtest.api.isNetworkMaster(connectionMeta) then
industrialtest.api.createNetworkMapForNode(conn)
minetest.get_node_timer(conn):start(industrialtest.updateDelay)
else
local def=minetest.registered_nodes[minetest.get_node(conn).name]
if def.groups._industrialtest_cable then
@@ -100,10 +101,25 @@ end
machine.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.removeNodeFromNetwork(network,pos)
if industrialtest.api.isNetworkMaster(meta) then
local network=industrialtest.api.createNetworkMap(pos,true)
for _,endpoint in ipairs(network) do
local endpointMeta=minetest.get_meta(endpoint.position)
local networks=industrialtest.api.isAttachedToNetwork(endpointMeta)
for key,value in ipairs(networks) do
if value.x==pos.x and value.y==pos.y and value.z==pos.z then
table.remove(networks,key)
break
end
end
endpointMeta:set_string("industrialtest.networks",minetest.serialize(networks))
end
else
local networks=industrialtest.api.isAttachedToNetwork(meta)
if networks then
for _,network in ipairs(networks) do
industrialtest.api.removeNodeFromNetwork(network,pos)
end
end
end
end
@@ -119,7 +135,7 @@ machine.onTimer=function(pos,elapsed,config)
end
if shouldUpdateFormspec then
meta:set_string("formspec",machine.getFormspec(pos,config))
machine.updateFormspec(pos,config)
end
return shouldRerunTimer
@@ -179,7 +195,8 @@ function industrialtest.internal.registerMachine(config)
end,
on_destruct=machine.onDestruct,
on_timer=function(pos,elapsed)
return machine.onTimer(pos,elapsed,config)
local shouldRerunTimer,_=machine.onTimer(pos,elapsed,config)
return shouldRerunTimer
end,
allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count)
return machine.allowMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count,config)
@@ -256,12 +273,12 @@ function industrialtest.internal.registerMachine(config)
local shouldRerunTimer=false
local shouldUpdateFormspec=false
if config.onTimer then
if config.activeOnTimer then
shouldRerunTimer,shouldUpdateFormspec=config.activeOnTimer(pos,elapsed,meta,inv)
end
if shouldUpdateFormspec then
meta:set_string("formspec",machine.getFormspec(pos,config))
machine.updateFormspec(pos,config)
end
return shouldRerunTimer
@@ -441,9 +458,6 @@ simpleElectricItemProcessor.onTimer=function(pos,elapsed,meta,inv,config)
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end
end
if not industrialtest.api.isFullyCharged(meta) then
industrialtest.api.triggerNeighbours(pos)
end
return shouldRerunTimer,shouldUpdateFormspec
end
@@ -549,8 +563,8 @@ simpleElectricItemProcessor.activeOnTimer=function(pos,elapsed,meta,inv,config)
end
if meta:get_float("maxSrcTime")<=0 or meta:get_int("industrialtest.powerAmount")<requiredPower then
minetest.swap_node(pos,{
name="industrialtest:"..config.name,
param2=minetest.get_node(pos).param2
name="industrialtest:"..config.name,
param2=minetest.get_node(pos).param2
})
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end
@@ -563,9 +577,6 @@ simpleElectricItemProcessor.activeOnTimer=function(pos,elapsed,meta,inv,config)
end
inv:set_stack("src",1,output.src)
end
if not industrialtest.api.isFullyCharged(meta) then
industrialtest.api.triggerNeighbours(pos)
end
return shouldRerunTimer,shouldUpdateFormspec
end
@@ -610,7 +621,7 @@ function industrialtest.internal.registerSimpleElectricItemProcessor(config)
},
onConstruct=simpleElectricItemProcessor.onConstruct,
onTimer=function(pos,elapsed,meta,inv)
simpleElectricItemProcessor.onTimer(pos,elapsed,meta,inv,config)
return simpleElectricItemProcessor.onTimer(pos,elapsed,meta,inv,config)
end,
allowMetadataInventoryMove=simpleElectricItemProcessor.allowMetadataInventoryMove,
allowMetadataInventoryPut=simpleElectricItemProcessor.allowMetadataInventoryPut,
@@ -618,7 +629,7 @@ function industrialtest.internal.registerSimpleElectricItemProcessor(config)
onMetadataInventoryMove=simpleElectricItemProcessor.onMetadataInventoryMove,
onMetadataInventoryTake=simpleElectricItemProcessor.onMetadataInventoryTake,
activeOnTimer=function(pos,elapsed,meta,inv)
simpleElectricItemProcessor.activeOnTimer(pos,elapsed,meta,inv,config)
return simpleElectricItemProcessor.activeOnTimer(pos,elapsed,meta,inv,config)
end
})
end