Fixes in ActivatedElectricMachine and ElectricMachine

This commit is contained in:
2024-10-25 12:40:27 +02:00
parent 1f6f711b64
commit 83ee6fb4c8
2 changed files with 48 additions and 7 deletions

View File

@@ -78,8 +78,8 @@ end
function industrialtest.ElectricMachine.onTimer(self,pos,elapsed)
local result=industrialtest.Machine.onTimer(self,pos,elapsed)
self:requestPower(pos)
return result
local result2=self:powerExchange(pos)
return result or result2
end
function industrialtest.Machine.allowMetadataInventoryMove(self,pos,fromList,fromIndex,toList,toIndex,count)
@@ -116,8 +116,10 @@ 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)
function industrialtest.ElectricMachine.powerExchange(self,pos)
local meta=minetest.get_meta(pos)
local shouldRerunTimer=false
if self.hasPowerInput and not industrialtest.api.isFullyCharged(meta) then
local networks=industrialtest.api.isAttachedToNetwork(meta)
if networks then
@@ -125,5 +127,40 @@ function industrialtest.ElectricMachine.requestPower(self,pos)
minetest.get_node_timer(network):start(industrialtest.updateDelay)
end
end
shouldRerunTimer=shouldRerunTimer or not industrialtest.api.isFullyCharged(meta)
end
if self.hasPowerOutput and meta:get_int("industrialtest.powerAmount")>0 then
local spaceAvailable,flowTransferred=industrialtest.api.powerFlow(pos)
if flowTransferred then
self:updateFormspec(pos)
end
shouldRerunTimer=shouldRerunTimer or spaceAvailable
end
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)
end
end
end
return shouldRerunTimer
end
function industrialtest.ElectricMachine.createPowerIndicatorWidget(charged,x,y)
return table.concat({
string.format("box[%f,%f;0.3,4.8;#202020]",x,y),
(charged>0 and string.format("box[%f,%f;0.3,%f;#FF1010]",x,y+4.8-(charged*4.8),charged*4.8) or ""),
},"")
end