feat(tunnels-miner): drop items from inventory when full

This commit is contained in:
Guillaume ARM 2024-05-26 14:00:33 +02:00
parent 15764993e0
commit 7a8636f054
2 changed files with 32 additions and 4 deletions

View File

@ -9,5 +9,8 @@ return {
['mysticalagriculture:deepslate_prosperity_ore'] = true,
['mysticalagradditions:nether_prosperity_ore'] = true,
['mysticalagradditions:end_prosperity_ore'] = true
},
VEIN_ORE_WHITELIST_ITEMS = {
['mysticalagriculture:prosperity_shard'] = true
}
}

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.0.1"
local VERSION = "2.1.0"
local MOVES_BY_DIRECTION = {
right = {
@ -97,10 +97,14 @@ local function digForward(n, cb)
end
end
local function isWhitelistedOre(config, block)
local blockName = block and block.name
local function isWhitelistedOre(config, itemOrBlock)
local itemOrBlockName = itemOrBlock and itemOrBlock.name
if config.VEIN_ORES_WHITELIST[blockName] then
if config.VEIN_ORES_WHITELIST[itemOrBlockName] then
return true
end
if config.VEIN_ORES_WHITELIST_ITEMS[itemOrBlockName] then
return true
end
@ -112,7 +116,28 @@ local function inspectWhitelistedOre(config, inspectFn)
return isWhitelistedOre(config, block)
end
local function ensureEnoughSpaceInInventory(config)
if not turtleUtils.isInventoryFull() then
return
end
-- 1. select an item that is not in whitelist item
local selected = turtleUtils.selectItemBy(function(slot)
return not isWhitelistedOre(config, turtle.getItemDetail(slot))
end)
if selected then
-- 2. drop the selected item
turtle.drop()
else
-- TODO: handle when cannot drop anything
end
end
local function mineVeinOres(config)
ensureEnoughSpaceInInventory(config)
-- 1. front
if inspectWhitelistedOre(config, turtle.inspect) then
turtleUtils.forceForward()