Optimize electric network operations a little

This commit is contained in:
2025-01-08 22:45:12 +01:00
parent 6e2a3c22cf
commit 752fe4f192
5 changed files with 47 additions and 10 deletions

View File

@@ -76,17 +76,16 @@ function industrialtest.api.powerFlow(pos,sides,flowOverride)
transferred=true
end
local def=minetest.registered_nodes[minetest.get_node(endpoint.position).name]
if def then
local updateFormspec=def._industrialtest_updateFormspec
if updateFormspec then
updateFormspec(endpoint.position)
end
local onPowerFlow=def._industrialtest_onPowerFlow
if onPowerFlow and transferredPower>0 then
onPowerFlow(endpoint.position,industrialtest.api.getOppositeSide(endpoint.side),transferredPower)
if def and def._industrialtest_self then
def._industrialtest_self:updateFormspec(endpoint.position)
if def._industrialtest_self.onPowerFlow and transferredPower>0 then
def._industrialtest_self:onPowerFlow(endpoint.position,industrialtest.api.getOppositeSide(endpoint.side),transferredPower)
end
def._industrialtest_self:triggerIfNeeded(endpoint.position)
else
-- Support for bare definitions that don't use industrialtest pseudo-OOP
minetest.get_node_timer(endpoint.position):start(industrialtest.updateDelay)
end
minetest.get_node_timer(endpoint.position):start(industrialtest.updateDelay)
if not industrialtest.api.isFullyCharged(endpointMeta) then
roomAvailable=true
end