PrismarineJS / mineflayer

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

Chunksize is 73 but only 47 was read #2961

Open Lawerencium opened 1 year ago

Lawerencium commented 1 year ago

Versions

Detailed description of a problem

The bot bugs out with an errormessage, after which it kicks the bot from the server.

Chunk size is 73 but only 47 was read ; partial packet : {"name":"world_particles","params":{"particleId":40,"longDistance":false,"x":-546.5,"y":61.5,"z":915.5,"offsetX":0,"offsetY":0,"offsetZ":0,"particleData":0,"particles":1}}; buffer :222800c081140000000000404ec00000000000408c9c00000000000000000000000000000000000000000000000001106d696e6563726166743a656e746974799aed851c3eb851ec03

What did you try yet?

I tried what other bugreports told me to, by setting the version-number, which i did... it didnt change anything

Your current code

const mineflayer = require('mineflayer');
const Discord = require('discord.js');
const { EmbedBuilder } = require('discord.js');
const Vec3 = require('vec3')
const delay = require('util').promisify(setTimeout)
const {pathfinder,Movements} = require('mineflayer-pathfinder')
const {GoalNear,GoalBlock,GoalFollow,GoalBreakBlock} = require('mineflayer-pathfinder').goals

let bot
let botStatus = false

// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits, Intents ,IntentsBitField, Partials} = require('discord.js');

// Create a new client instance
const client = new Client({
  intents: [IntentsBitField.Flags.GuildMembers, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.DirectMessages, IntentsBitField.Flags.Guilds, IntentsBitField.Flags.MessageContent],
  partials: [Partials.Message, Partials.Channel, Partials.GuildMember, Partials.User]
})

// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, c => {
    console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.login('DISCORDTOKEN');

const bindEvents = () => {
// Log in to Discord with your client's token

  console.log("restarting now...")
  bot = mineflayer.createBot({
    host: 'IP',
    // port: 25565,
    username: 'EMAIL',
    password: 'PWD',
    auth: 'microsoft',
    version:"1.19.3"
  })

  //------------------------------------------- FISHING ------------------------------------------//

  async function startFishing() {
    var errorNotify = false

    try {
      await bot.equip(bot.registry.itemsByName.fishing_rod.id, 'hand')
    } catch (err) {
      errorNotify = true
      return bot.chat("/msg scout247 " + err.message)
    }

  nowFishing = true

  try {
    await bot.fish()
  } catch (err) {
    errorNotify = true
    bot.chat("/msg scout247 " + err.message)
  }

  nowFishing = false
  if (errorNotify === false) {
    setTimeout(startFishing, 2000)
  }

  }

  bot.on('spawn', function() {
    bot.loadPlugin(require('mineflayer-autoclicker'))
    bot.autoclicker.start();
    startFishing()
  });

  bot.on('death', function() {
    bot.autoclicker.stop()
  })

  bot.on('end', () => {
    botStatus = false
    console.log('connection ended, reconnecting in 30 seconds')
    if (botStatus == false) {
      setTimeout(bindEvents, 30000)
    }
  })

  bot.on('login', () => {
    botStatus = true
    console.log('DutchBot is Online')
  })

  bot.on('messagestr', (message) => {

      function checkTime(i) {
          return (i < 10) ? "0" + i : i;
      }

      function GetTime(){
          var todayF = new Date();
          h = checkTime(todayF.getHours());
          m = checkTime(todayF.getMinutes());
          s = checkTime(todayF.getSeconds());
          var result = h + ':' + m + ':' + s
          return result;
      }

      let rawMessage = message
          .replace(/\[.*\]/g, '')
          .trim()
          .replace(/:/, '')

      if (rawMessage.includes('whispers to you')) {return}

      var outputMessage = "PLACEHOLDER"
      var flag = "CHAT"

      if (rawMessage.includes("left the game")) {flag = "LEFT"}
      if (rawMessage.includes("joined the game")) {flag = "JOIN"}
      if (rawMessage.includes("players sleeping")) {return}
      var username = rawMessage.split(' ')[0]
      if (username === "DutchBot" || username === "Sleeping") {return}
      const chatMessage = rawMessage.split(' ').slice(1).join(" ")
      if (username === "scout247" && chatMessage === "!db start fishing") {
        startFishing()
      }

      username = username.padStart(16)

      if (flag === "CHAT") {
        outputMessage = '`' + GetTime() + ' - ' + username +  `:` + ' [' + flag + ']` ' + chatMessage
      }

      if (flag === "LEFT" || flag === "JOIN") {
        outputMessage = '`' + GetTime() + ' - ' + username +  `:` + ' [' + flag + ']` '
      }

      client.channels.cache.get("1078402036258836490").send(outputMessage);
  })

  bot.on('message', (message) => {
    console.log(message.toAnsi())
  })
}

client.on('messageCreate', (message) => {
  if (message.channel.id !== '1078402036258836490') {return}
  if (message.author.bot) return
  var parsedUsername = message.author.username
  //if (message.member.nickname != undefined) {var parsedUsername = '~' + message.member.nickname;}
  var sendMessage = message.content

  if (message.content == 'tab' || message.content == 'Tab') {

    const players = Object.keys(bot.players).sort()
    var playerList = players.join('\n')
    playerList = '```' + "\n" + playerList + '```'
    const embedTab = new EmbedBuilder()
     .setColor(0x0099FF)
     .setTitle(`Players online ` + "(" + Object.keys(bot.players).length + ") :")
     .setDescription(playerList)
     .setTimestamp()
     .setFooter({ text: 'IP' });
    return client.channels.cache.get(message.channel.id).send({ embeds: [embedTab] });
  }

  bot.chat("**" + parsedUsername + "** ➠ " + sendMessage.substring(0, 230))
})

return bindEvents()

Expected behavior

Not give the error, and just work (fishing)

Additional context

There is a bit of discord-related stuff in the code aswell, thats a discord chatbot

Lawerencium commented 1 year ago

I found out it is because of the particle that a noteblock sends to an allay. I broke the noteblock and the issue stopped. Seems like a bug to me. the particle-Id seems to be "40"

frej4189 commented 1 year ago

Could be related to missing particle data in NMP