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