Skip to content

bot.toss and bot.tossStack instantly crash the bot #3590

Open
@JaWarrior12

Description

@JaWarrior12
  • The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 10.9.2
  • server: vanilla/spigot/paper vanilla 1.20.4
  • node: 22.14.0

Detailed description of a problem

A clear and concise description of what the problem is, with as much context as possible.
What are you building? What problem are you trying to solve?

I'm trying to build a kitbot for shulker/item delivery. When I go to have the bot toss the items out from its inventory, it crashes instantly.

Error:

    triggerUncaughtException(err, true /* fromPromise */);
    ^

AssertionError [ERR_ASSERTION]: Invalid itemType
    at transferOne (----\node_modules\mineflayer\lib\plugins\inventory.js:293:9)
    at EventEmitter.transfer (----\node_modules\mineflayer\lib\plugins\inventory.js:280:11)
    at EventEmitter.toss (----\node_modules\mineflayer\lib\plugins\simple_inventory.js:40:15)
    at EventEmitter.<anonymous> (--------\fetchKit.js:62:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '=='
}

What did you try yet?

Did you try any method from the API? Yes, I've tried both toss and tossStack, both fail with the same AssertionError
Did you try any example? Any error from those? I haven't found an example that uses toss or tossStack.

I've tried hard coding the item data through a direct minecraft-data itemsByName and to hasn't worked.

Your current code

const mcData = require('minecraft-data')(botInstance.version)
const chestBlock = bot.findBlock({
    matching: mcData.blocksByName.chest.id,
    maxDistance: 2
  })
//const chestBlock = botInstance.blockAt(chestPos, true);
const chest = await botInstance.openContainer(chestBlock);

const item = chestData.item;
await chest.withdraw(botInstance.registry.itemsByName[item].id, null, amount);
chest.close();

botInstance.chat(`/w ${player} Took ${amount} ${item} from "${chestName}" chest.`);
botInstance.chat(`/tpa ${player}`);
botInstance.pathfinder.setGoal(null);
console.log(mcData.blocksByName["lime_shulker_box"])
console.log(mcData.blocksByName["lime_shulker_box"].id)
console.log(mcData.blocksByName[chestData.item])
console.log(mcData.blocksByName[chestData.item].id)
const itemInfo = mcData.itemsByName[chestData.item]
botInstance.toss(itemInfo,null,amount)//, null, amount);
resolve(true);
} catch (error) {
console.log("Error taking item from chest:");
reject(error);
}

Expected behavior

The bot is expected to toss the shulker box from its inventory, instead it crashes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stage1just created by someone new to the project, we don't know yet if it deserves an implementation / a fpossible bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions