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