PrismarineJS / mineflayer-pathfinder

Pathfinding plugin that gives bot the ability to go from A to B
MIT License
218 stars 67 forks source link

Bot Constantly Stuck or Halts with GoalFollow - #332

Open zhaungsont opened 1 year ago

zhaungsont commented 1 year ago

Hi, I have a section of the code that tells the bot to follow a user using GoalFollow, but for some reason my implementation of pathfinder just doesn't seem to work. My bot would sometimes stop for no reason, or sprint into a corner and stuck there.

Issue Description

I have observed 3 main issues:

  1. When the bot follows a player, it doesn't stop as soon as it reaches the radius of the goal player, instead it continues to push into the player.
  2. Sometimes upon receiving the follow command, the bot does not immediately start moving until several seconds later; and sometimes it follows for a while, and then decides to halt.
  3. Sometimes the pathfinding would lead it next to a bamboo or a display case, and it would be stuck there (sometimes it appears to be sprinting even though it is stuck); sometimes is simply a stone wall that is stopping him. It is worth noting that I have encountered one incident where the program crashed after running the follow command for a short while. The error log reads as follows:
    Error: client timed out after 30000 milliseconds
    at Timeout._onTimeout (/Users/sakanasont/Documents/GitHub/mineflayer-gpt/node_modules/minecraft-protocol/src/client/keepalive.js:18:28)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7)
    Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
    errno: -54,
    code: 'ECONNRESET',
    syscall: 'read'
    }
    {"translate":"disconnect.timeout"} true
    [nodemon] clean exit - waiting for changes before restart

Testing Environment

My Code

import pkg from 'mineflayer-pathfinder';
const { pathfinder, Movements, goals } = pkg;
const { GoalNear, GoalFollow } = goals;

// create bot
const options = { ... };
const bot = mineflayer.createBot(options);

//bot plugins
bot.loadPlugin(pathfinder);

bot.once('spawn', () => {
    bot.on('chat', (username, message) => {
        followHandler(username);
    });
});

function followHandler(username) {
    const RANGE_GOAL = 5; // get within this radius of the player
    const target = bot.players[username]?.entity;
    if (!target) {
        bot.chat("I don't see you !");
        return;
    }
    bot.chat(`Coming, ${username} !`);
    const goal = new GoalFollow(bot.players[username].entity, RANGE_GOAL);
    bot.pathfinder.setGoal(goal, true);
}

Is there any issue with the implementation itself? I'm suspecting there might also be some external factors at play here, such as the fact that I'm testing all its behaviors on a free Minecraft server (aternos.org) and the connection usually isn't great.

Any help is appreciated, thanks.

IceTank commented 1 year ago

The first error you posted happens because the connection timed out. That should not have anything to do with pathfinder. The code itself is fine and should work. The issue you are experiencing sounds more like the control state is stuck. This could be an issue in pathfinder some steps to reliably reproduce this issue would be good.

zhaungsont commented 1 year ago

Thanks for the suggestion. I'll try to do exactly that!