PrismarineJS / mineflayer

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

Bot timing out when server has specified resourcepack #3317

Closed TerminalCalamitas closed 8 months ago

TerminalCalamitas commented 8 months ago

Versions

Detailed description of a problem

When connecting to a 1.20.4 server, if the server has a specified resource pack, the bot doesn't spawn and times out.

What did you try yet?

Did you try any method from the API? I tried using the bot.denyResourcePack() and bot.acceptResourcePack() methods, but those didn't work. Did you try any example? Any error from those? The resourcepack example is also unable to join the server.

Your current code

My code is really large, so this is just a small section.


console.log("Loading Options")
// Will load options from runtime args or if they don't exist, load from the config
var options = {
    host: process.argv[3] || config.bot.host,
    port: parseInt(process.argv[4]) ||config.bot.port,
    username: process.argv[2] || config.bot.username,
    auth: process.argv[5] || config.bot.auth,
    version: "1.20.4",
    checkTimeoutInterval: 32*1000
}

//Simple logging for debuging in case a bot isn't launching
console.log("Creating bot")
var bot = mineflayer.createBot(options)
console.log("Loading plugins")
bot.loadPlugin(autoeat)
console.log("Loading plugins.")
bot.loadPlugin(pathfinder)
console.log("Loading plugins..")
bot.loadPlugin(pvp)
console.log("Loading plugins...")
bot.loadPlugin(armormanager)
console.log("Plugins Loaded")

bot.on('resourcePack', () => { // Code from the resourcePack example
  bot.denyResourcePack()
})

bot.on("spawn", () => {
  console.log(`(${bot.username}) running Minecraft-DJ-Bot v${botVersion} logged in!`)
  if (config.startup.active) {
    for (let i = 0; i < config.startup.messages.length; i++) {
      bot.chat(config.startup.messages[i])
    }
  }
  cmd_handler.load()

Expected behavior

In this code the bot should output:

Creating bot
Loading plugins
Loading plugins.
Loading plugins..
Loading plugins...
Plugins Loaded
(${bot.username}) running Minecraft-DJ-Bot v${botVersion} logged in!

But the code gets stuck at Plugins Loaded, then times out.

Additional context

No matter what code examples I run the bot won't connect to a server with a specified resource pack. I've attached a file with the debug output of the bot execution that also has the error that appears in the server console when the bot times out, in case that's helpful. BotTimeOut.log

wgaylord commented 8 months ago

Looks like the resource pack plugin needs to be updated to support the new add_resource_pack packet which allows a server to use multiple resource packs. May also want to add support for the remove_resource_pack packet in that as well. (Keep track of enabled resource packs?)

TerminalCalamitas commented 8 months ago

I'm willing to update the resource_pack.js plugin, but before I do stuff, is there a recommended way to write the plugins? I ask since I'm unfamiliar with how the events get defined.