Fixes in ActivatedElectricMachine and ElectricMachine

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

View File

@ -17,14 +17,17 @@
industrialtest.ActivatedElectricMachine=table.copy(industrialtest.ElectricMachine) industrialtest.ActivatedElectricMachine=table.copy(industrialtest.ElectricMachine)
function industrialtest.ActivatedElectricMachine.onTimer(self,pos,elapsed) function industrialtest.ActivatedElectricMachine.onTimer(self,pos,elapsed)
industrialtest.ElectricMachine.requestPower(self,pos) local result=self:powerExchange(pos)
return industrialtest.ActivatedMachine.onTimer(self,pos,elapsed) local result2=industrialtest.ActivatedMachine.onTimer(self,pos,elapsed)
return result or result2
end end
industrialtest.ActivatedElectricMachine.register=industrialtest.ActivatedMachine.register industrialtest.ActivatedElectricMachine.register=industrialtest.ActivatedMachine.register
industrialtest.ActivatedElectricMachine.createDefinitionTable=industrialtest.ActivatedMachine.createDefinitionTable industrialtest.ActivatedElectricMachine.createDefinitionTable=industrialtest.ActivatedMachine.createDefinitionTable
industrialtest.ActivatedElectricMachine.createActiveDefinitionTable=industrialtest.ActivatedMachine.createActiveDefinitionTable
industrialtest.ActivatedElectricMachine.shouldActivate=industrialtest.ActivatedMachine.shouldActivate industrialtest.ActivatedElectricMachine.shouldActivate=industrialtest.ActivatedMachine.shouldActivate
industrialtest.ActivatedElectricMachine.shouldDeactivate=industrialtest.ActivatedMachine.shouldDeactivate industrialtest.ActivatedElectricMachine.shouldDeactivate=industrialtest.ActivatedMachine.shouldDeactivate
@ -34,7 +37,8 @@ industrialtest.ActivatedElectricMachine.afterActivation=industrialtest.Activated
industrialtest.ActivatedElectricMachine.afterDeactivation=industrialtest.ActivatedMachine.afterDeactivation industrialtest.ActivatedElectricMachine.afterDeactivation=industrialtest.ActivatedMachine.afterDeactivation
function industrialtest.ActivatedElectricMachine.activeOnTimer(self,pos,elapsed) function industrialtest.ActivatedElectricMachine.activeOnTimer(self,pos,elapsed)
industrialtest.ElectricMachine.requestPower(self,pos) local result=self:powerExchange(pos)
return industrialtest.ActivatedMachine.activeOnTimer(self,pos,elapsed) local result2=industrialtest.ActivatedMachine.activeOnTimer(self,pos,elapsed)
return result or result2
end end

View File

@ -78,8 +78,8 @@ end
function industrialtest.ElectricMachine.onTimer(self,pos,elapsed) function industrialtest.ElectricMachine.onTimer(self,pos,elapsed)
local result=industrialtest.Machine.onTimer(self,pos,elapsed) local result=industrialtest.Machine.onTimer(self,pos,elapsed)
self:requestPower(pos) local result2=self:powerExchange(pos)
return result return result or result2
end end
function industrialtest.Machine.allowMetadataInventoryMove(self,pos,fromList,fromIndex,toList,toIndex,count) 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) return industrialtest.Machine.allowMetadataInventoryPut(self,pos,listname,index,stack,player)
end end
function industrialtest.ElectricMachine.requestPower(self,pos) function industrialtest.ElectricMachine.powerExchange(self,pos)
local meta=minetest.get_meta(pos) local meta=minetest.get_meta(pos)
local shouldRerunTimer=false
if self.hasPowerInput and not industrialtest.api.isFullyCharged(meta) then if self.hasPowerInput and not industrialtest.api.isFullyCharged(meta) then
local networks=industrialtest.api.isAttachedToNetwork(meta) local networks=industrialtest.api.isAttachedToNetwork(meta)
if networks then if networks then
@ -125,5 +127,40 @@ function industrialtest.ElectricMachine.requestPower(self,pos)
minetest.get_node_timer(network):start(industrialtest.updateDelay) minetest.get_node_timer(network):start(industrialtest.updateDelay)
end end
end end
shouldRerunTimer=shouldRerunTimer or not industrialtest.api.isFullyCharged(meta)
end 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 end