diff --git a/coal-crafter.lua b/coal-crafter.lua index c80cb98..19bd284 100644 --- a/coal-crafter.lua +++ b/coal-crafter.lua @@ -8,14 +8,24 @@ local MIN_ESSENCE_NEEDED = 8 local COAL_ESSENCE_NAME = 'mysticalagriculture:coal_essence' local COAL_NAME = 'minecraft:coal' +local function countCoalItems(inventory) + local total = 0 + + for slot, item in pairs(inventory.list()) do + if item.name == COAL_NAME then + total = total + item.count + end + end + + return total +end + local function waitForNotEnoughCoal(inventory) while true do - for slot, item in pairs(inventory.list()) do - local enoughCoal = item.name == COAL_NAME and item.count >= NB_NEEDED_COAL + local nbCoals = countCoalItems(inventory) - if not enoughCoal then - return - end + if nbCoals < NB_NEEDED_COAL then + return end os.sleep(IDLE_TIME_ENOUGH_COAL)