PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.92k stars 904 forks source link

Error: Can't find potato in slots [54 - 90], (item id: 1091) #3350

Closed uwuv3 closed 5 months ago

uwuv3 commented 5 months ago

Versions

Detailed description of a problem

I wanted to make a farming boot for the server and I wanted to put it in a crate for him to put things in, but when I was putting things in (potatoes) Error: Can't find potato in slots [54 - 90], (item id: 1091) error appeared

What did you try yet?

I Try copy farmer bot from "https://github.com/MakkusuOtaku/mc-farmer/tree/main"

Your current code


    async function depositLoop() {
        let chestBlock = bot.findBlock({
            matching: mcData.blocksByName["chest"].id,
            maxDistance: 4
        });
        if (!chestBlock) return;

        const movement = new Movements(bot)
        movement.allowParkour = false;
        movement.allowSprinting = true;

        await bot.pathfinder.setMovements(movement)
        await bot.pathfinder.goto(new goals.GoalNear(chestBlock.position.x, chestBlock.position.y, chestBlock.position.z, 3));
        let chest = await bot.openChest(chestBlock);
        for (let slot of bot.inventory.slots) {
            if (slot) {
                console.log(slot);
                await chest.deposit(slot.type, null, slot.count);
            }
        }
        chest.close();

    }

Expected behavior

    if (!sourceItem) throw new Error(`Can't find ${mcDataEntry.name} in slots [${sourceStart} - ${sourceEnd}], (item id: ${itemType})`)
                           ^

Error: Can't find potato in slots [54 - 90], (item id: 1091) at transferOne (C:\Users\shopu\OneDrive\Desktop\ometmcbot\node_modules\mineflayer\lib\plugins\inventory.js:277:32) at transfer (C:\Users\shopu\OneDrive\Desktop\ometmcbot\node_modules\mineflayer\lib\plugins\inventory.js:263:11) at window.deposit (C:\Users\shopu\OneDrive\Desktop\ometmcbot\node_modules\mineflayer\lib\plugins\inventory.js:360:13) at depositLoop (C:\Users\shopu\OneDrive\Desktop\ometmcbot\dist\index.js:108:29) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async loop (C:\Users\shopu\OneDrive\Desktop\ometmcbot\dist\index.js:67:13)

Node.js v21.7.1

I think this causes offhand slot

uwuv3 commented 5 months ago

Yep, this because of off-hand, i added this to loop,its solved

         if (bot.inventory.slots[bot.getEquipmentDestSlot("off-hand")]) {
                const oldItem = bot.inventory.slots[bot.getEquipmentDestSlot("off-hand")];
                if (!oldItem) return
                await bot.equip(oldItem, "hand");
            }