Fix inventory: window_id 'inventory' now maps to bot.inventory

Root cause: Bedrock sends inventory_content with window_id as string
("inventory", "armor", "offhand") but bot.inventory has numeric id 0.
The getWindow() lookup failed silently, so inventory was never populated.

Fix: check for string window_id values and map them to bot.inventory
directly, bypassing the numeric ID lookup.

This fixes:
- bot.inventory.items() returning empty
- Auto-equip not detecting items
- "item not in inventory" errors for equip commands
- Inventory check command returning empty

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
roberts 2026-03-30 21:12:15 -05:00
parent 1872d0b89a
commit a3e3d9f6ea

View file

@ -142,7 +142,14 @@ export default function inject(bot: BedrockBot) {
} }
}); });
bot._client.on('inventory_content', (packet: protocolTypes.packet_inventory_content) => { bot._client.on('inventory_content', (packet: protocolTypes.packet_inventory_content) => {
const window = bot.currentWindow?.id == packet.window_id ? bot.currentWindow : getWindow(packet.window_id); // On Bedrock, window_id for player inventory is the string "inventory"
// but bot.inventory has numeric id 0. Handle both.
let window;
if (packet.window_id === 'inventory' || packet.window_id === 'armor' || packet.window_id === 'offhand') {
window = bot.inventory;
} else {
window = bot.currentWindow?.id == packet.window_id ? bot.currentWindow : getWindow(packet.window_id);
}
if (!window) return; if (!window) return;
if (packet.window_id === 'inventory') { if (packet.window_id === 'inventory') {