diff --git a/machines/rotary_macerator.lua b/machines/rotary_macerator.lua index d0f430d..3ac915c 100644 --- a/machines/rotary_macerator.lua +++ b/machines/rotary_macerator.lua @@ -150,10 +150,12 @@ rotaryMacerator.activeOnTimer=function(pos,elapsed,meta,inv) local dstSlot=inv:get_stack("dst",1) local powerAmount=meta:get_int("industrialtest.powerAmount") local rpm=meta:get_int("rpm") + local speed=industrialtest.api.getMachineSpeed(meta) + local requiredPower=elapsed*rotaryMacerator.opPower*speed industrialtest.internal.chargeFromPowerStorageItem(meta,inv) - if srcSlot:is_empty() or powerAmount=meta:get_float("maxSrcTime") then - local speed=industrialtest.api.getMachineSpeed(meta) - local multiplier=1 - if srcSlot:get_count()>=speed then - multiplier=speed - end + local multiplier=math.min(srcSlot:get_count(),speed) + local prevCount=resultStack:get_count() resultStack:set_count(resultStack:get_count()*multiplier) - inv:add_item("dst",resultStack) + local leftover=inv:add_item("dst",resultStack) meta:set_float("srcTime",0) meta:set_float("maxSrcTime",0) - srcSlot:set_count(srcSlot:get_count()-multiplier) + srcSlot:take_item(multiplier-leftover:get_count()/prevCount) inv:set_stack("src",1,srcSlot) meta:set_int("rpm",math.min(rpm+750*elapsed,7500)) if modified then @@ -225,6 +224,8 @@ rotaryMacerator.activeOnTimer=function(pos,elapsed,meta,inv) meta:set_float("srcTime",srcTime) end + industrialtest.api.addPower(meta,-requiredPower) + return true,true end