From 09a0d9c8552242aed0dfa0fc975fd2c213fbace7 Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Mon, 20 Jan 2025 22:21:06 +0100 Subject: [PATCH] Use appropriate item power exchange direction --- machines/canning_machine.lua | 8 ++++++-- machines/electric_machine.lua | 35 +++++++++++++++++++++++++---------- machines/generator.lua | 7 ++++++- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/machines/canning_machine.lua b/machines/canning_machine.lua index 6f78634..a9020ea 100644 --- a/machines/canning_machine.lua +++ b/machines/canning_machine.lua @@ -37,7 +37,12 @@ industrialtest.internal.unpackTableInto(industrialtest.CanningMachine,{ "upgrades", "powerStorage" }, - powerLists={"powerStorage"}, + powerLists={ + { + list="powerStorage", + direction="i" + } + }, active={ tiles={ "industrialtest_machine_block.png", @@ -184,7 +189,6 @@ function industrialtest.CanningMachine.shouldDeactivate(self,pos) end function industrialtest.CanningMachine.afterDeactivation(self,pos) - minetest.debug("deactivated") local meta=minetest.get_meta(pos) local inv=meta:get_inventory() local targetSlot=inv:get_stack("dst",1) diff --git a/machines/electric_machine.lua b/machines/electric_machine.lua index 2864699..7c2bf94 100644 --- a/machines/electric_machine.lua +++ b/machines/electric_machine.lua @@ -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 diff --git a/machines/generator.lua b/machines/generator.lua index 31753f0..e0ad45f 100644 --- a/machines/generator.lua +++ b/machines/generator.lua @@ -50,7 +50,12 @@ industrialtest.internal.unpackTableInto(industrialtest.Generator,{ flow=industrialtest.api.lvPowerFlow, ioConfig="oooooo", hasPowerOutput=true, - powerLists={"charged"} + powerLists={ + { + list="charged", + direction="o" + } + } }) function industrialtest.Generator.onConstruct(self,pos)