fix(tunnels-miner): try to select a non-empty slot when possible + use ensureWnoughSpaceInInventory everywhere

This commit is contained in:
Guillaume ARM 2024-05-26 14:06:17 +02:00
parent 7a8636f054
commit 0b2e412ad9

View File

@ -6,7 +6,7 @@ local TIME_TO_START = 3
local IDLE_TIME_BETWEEN_TUNNELS = 1
local SPACE_BETWEEN_TUNNELS = 3
local VERSION = "2.1.0"
local VERSION = "2.1.1"
local MOVES_BY_DIRECTION = {
right = {
@ -116,6 +116,14 @@ local function inspectWhitelistedOre(config, inspectFn)
return isWhitelistedOre(config, block)
end
local function trySelectEmptySlot()
if turtle.getItemDetail() then
turtleUtils.selectItemBy(function(slot)
return not not turtle.getItemDetail(slot)
end)
end
end
local function ensureEnoughSpaceInInventory(config)
if not turtleUtils.isInventoryFull() then
return
@ -129,10 +137,10 @@ local function ensureEnoughSpaceInInventory(config)
if selected then
-- 2. drop the selected item
turtle.drop()
trySelectEmptySlot()
else
-- TODO: handle when cannot drop anything
-- TODO: handle when cannot drop anything (monitoring over network ?)
end
end
local function mineVeinOres(config)
@ -193,7 +201,10 @@ end
local function mineTunnelProcedure(config)
local distance = config.DISTANCE_Z
local onMineCb = function() mineVeinProcedure(config) end
local onMineCb = function()
ensureEnoughSpaceInInventory()
mineVeinProcedure(config)
end
digForward(distance, onMineCb)
getMoves(config).turnRight()