forked from mrkubax10/industrialtest
Optimize electric network operations a little
This commit is contained in:
@@ -116,6 +116,20 @@ function industrialtest.Machine.allowMetadataInventoryPut(self,pos,listname,inde
|
||||
return industrialtest.Machine.allowMetadataInventoryPut(self,pos,listname,index,stack,player)
|
||||
end
|
||||
|
||||
function industrialtest.ElectricMachine.requestPower(self,pos)
|
||||
if not self.hasPowerOutput then
|
||||
return
|
||||
end
|
||||
local meta=minetest.get_meta(pos)
|
||||
if meta:get_int("industrialtest.powerAmount")<=0 then
|
||||
return
|
||||
end
|
||||
local spaceAvailable,flowTransferred=industrialtest.api.powerFlow(pos)
|
||||
if (spaceAvailable and meta:get_int("industrialtest.powerAmount")>0) or self:canUpdate(pos) then
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
end
|
||||
|
||||
function industrialtest.ElectricMachine.powerExchange(self,pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local shouldRerunTimer=false
|
||||
@@ -124,7 +138,13 @@ function industrialtest.ElectricMachine.powerExchange(self,pos)
|
||||
local networks=industrialtest.api.isAttachedToNetwork(meta)
|
||||
if networks then
|
||||
for _,network in ipairs(networks) do
|
||||
minetest.get_node_timer(network):start(industrialtest.updateDelay)
|
||||
local def=minetest.registered_nodes[minetest.get_node(network).name]
|
||||
if def and def._industrialtest_self then
|
||||
def._industrialtest_self:requestPower(network)
|
||||
else
|
||||
-- Support for bare definitions that don't use industrialtest pseudo-OOP
|
||||
minetest.get_node_timer(network):start(industrialtest.updateDelay)
|
||||
end
|
||||
end
|
||||
end
|
||||
shouldRerunTimer=shouldRerunTimer or not industrialtest.api.isFullyCharged(meta)
|
||||
|
||||
Reference in New Issue
Block a user