From 115ffd2e78cdb95173a4e55200e9535badc0af0e Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Mon, 20 May 2024 01:25:04 +0200 Subject: [PATCH] feat: add coal-crafter --- coal-crafter.lua | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ install.lua | 1 + 2 files changed, 79 insertions(+) create mode 100644 coal-crafter.lua diff --git a/coal-crafter.lua b/coal-crafter.lua new file mode 100644 index 0000000..a58dc92 --- /dev/null +++ b/coal-crafter.lua @@ -0,0 +1,78 @@ +local turtleUtils = require('turtle-utils') + +local WAIT_INVENTORY_TIME = 3 +local IDLE_TIME = 10 +local MIN_ESSENCE_NEEDED = 8 +local COAL_ESSENCE_NAME = 'mysticalagriculture:essence_coal' + +-- the slot of the coal essence is returned +local function waitForCoalEssence(inventory) + + while true do + for slot, item in pairs(inventory.list()) do + if item.name == COAL_ESSENCE_NAME and item.count >= MIN_ESSENCE_NEEDED then + return slot + end + end + + os.sleep(IDLE_TIME) + end +end + +local function prepareCraftShape() + turtle.transferTo(2, 1) + turtle.transferTo(3, 1) + + turtle.transferTo(5, 1) + turtle.transferTo(7, 1) + + turtle.transferTo(9, 1) + turtle.transferTo(10, 1) + turtle.transferTo(11, 1) +end + +local function craft() + local craftOk = turtle.craft() + + if not craftOk then + error('cannot craft') + end + + return craftOk +end + +local functin dropSelected() + turtle.turnLeft() + turtle.drop() + turtle.turnRight() +end + +local function main() + turtle.select(1) + + print('> Waiting for left inventory (storage)') + local storageInventory = turtleUtils.waitForInventory('left', WAIT_INVENTORY_TIME) + + print('> Waiting for the front inventory (buffer chest)') + local bufferInventory = turtleUtils.waitForInventory('front', WAIT_INVENTORY_TIME) + + print('> coal-crafter process started') + + while true do + storageInventory = turtleUtils.waitForInventory('left', WAIT_INVENTORY_TIME) + bufferInventory = turtleUtils.waitForInventory('front', WAIT_INVENTORY_TIME) + + local coalEssenceSlot = waitForCoalEssence(storageInventory) + local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), coalEssenceSlot) + + if not pushOk then + error('cannot pushItems from storage to buffer') + end + + prepareCraftShape() + craft() + dropSelected() + end +end + +main() diff --git a/install.lua b/install.lua index 5842df4..eac3b21 100644 --- a/install.lua +++ b/install.lua @@ -1,6 +1,7 @@ local LIST_FILES = { 'old/simple-harvester.lua', 'miner.lua', + 'coal-crafter.lua', 'inferium-upgrader.lua', 'inferium-harvester.lua' };