Trigger network master if endpoint is not fully charged

This commit is contained in:
mrkubax10 2023-11-16 17:33:36 +01:00
parent 8724b563c4
commit bd51f1d18f
2 changed files with 14 additions and 3 deletions

View File

@ -473,10 +473,11 @@ industrialtest.api.getConnections=function(pos,direction)
for key,conn in ipairs(neighbourPositions) do for key,conn in ipairs(neighbourPositions) do
local meta=minetest.get_meta(conn) local meta=minetest.get_meta(conn)
local def=minetest.registered_nodes[minetest.get_node(conn).name] local def=minetest.registered_nodes[minetest.get_node(conn).name]
local powerOutput=(sourceDef.groups._industrialtest_cable or industrialtest.api.isPowerOutput(sourceMeta,key)) local normalizedKey=industrialtest.api.normalizeSide(pos,key)
local powerInput=(sourceDef.groups._industrialtest_cable or industrialtest.api.isPowerInput(sourceMeta,key)) local powerOutput=(sourceDef.groups._industrialtest_cable or industrialtest.api.isPowerOutput(sourceMeta,normalizedKey))
local powerInput=(sourceDef.groups._industrialtest_cable or industrialtest.api.isPowerInput(sourceMeta,normalizedKey))
if def.groups._industrialtest_cable or industrialtest.api.hasPowerStorage(meta) then if def.groups._industrialtest_cable or industrialtest.api.hasPowerStorage(meta) then
local side=industrialtest.api.getOppositeSide(key) local side=industrialtest.api.getOppositeSide(normalizedKey)
if (powerOutput and directionInput and (def.groups._industrialtest_cable or industrialtest.api.isPowerInput(meta,side))) or ((def.groups._industrialtest_cable or industrialtest.api.isPowerOutput(meta,side)) and powerInput and directionOutput) then if (powerOutput and directionInput and (def.groups._industrialtest_cable or industrialtest.api.isPowerInput(meta,side))) or ((def.groups._industrialtest_cable or industrialtest.api.isPowerOutput(meta,side)) and powerInput and directionOutput) then
table.insert(result,conn) table.insert(result,conn)
end end

View File

@ -134,6 +134,16 @@ machine.onTimer=function(pos,elapsed,config)
shouldRerunTimer,shouldUpdateFormspec=config.onTimer(pos,elapsed,meta,inv) shouldRerunTimer,shouldUpdateFormspec=config.onTimer(pos,elapsed,meta,inv)
end end
local def=minetest.registered_nodes[minetest.get_node(pos).name]
if def.groups and def.groups._industrialtest_hasPowerInput and not industrialtest.api.isFullyCharged(meta) then
local networks=industrialtest.api.isAttachedToNetwork(meta)
if networks then
for _,network in ipairs(networks) do
minetest.get_node_timer(network):start(industrialtest.updateDelay)
end
end
end
if shouldUpdateFormspec then if shouldUpdateFormspec then
machine.updateFormspec(pos,config) machine.updateFormspec(pos,config)
end end