Skip to content

Commit 447f779

Browse files
shinohara-rinnekomeowww
authored andcommitted
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
1 parent 843b149 commit 447f779

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

services/minecraft/src/skills/actions/collect-block.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,22 @@ export async function collectBlock(
7070
// Equip appropriate tool
7171
if (mineflayer.bot.game.gameMode !== 'creative') {
7272
await mineflayer.bot.tool.equipForBlock(block)
73-
const itemId = mineflayer.bot.heldItem ? mineflayer.bot.heldItem.type : null
73+
let itemId = mineflayer.bot.heldItem ? mineflayer.bot.heldItem.type : null
7474
if (!block.canHarvest(itemId)) {
7575
logger.log(`Don't have right tools to harvest ${block.name}.`)
7676
if (block.name.includes('ore') || block.name.includes('stone')) {
7777
await ensurePickaxe(mineflayer)
78+
// Re-equip after crafting/ensuring tool and re-check harvestability.
79+
await mineflayer.bot.tool.equipForBlock(block)
80+
itemId = mineflayer.bot.heldItem ? mineflayer.bot.heldItem.type : null
81+
}
82+
if (!block.canHarvest(itemId)) {
83+
throw new ActionError(
84+
'RESOURCE_MISSING',
85+
`Don't have right tools to harvest ${block.name}`,
86+
{ blockType: block.name },
87+
)
7888
}
79-
throw new Error('Don\'t have right tools to harvest block.')
8089
}
8190
}
8291

0 commit comments

Comments
 (0)