PrismarineJS / mineflayer

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

An error that keeps on getting spammed after joining a server. PartialReadError: Read error for undefined : undefined #2882

Closed ghost closed 1 year ago

ghost commented 1 year ago

Versions

Detailed description of a problem

I joined the local server and there is no errors, but when i join a server 'PikaNetwork' i keep on getting spammed with the following error.

PartialReadError: Read error for undefined : undefined
    at new ExtendableError (C:\Users\Taha Abdulgader\Desktop\PikaNetwork-API\node_modules\protodef\src\utils.js:63:13)
    at new PartialReadError (C:\Users\Taha Abdulgader\Desktop\PikaNetwork-API\node_modules\protodef\src\utils.js:70:5)
    at Object.readBool [as bool] (C:\Users\Taha Abdulgader\Desktop\PikaNetwork-API\node_modules\protodef\src\datatypes\utils.js:133:41)
    at Object.slot (eval at compile (C:\Users\Taha Abdulgader\Desktop\PikaNetwork-API\node_modules\protodef\src\compiler.js:258:12), <anonymous>:53:61)
    at eval (eval at compile (C:\Users\Taha Abdulgader\Desktop\PikaNetwork-API\node_modules\protodef\src\compiler.js:258:12), <anonymous>:114:59)
    at Object.particleData (eval at compile (C:\Users\Taha Abdulgader\Desktop\PikaNetwork-API\node_modules\protodef\src\compiler.js:258:12), <anonymous>:116:11)
    at Object.packet_world_particles (eval at compile (C:\Users\Taha Abdulgader\Desktop\PikaNetwork-API\node_modules\protodef\src\compiler.js:258:12), <anonymous>:1152:63)
    at eval (eval at compile (C:\Users\Taha Abdulgader\Desktop\PikaNetwork-API\node_modules\protodef\src\compiler.js:258:12), <anonymous>:2338:70)
    at packet (eval at compile (C:\Users\Taha Abdulgader\Desktop\PikaNetwork-API\node_modules\protodef\src\compiler.js:258:12), <anonymous>:2412:9)

What did you try yet?

I tried nothing, just a basic bot with some code in it with no actions but sending a single message to the server...

Your current code

const mineflayer = require('mineflayer')
const { pathfinder } = require('mineflayer-pathfinder')
const express = require('express');

// local = localhost
// pika = pika.host

const bot = mineflayer.createBot({
  host: 'pika.host',
  username: 'UpdateDatabase'
})

const bot_data = {
    "on_server": false,
    "position": null,
    "login": false
}

const app = express()
const port = 3000

bot.loadPlugin(pathfinder)

// function followPlayer(username) {

//     const mcData = require('minecraft-data')(bot.version)
//     const movements = new Movements(bot, mcData)
//     movements.scafoldingBlocks = []

//     bot.pathfinder.setMovements(movements)

//     p = bot.players[username].entity.position

//     bot.pathfinder.setGoal(new goals.GoalNear(p.x, p.y, p.z, 1))

//     bot.on('goal_reached', function Arrived(){
//       console.log("Reached my destination!")
//       bot.lookAt(p)
//       bot.attack(bot.players[username])
//     }
// )
//   };

bot.once('spawn', () => {

    bot_data.on_server = true
    bot_data.position = bot.entity.position

    console.log("I am online.")

  })

bot.on('chat', (username, message) => {
  if (username === bot.username) return

  console.log(`${username} > ${message}`)

  if (message === "Successful login!") {
    console.log("Login Succesfully.")
    bot_data.login = true
  }
  if (message === "Please register with /register <password> <password>") {
    setTimeout(function() {
      bot.chat("/register password password");
      console.log("Registered Succesfully.")
  }, 3000);
  }
  if (message === "Please login with /login <password>") {
    setTimeout(function() {
      bot.chat("/login password");
      console.log("Login Succesfully.")
  }, 3000);
  }
})

// express server routes

app.get('/get_position', (req, res) => {
    res.send(bot_data.position)
  })

app.get('/entities', (req, res) => {
    res.send(bot.entities)
})

app.get('/players', (req, res) => {
    res.send(bot.players)
})

// express server runner
app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
})
// ------------#

// Log errors and kick reasons:
bot.on('kicked', console.log)
bot.on('error', console.log)

bot.on('death', function() {
  bot.chat("I died x.x");
})

Expected behavior

The console should not spam any errors and work normally...

Additional context

Add any other context about the problem here.

ghost commented 1 year ago

used hideErrors: true to hide the spam of this error, the error causes vscode to crash or freeze for some reason, related to terminal if i'm being honest.

kashalls commented 1 year ago

used hideErrors: true to hide the spam of this error, the error causes vscode to crash or freeze for some reason, related to terminal if i'm being honest.

Constant writes to stdin will cause the node lifecycle to just ignore heartbeats in the bot etc...

ghost commented 1 year ago

I see, explains the freezing once this error starts spamming.

On Mon, 2 Jan 2023, 3:27 pm Kashall, @.***> wrote:

used hideErrors: true to hide the spam of this error, the error causes vscode to crash or freeze for some reason, related to terminal if i'm being honest.

Constant writes to stdin will cause the node lifecycle to just ignore heartbeats in the bot etc...

— Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/2882#issuecomment-1368992848, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3YHJBUICTCHOEON64VYLQDWQLQU3ANCNFSM6AAAAAATNPY6YI . You are receiving this because you authored the thread.Message ID: @.***>