Fix item name matching: handle minecraft: prefix in inventory
- 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) <noreply@anthropic.com>
This commit is contained in:
parent
c2b996947a
commit
c4e1416f5f
1 changed files with 13 additions and 5 deletions
|
|
@ -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 };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue