PrismarineJS / mineflayer

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

Cannot Take Item out of Chest (Hangs on window.Withdraw) #3383

Closed Banana1059 closed 1 month ago

Banana1059 commented 1 month ago

Versions

Detailed description of a problem

I'm trying to get it where my bot opens a chest and takes the first shulker box it finds. I'm able to get it to the chest and open it just fine, but cannot get it to take items from the chest as it just hangs at the chest.withdraw() line

What did you try yet?

I've tried window.withdraw and bot.moveSlotItem

Your current code

const chestBlock = bot.blockAt(new Vec3(x + offset, y, z));
        await bot.openContainer(chestBlock).then(async chest => {
            console.log(chest.slots)
            console.log(chest.slots.length)
            for (i = 0; i < chest.slots.length; i++) {
                if (!(chest.slots[i] === null)) {
                    if (chest.slots[i].name.includes('shulker_box')) {
                        shulker = chest.slots[i]
                    }
                }
            }
            if (!shulker) {
                kit_OutOfStock.push(kit);
                sendMessage(`/msg ${username} Kit Out Of Stock`);
                await chest.close();
                return;
            }
            console.log(shulker)
            await chest.withdraw(shulker.type, null, 1) //HANGS HERE
            await chest.close();
        });

Expected behavior

I except it to take a shulker out of the chest and then close the chest

Additional context

Each chest I test it on is full of exactly the same shulkers