forked from mrkubax10/industrialtest
Deduplicate machine charging from power storage item code
This commit is contained in:
parent
664b11fe33
commit
3041d0982f
@ -85,15 +85,7 @@ canningMachine.onTimer=function(pos,elapsed,meta,inv)
|
|||||||
local powerStorageSlot=inv:get_stack("powerStorage",1)
|
local powerStorageSlot=inv:get_stack("powerStorage",1)
|
||||||
local targetMeta=targetSlot:get_meta()
|
local targetMeta=targetSlot:get_meta()
|
||||||
|
|
||||||
if not powerStorageSlot:is_empty() then
|
shouldRerunTimer,shouldUpdateFormspec=industrialtest.internal.chargeFromPowerStorageItem(meta,inv)
|
||||||
local stackMeta=powerStorageSlot:get_meta()
|
|
||||||
if industrialtest.api.transferPower(stackMeta,meta,stackMeta:get_int("industrialtest.powerFlow"))>0 then
|
|
||||||
shouldUpdateFormspec=true
|
|
||||||
shouldRerunTimer=true
|
|
||||||
industrialtest.api.updateItemPowerText(powerStorageSlot)
|
|
||||||
inv:set_stack("powerStorage",1,powerStorageSlot)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local def=fuelSlot:get_definition()
|
local def=fuelSlot:get_definition()
|
||||||
if not fuelSlot:is_empty() and not targetSlot:is_empty() and meta:get_int("industrialtest.powerAmount")>=canningMachine.opPower and (not def._industrialtest_emptyVariant or leftoverSlot:item_fits(ItemStack(def._industrialtest_emptyVariant))) and
|
if not fuelSlot:is_empty() and not targetSlot:is_empty() and meta:get_int("industrialtest.powerAmount")>=canningMachine.opPower and (not def._industrialtest_emptyVariant or leftoverSlot:item_fits(ItemStack(def._industrialtest_emptyVariant))) and
|
||||||
@ -170,14 +162,7 @@ canningMachine.activeOnTimer=function(pos,elapsed,meta,inv)
|
|||||||
local targetSlot=inv:get_stack("target",1)
|
local targetSlot=inv:get_stack("target",1)
|
||||||
local powerStorageSlot=inv:get_stack("powerStorage",1)
|
local powerStorageSlot=inv:get_stack("powerStorage",1)
|
||||||
|
|
||||||
if not powerStorageSlot:is_empty() then
|
shouldRerunTimer,shouldUpdateFormspec=industrialtest.internal.chargeFromPowerStorageItem(meta,inv)
|
||||||
local stackMeta=powerStorageSlot:get_meta()
|
|
||||||
if industrialtest.api.transferPower(stackMeta,meta,stackMeta:get_int("industrialtest.powerFlow"))>0 then
|
|
||||||
shouldUpdateFormspec=true
|
|
||||||
industrialtest.api.updateItemPowerText(powerStorageSlot)
|
|
||||||
inv:set_stack("powerStorage",1,powerStorageSlot)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if fuelSlot:is_empty() or targetSlot:is_empty() or meta:get_int("industrialtest.powerAmount")<canningMachine.opPower then
|
if fuelSlot:is_empty() or targetSlot:is_empty() or meta:get_int("industrialtest.powerAmount")<canningMachine.opPower then
|
||||||
if meta:get_int("industrialtest.powerAmount")>=canningMachine.opPower then
|
if meta:get_int("industrialtest.powerAmount")>=canningMachine.opPower then
|
||||||
|
@ -49,6 +49,22 @@ industrialtest.internal.allowMoveToUpgradeSlot=function(pos,toIndex,stack)
|
|||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
industrialtest.internal.chargeFromPowerStorageItem=function(meta,inv)
|
||||||
|
local shouldRerunTimer=false
|
||||||
|
local shouldUpdateFormspec=false
|
||||||
|
local powerStorageSlot=inv:get_stack("powerStorage",1)
|
||||||
|
if not powerStorageSlot:is_empty() then
|
||||||
|
local stackMeta=powerStorageSlot:get_meta()
|
||||||
|
if industrialtest.api.transferPower(stackMeta,meta,stackMeta:get_int("industrialtest.powerFlow"))>0 then
|
||||||
|
shouldUpdateFormspec=true
|
||||||
|
shouldRerunTimer=stackMeta:get_int("industrialtest.powerAmount")>0 and not industrialtest.api.isFullyCharged(meta)
|
||||||
|
industrialtest.api.updateItemPowerText(powerStorageSlot)
|
||||||
|
inv:set_stack("powerStorage",1,powerStorageSlot)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return shouldRerunTimer,shouldUpdateFormspec
|
||||||
|
end
|
||||||
|
|
||||||
machine.getFormspec=function(pos,config)
|
machine.getFormspec=function(pos,config)
|
||||||
local formspec
|
local formspec
|
||||||
if industrialtest.mtgAvailable then
|
if industrialtest.mtgAvailable then
|
||||||
@ -561,15 +577,9 @@ simpleElectricItemProcessor.onTimer=function(pos,elapsed,meta,inv,config)
|
|||||||
local shouldUpdateFormspec=false
|
local shouldUpdateFormspec=false
|
||||||
local shouldRerunTimer=false
|
local shouldRerunTimer=false
|
||||||
local requiredPower=elapsed*config.opPower*industrialtest.api.getMachineSpeed(meta)
|
local requiredPower=elapsed*config.opPower*industrialtest.api.getMachineSpeed(meta)
|
||||||
if powerStorageSlot:get_count()>0 then
|
|
||||||
local stackMeta=powerStorageSlot:get_meta()
|
shouldRerunTimer,shouldUpdateFormspec=industrialtest.internal.chargeFromPowerStorageItem(meta,inv)
|
||||||
if industrialtest.api.transferPower(stackMeta,meta,stackMeta:get_int("industrialtest.powerFlow"))>0 then
|
|
||||||
shouldUpdateFormspec=true
|
|
||||||
shouldRerunTimer=true
|
|
||||||
industrialtest.api.updateItemPowerText(powerStorageSlot)
|
|
||||||
inv:set_stack("powerStorage",1,powerStorageSlot)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if srcSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>=requiredPower then
|
if srcSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>=requiredPower then
|
||||||
local output=craftResultProxy(config.method,srcSlot)
|
local output=craftResultProxy(config.method,srcSlot)
|
||||||
if output.time>0 and inv:room_for_item("dst",output.item) then
|
if output.time>0 and inv:room_for_item("dst",output.item) then
|
||||||
@ -658,15 +668,8 @@ simpleElectricItemProcessor.activeOnTimer=function(pos,elapsed,meta,inv,config)
|
|||||||
local shouldRerunTimer=false
|
local shouldRerunTimer=false
|
||||||
local requiredPower=elapsed*config.opPower*industrialtest.api.getMachineSpeed(meta)
|
local requiredPower=elapsed*config.opPower*industrialtest.api.getMachineSpeed(meta)
|
||||||
|
|
||||||
if powerStorageSlot:get_count()>0 then
|
shouldRerunTimer,shouldUpdateFormspec=industrialtest.internal.chargeFromPowerStorageItem(meta,inv)
|
||||||
local stackMeta=powerStorageSlot:get_meta()
|
|
||||||
if industrialtest.api.transferPower(stackMeta,meta,stackMeta:get_int("industrialtest.powerFlow"))>0 then
|
|
||||||
shouldUpdateFormspec=true
|
|
||||||
shouldRerunTimer=true
|
|
||||||
industrialtest.api.updateItemPowerText(powerStorageSlot)
|
|
||||||
inv:set_stack("powerStorage",1,powerStorageSlot)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if srcSlot:get_count()>0 and meta:get_float("maxSrcTime")<=0 and meta:get_int("industrialtest.powerAmount")>=requiredPower then
|
if srcSlot:get_count()>0 and meta:get_float("maxSrcTime")<=0 and meta:get_int("industrialtest.powerAmount")>=requiredPower then
|
||||||
local output=craftResultProxy(config.method,srcSlot)
|
local output=craftResultProxy(config.method,srcSlot)
|
||||||
if output.time>0 and inv:room_for_item("dst",output.item) then
|
if output.time>0 and inv:room_for_item("dst",output.item) then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user