PrismarineJS / mineflayer

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

Bot can't transition back into configuration state from play state properly. #3292

Open wgaylord opened 8 months ago

wgaylord commented 8 months ago

Versions

Detailed description of a problem

The bot will connect (enter a password since its an offline server) then after 30 seconds it will time out. While looking at the debug logs it appears as if it continues trying to do physics and stuff as if it was in the play state after transitioning back to the configuration to the configuration state

What did you try yet?

I haven't tried much since I just discovered the issue.

Your current code

const mineflayer = require('mineflayer');

var AutoAuth = require('mineflayer-auto-auth')

const bot = mineflayer.createBot({
host: 'play_pika-network_net.pika.host',
port: 25565,
username: '<username>',
auth: 'offline',
version: '1.20.2',
plugins: [AutoAuth],
  AutoAuth: {
    logging: true,
    password: '<a password you set on the server>',
    ignoreRepeat: true
  }
})

bot.on('messagestr', (msg) =>{
    console.log(msg);
})

bot.once('spawn', () => {console.log(`logged in as $(bot.username)`);bot.setControlState('forward',true);})

bot.on('serverAuth', function() {

});

bot.on('kick',(msg) => {console.log('kicked '+msg)})

Expected behavior

I expect the bot to join the server and stay connected. This was originally reported on the Discord and I continued investigating it.

Additional context

This is the debug log of joining the server. At the end you can notice it was told to enter the configuration state, then it starts trying to send packets that don't exist, showing that it clearly isn't transitioning properly.

log.txt

wgaylord commented 8 months ago

This is likely to be a bug both here (since it keeps doing position updates) and in node-minecraft-protocol.

wgaylord commented 8 months ago

I have found a solution and will be submitting two PRs one to mineflayer and one to node-minecraft-protocol

wgaylord commented 8 months ago

It appears as if only node-minecraft-protocol needed to be fixed. https://github.com/PrismarineJS/node-minecraft-protocol/pull/1284 Close this when that is merged.

wgaylord commented 8 months ago

This is now fixed.

wgaylord commented 8 months ago

Seems I closed this to early, noticed the bot continues trying to send position packets while in config state the second time. Should be a simple fix.

wgaylord commented 8 months ago

Looks like the only reason its not fixed yet is that this fixed version of node-minecraft-protocol has not been pushed as a release to npm yet.

extremeheat commented 8 months ago

Fix was released, there could be issues between switching states even though we only stay in the config phase for a few milliseconds (ideally). So other code might not be aware of state change and continue sending play phase packets within that time. Fixing that is going to be hard, so I'd say let's see if it causes any problems before making lots of changes to everything