From 447f779393be3caba249d179c49dfbdec91cb8e4 Mon Sep 17 00:00:00 2001 From: Rin Date: Sat, 7 Feb 2026 05:11:20 +0800 Subject: [PATCH] fix(minecraft): re-equip tool after ensurePickaxe and throw typed error for missing harvest tools Re-equip block-appropriate tool after ensurePickaxe crafting/ensuring workflow to capture newly crafted pickaxe, add second canHarvest check post-equip to verify harvestability with new tool, replace generic Error with ActionError(RESOURCE_MISSING) for missing tool failures to enable proper error handling --- .../minecraft/src/skills/actions/collect-block.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/services/minecraft/src/skills/actions/collect-block.ts b/services/minecraft/src/skills/actions/collect-block.ts index 72e65481f..1d5c0bc08 100644 --- a/services/minecraft/src/skills/actions/collect-block.ts +++ b/services/minecraft/src/skills/actions/collect-block.ts @@ -70,13 +70,22 @@ export async function collectBlock( // Equip appropriate tool if (mineflayer.bot.game.gameMode !== 'creative') { await mineflayer.bot.tool.equipForBlock(block) - const itemId = mineflayer.bot.heldItem ? mineflayer.bot.heldItem.type : null + let itemId = mineflayer.bot.heldItem ? mineflayer.bot.heldItem.type : null if (!block.canHarvest(itemId)) { logger.log(`Don't have right tools to harvest ${block.name}.`) if (block.name.includes('ore') || block.name.includes('stone')) { await ensurePickaxe(mineflayer) + // Re-equip after crafting/ensuring tool and re-check harvestability. + await mineflayer.bot.tool.equipForBlock(block) + itemId = mineflayer.bot.heldItem ? mineflayer.bot.heldItem.type : null + } + if (!block.canHarvest(itemId)) { + throw new ActionError( + 'RESOURCE_MISSING', + `Don't have right tools to harvest ${block.name}`, + { blockType: block.name }, + ) } - throw new Error('Don\'t have right tools to harvest block.') } }