From 0b2e412ad9c161a81ca3f0d4642d5ae79298a988 Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Sun, 26 May 2024 14:06:17 +0200 Subject: [PATCH] fix(tunnels-miner): try to select a non-empty slot when possible + use ensureWnoughSpaceInInventory everywhere --- tunnels-miner.lua | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tunnels-miner.lua b/tunnels-miner.lua index b72aaf1..d22c62b 100644 --- a/tunnels-miner.lua +++ b/tunnels-miner.lua @@ -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()