Use appropriate item power exchange direction

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

View File

@ -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)

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

View File

@ -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)