diff --git a/coal-crafter.lua b/coal-crafter.lua index 3243fa6..c80cb98 100644 --- a/coal-crafter.lua +++ b/coal-crafter.lua @@ -1,9 +1,26 @@ local turtleUtils = require('libs/turtle-utils') +local NB_NEEDED_COAL = 256 local WAIT_INVENTORY_TIME = 3 -local IDLE_TIME = 10 +local IDLE_TIME = 30 +local IDLE_TIME_ENOUGH_COAL = 120 local MIN_ESSENCE_NEEDED = 8 local COAL_ESSENCE_NAME = 'mysticalagriculture:coal_essence' +local COAL_NAME = 'minecraft:coal' + +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 + + if not enoughCoal then + return + end + end + + os.sleep(IDLE_TIME_ENOUGH_COAL) + end +end -- the slot of the coal essence is returned local function waitForCoalEssence(inventory) @@ -89,6 +106,7 @@ local function main() storageInventory = turtleUtils.waitForInventory('back', WAIT_INVENTORY_TIME) bufferInventory = turtleUtils.waitForInventory('front', WAIT_INVENTORY_TIME) + waitForNotEnoughCoal(storageInventory) local coalEssenceSlot = waitForCoalEssence(storageInventory) local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), coalEssenceSlot, MIN_ESSENCE_NEEDED)