From c4e1416f5f6023e143ee0bbbb32a329851dca56f Mon Sep 17 00:00:00 2001 From: roberts Date: Mon, 30 Mar 2026 17:42:56 -0500 Subject: [PATCH] Fix item name matching: handle minecraft: prefix in inventory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - equip_item now tries: exact → stripped prefix → fuzzy substring match - If item not found, error message lists actual inventory contents - get_inventory strips minecraft: prefix from item names - Fixes "diamond_sword not in inventory" when item exists as "minecraft:diamond_sword" Co-Authored-By: Claude Opus 4.6 (1M context) --- bridge/src/index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/bridge/src/index.js b/bridge/src/index.js index 75b0267..547c88f 100644 --- a/bridge/src/index.js +++ b/bridge/src/index.js @@ -663,10 +663,18 @@ async function handleAction(action, params = {}) { case 'equip_item': { const { name, destination } = params; - const item = bot.inventory.items().find(i => i.name === name); - if (!item) throw new Error(`Item ${name} not in inventory`); + const searchName = name.replace('minecraft:', '').toLowerCase(); + // Try exact match, then without prefix, then fuzzy + let item = bot.inventory.items().find(i => i.name === name); + if (!item) item = bot.inventory.items().find(i => i.name.replace('minecraft:', '').toLowerCase() === searchName); + if (!item) item = bot.inventory.items().find(i => i.name.replace('minecraft:', '').toLowerCase().includes(searchName)); + if (!item) { + // List what we actually have for debugging + const have = bot.inventory.items().map(i => i.name).join(', '); + throw new Error(`Item ${name} not in inventory. I have: ${have || 'nothing'}`); + } await bot.equip(item, destination || 'hand'); - return { equipped: name }; + return { equipped: item.name }; } case 'stop': { @@ -700,10 +708,10 @@ async function handleAction(action, params = {}) { case 'get_inventory': { const items = bot.inventory.items().map(item => ({ - name: item.name, + name: item.name.replace('minecraft:', ''), count: item.count, slot: item.slot, - displayName: item.displayName, + displayName: item.displayName || item.name.replace('minecraft:', ''), })); return { items }; }