PrismarineJS / mineflayer

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

buffer.js crashes bot #2175

Closed crispy-cookie closed 3 years ago

crispy-cookie commented 3 years ago

Versions

Detailed description of a problem

I'm trying to join a bot on a server, but the bot gets disconnected and throws error an in buffer.js.

What did you try yet?

I started a new world. Light updates don't seem to throw an error.

Moving around (and generating new chunks) threw this error. But I also tried a different server which already had chunks generated and the error still showed up. I can't reproduce the bug.

Your current code


const mineflayer = require('mineflayer');

const bot = mineflayer.createBot({
  host: process.env.MCHOST,
  port: process.env.MCPORT,
  username: 'cctitan',
  viewDistance: 'tiny',
  logErrors: true,
});

bot.once('spawn', () => {
  console.log(`${bot.username} has spawned`);
});
bot.on('error', (err) => {
  console.log(`Bot has encountered an error: ${err}`);
});
bot.on('kicked', (kickreason) => {
  console.log(`disconnected: ${kickreason}`)
});

Expected behavior

Hopefully no more disconnects.

Additional context

Error log

  minecraft-protocol read packet play.update_light +2ms
  minecraft-protocol {
  minecraft-protocol   chunkX: -20,
  minecraft-protocol   chunkZ: 11,
  minecraft-protocol   trustEdges: true,
  minecraft-protocol   skyLightMask: [],
  minecraft-protocol   blockLightMask: [ BigIntExtended(2) [ 0, 2 ] ],
  minecraft-protocol   emptySkyLightMask: [],
  minecraft-protocol   emptyBlockLightMask: [],
  minecraft-protocol   skyLight: [],
  minecraft-protocol   blockLight: [
  minecraft-protocol     [
  minecraft-protocol       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  minecraft-protocol       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  minecraft-protocol       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  minecraft-protocol       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  minecraft-protocol       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  minecraft-protocol       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  minecraft-protocol       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  minecraft-protocol       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  minecraft-protocol       0, 0, 0, 0,
  minecraft-protocol       ... 1948 more items
  minecraft-protocol     ]
  minecraft-protocol   ]
  minecraft-protocol } +0ms
buffer.js:330
  throw new ERR_INVALID_ARG_TYPE(
  ^

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
    at Function.from (buffer.js:330:9)
    at ChunkColumn.loadParsedLight (/home/cctitan/mineflayer/node_modules/prismarine-chunk/src/pc/1.17/ChunkColumn.js:338:38)
    at Client.<anonymous> (/home/cctitan/mineflayer/node_modules/mineflayer/lib/plugins/blocks.js:311:14)
    at Client.emit (events.js:400:28)
    at FullPacketParser.<anonymous> (/home/cctitan/mineflayer/node_modules/minecraft-protocol/src/client.js:91:12)
    at FullPacketParser.emit (events.js:400:28)
    at addChunk (/home/cctitan/mineflayer/node_modules/readable-stream/lib/_stream_readable.js:298:12)
    at readableAddChunk (/home/cctitan/mineflayer/node_modules/readable-stream/lib/_stream_readable.js:280:11)
    at FullPacketParser.Readable.push (/home/cctitan/mineflayer/node_modules/readable-stream/lib/_stream_readable.js:241:10)
    at FullPacketParser.Transform.push (/home/cctitan/mineflayer/node_modules/readable-stream/lib/_stream_transform.js:139:32) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Here is the full protocol debugging output: https://gist.github.com/CC044/af373aad0e7720b2403d90e3871256a8

crispy-cookie commented 3 years ago

Probably same as #2159