fix(coal-creafter): be sure to select slot 1 + fix dropAll

This commit is contained in:
Guillaume ARM 2024-05-24 18:41:33 +02:00
parent 6a50fef10a
commit a1364a4bff
2 changed files with 25 additions and 4 deletions

View File

@ -7,6 +7,7 @@ local IDLE_TIME_ENOUGH_COAL = 120
local MIN_ESSENCE_NEEDED = 8
local COAL_ESSENCE_NAME = 'mysticalagriculture:coal_essence'
local COAL_NAME = 'minecraft:coal'
local CRAFTING_SLOT = 1
local STORAGE_BUFFER_SIDE = 'bottom'
local STORAGE_INVENTORY_SIDE = 'front'
@ -15,17 +16,29 @@ local dropInStorageFn = turtle.drop
local suckFromBufferFn = turtle.suckDown
local function dropAll(side, dropFn)
local previousSelectedSlot = turtle.getSelectedSlot()
for i=1, 16, 1 do
local count = turtle.getItemCount(i)
if count > 0 then
turtleUtils.waitForInventory(side, IDLE_TIME)
if not turtleUtils.dropSlot(i, dropFn) then
error('please empty the turtle inventory', 0)
local errorPrinted = false
while not turtleUtils.dropSlot(i, dropFn) do
if not errorPrinted then
print('> please empty the turtle inventory')
errorPrinted = true
end
os.sleep(WAIT_INVENTORY_TIME)
end
end
end
if previousSelectedSlot ~= turtle.getSelectedSlot() then
turtle.select(previousSelectedSlot)
end
end
local function countCoalItems(inventory)
@ -116,8 +129,6 @@ local function findStorageChestOrientation()
end
local function main()
turtle.select(1)
findStorageChestOrientation()
print('> Waiting for the back inventory (storage)')
@ -129,6 +140,7 @@ local function main()
print('> drop all')
dropAll(STORAGE_INVENTORY_SIDE, dropInStorageFn)
turtle.select(CRAFTING_SLOT)
print('> coal-crafter process started')
while true do
@ -149,6 +161,7 @@ local function main()
error('cannot suck into front buffer chest: ' .. tostring(suckErr))
end
turtleUtils.ensureSelected(CRAFTING_SLOT)
prepareCraftShape()
craft()
dropInStorageFn()

View File

@ -213,6 +213,14 @@ turtleUtils.selectItemBy = function(predicate)
return false
end
turtleUtils.ensureSelected = function(slot)
if turtle.getSelectedSlot() ~= slot then
return turtle.select(slot)
end
return true
end
turtleUtils.refuel = function(minFuel, suckFn, sleepTime)
suckFn = suckFn or turtle.suck
sleepTime = sleepTime or DEFAULT_IDLE_TIME