PrismarineJS / mineflayer

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

auto_totem.js example transaction not confirming #1432

Open flowl opened 4 years ago

flowl commented 4 years ago

Versions

Detailed description of a problem

The example auto_totem.js is leading to rejected frame when the bot has a totem in the inventory.

  minecraft-protocol writing packet play.window_click +0ms
  minecraft-protocol {
  minecraft-protocol   windowId: 0,
  minecraft-protocol   slot: 11,
  minecraft-protocol   mouseButton: 0,
  minecraft-protocol   action: 1,
  minecraft-protocol   mode: 0,
  minecraft-protocol   item: { present: true, itemId: 904, itemCount: 1 }
  minecraft-protocol } +0ms
  # ... more head rotation and and action: 2 stuff
  minecraft-protocol read packet play.entity_head_rotation +0ms
  minecraft-protocol {
  minecraft-protocol   "entityId": 44749,
  minecraft-protocol   "headYaw": 28
  minecraft-protocol } +1ms
  minecraft-protocol read packet play.entity_head_rotation +0ms
  minecraft-protocol {
  minecraft-protocol   "entityId": 44721,
  minecraft-protocol   "headYaw": -78
  minecraft-protocol } +0ms
  minecraft-protocol read packet play.transaction +29ms
  minecraft-protocol {
  minecraft-protocol   "windowId": 0,
  minecraft-protocol   "action": 1,
  minecraft-protocol   "accepted": false
  minecraft-protocol } +0ms
  minecraft-protocol writing packet play.transaction +0ms
  minecraft-protocol { windowId: 0, action: 1, accepted: false } +0ms

Stacktrace

/node_modules/minecraft-protocol/src/transforms/framing.js:67
} else { throw e }
^

Error: Server rejected transaction.
    at Bot.<anonymous> (/node_modules/mineflayer/lib/plugins/inventory.js:570:12)
    at Object.onceWrapper (events.js:421:26)
    at Bot.emit (events.js:314:20)
    at onRejected (/node_modules/mineflayer/lib/plugins/inventory.js:526:11)
    at confirmTransaction (/node_modules/mineflayer/lib/plugins/inventory.js:509:7)
    at Client.<anonymous> (/node_modules/mineflayer/lib/plugins/inventory.js:613:5)
        at Client.emit (events.js:314:20)
        at FullPacketParser.<anonymous> (/node_modules/minecraft-protocol/src/client.js:89:12)
            at FullPacketParser.emit (events.js:314:20)
            at addChunk (/node_modules/readable-stream/lib/_stream_readable.js:298:12)
flowl commented 4 years ago

I found out the server doesn't like receiving "equip item" every 50ms, using 1000ms works but unstable, 5000ms seems ok. So I would confirm this is not a mineflayer bug, but it's unclear at first why the example is not working.

TheDudeFromCI commented 4 years ago

Might be a good idea to check if the item is already in the bot's hand before triggering a new equip event.

nothub commented 3 years ago

this is still happening in mineflayer 3.7.0

setInterval(() => {
    if (mcData.itemsByName.totem_of_undying && bot.inventory.slots[45] == null) {
        const totem = bot.inventory.findInventoryItem(mcData.itemsByName.totem_of_undying.id, null, null);
        if (totem) {
            equip(totem, 'off-hand')
        }
    }
}, 10000)
(node:44365) Error: Server rejected transaction for clicking on slot 41, on window [
  null,
  null,
  ...
  {
    "type": 449,
    "count": 1,
    "metadata": 0,
    "nbt": null,
    "name": "totem_of_undying",
    "displayName": "Totem of Undying",
    "stackSize": 1,
    "slot": 41
  },
  {
    "type": 449,
    "count": 1,
    "metadata": 0,
    "nbt": null,
    "name": "totem_of_undying",
    "displayName": "Totem of Undying",
    "stackSize": 1,
    "slot": 42
  },
  null,
  null,
  null
].
    at clickWindow (/home/hub/projects/annoyance-bot/node_modules/mineflayer/lib/plugins/inventory.js:416:13)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async moveSlotItem (/home/hub/projects/annoyance-bot/node_modules/mineflayer/lib/plugins/inventory.js:431:5)
    at async equip (/home/hub/projects/annoyance-bot/node_modules/mineflayer/lib/plugins/simple_inventory.js:108:7)
(node:44365) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    at emitDeprecationWarning (internal/process/promises.js:180:11)
    at processPromiseRejections (internal/process/promises.js:249:13)
    at processTicksAndRejections (internal/process/task_queues.js:96:32)