feat(coal-crafter)!: buffer chest under the turtle

This commit is contained in:
Guillaume ARM 2024-05-24 18:09:41 +02:00
parent 43d931994a
commit 201831b16c

View File

@ -8,6 +8,12 @@ local MIN_ESSENCE_NEEDED = 8
local COAL_ESSENCE_NAME = 'mysticalagriculture:coal_essence'
local COAL_NAME = 'minecraft:coal'
local STORAGE_BUFFER_SIDE = 'bottom'
local STORAGE_INVENTORY_SIDE = 'front'
local dropInStorageFn = turtle.drop
local suckFromBufferFn = turtle.suckDown
local function countCoalItems(inventory)
local total = 0
@ -79,42 +85,38 @@ local function craft()
end
local function dropSelected()
turtle.turnLeft()
turtle.turnLeft()
turtle.drop()
turtle.turnRight()
turtle.turnRight()
dropInStorageFn()
end
local function findBufferChestOrientation()
local function findStorageChestOrientation()
for i=1, 3, 1 do
local inv = turtleUtils.getInventory('front')
if inv and #inv.list() == 0 then
local inv = turtleUtils.getInventory(STORAGE_INVENTORY_SIDE)
if inv then
return
end
turtle.turnRight()
end
error('buffer inventory not found (empty chest expected)')
error('storage chest inventory not found')
end
local function main()
turtle.select(1)
findBufferChestOrientation()
findStorageChestOrientation()
print('> Waiting for the back inventory (storage)')
local storageInventory = turtleUtils.waitForInventory('back', WAIT_INVENTORY_TIME)
local storageInventory = turtleUtils.waitForInventory(STORAGE_INVENTORY_SIDE, WAIT_INVENTORY_TIME)
print('> Waiting for the front inventory (buffer chest)')
local bufferInventory = turtleUtils.waitForInventory('front', WAIT_INVENTORY_TIME)
local bufferInventory = turtleUtils.waitForInventory(STORAGE_BUFFER_SIDE, WAIT_INVENTORY_TIME)
print('> coal-crafter process started')
while true do
storageInventory = turtleUtils.waitForInventory('back', WAIT_INVENTORY_TIME)
bufferInventory = turtleUtils.waitForInventory('front', WAIT_INVENTORY_TIME)
storageInventory = turtleUtils.waitForInventory(STORAGE_INVENTORY_SIDE, WAIT_INVENTORY_TIME)
bufferInventory = turtleUtils.waitForInventory(STORAGE_BUFFER_SIDE, WAIT_INVENTORY_TIME)
waitForNotEnoughCoal(storageInventory)
local coalEssenceSlot = waitForCoalEssence(storageInventory)
@ -124,7 +126,7 @@ local function main()
error('cannot pushItems from storage to buffer')
end
local suckOk, suckErr = turtle.suck()
local suckOk, suckErr = suckFromBufferFn()
if not suckOk then
error('cannot suck into front buffer chest: ' .. tostring(suckErr))
@ -132,7 +134,7 @@ local function main()
prepareCraftShape()
craft()
dropSelected()
dropInStorageFn()
end
end