Use appropriate item power exchange direction

This commit is contained in:
2025-01-20 22:21:06 +01:00
parent fd45e58e9c
commit 09a0d9c855
3 changed files with 37 additions and 13 deletions

View File

@@ -161,16 +161,31 @@ function industrialtest.ElectricMachine.powerExchange(self,pos)
if self.powerLists then
local inv=meta:get_inventory()
local powerFlow=meta:get_int("industrialtest.powerFlow")
for _,list in ipairs(self.powerLists) do
if meta:get_int("industrialtest.powerAmount")<=0 then
break
end
local slot=inv:get_stack(list,1)
if slot:get_count()>0 and not industrialtest.api.isFullyCharged(slot:get_meta()) then
industrialtest.api.transferPowerToItem(meta,slot,powerFlow)
inv:set_stack(list,1,slot)
self:updateFormspec(pos)
shouldRerunTimer=shouldRerunTimer or (not industrialtest.api.isFullyCharged(slot:get_meta()) and meta:get_int("industrialtest.powerAmount")>0)
for _,listDesc in ipairs(self.powerLists) do
local slot=inv:get_stack(listDesc.list,1)
if slot:get_count()>0 then
if listDesc.direction=="o" then
if meta:get_int("industrialtest.powerAmount")<=0 then
break
end
if not industrialtest.api.isFullyCharged(slot:get_meta()) then
industrialtest.api.transferPowerToItem(meta,slot,powerFlow)
inv:set_stack(listDesc.list,1,slot)
self:updateFormspec(pos)
shouldRerunTimer=shouldRerunTimer or (not industrialtest.api.isFullyCharged(slot:get_meta()) and meta:get_int("industrialtest.powerAmount")>0)
end
elseif listDesc.direction=="i" then
if industrialtest.api.isFullyCharged(meta) then
break
end
local slotMeta=slot:get_meta()
if slotMeta:get_int("industrialtest.powerAmount")>0 then
industrialtest.api.transferPowerFromItem(slot,meta,powerFlow)
inv:set_stack(listDesc.list,1,slot)
self:updateFormspec(pos)
shouldRerunTimer=shouldRerunTimer or (not industrialtest.api.isFullyCharged(meta) and slotMeta:get_int("industrialtest.powerAmount")>0)
end
end
end
end
end