PrismarineJS / mineflayer-pathfinder

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

setGoal doesn't work on goal_reached? #164

Open BotNC opened 3 years ago

BotNC commented 3 years ago

I think it's just an error that I made, or setGoal really doesn't work on the goal_reached event. Here's my code:

const { pathfinder, goals, Movements } = require('mineflayer-pathfinder');
const blockfinder = require('mineflayer-blockfinder')(mineflayer);

const bot = mineflayer.createBot({ host: 'xxx', port: 'xxx', username: 'woodfetcher' });

bot.loadPlugin(pathfinder);
bot.loadPlugin(blockfinder);

let player;

bot.once('spawn', () => {
    const mcData = require('minecraft-data')(bot.version);
    const defaultMovements = new Movements(bot, mcData);

    bot.on('chat', (username, message) => {
        player = bot.players[username].entity;

        if (message === 'fetch wood') {
            bot.findBlock({
                point: bot.entity.position,
                matching: 17,
                maxDistance: 256,
                count: 1
            }, (err, blocks) => {
                if (err) return console.error(err);

                if (blocks.length >= 1) {
                    bot.chat('Fetching wood!');

                    const pos = blocks[0].position;

                    bot.pathfinder.setMovements(defaultMovements);
                    bot.pathfinder.setGoal(new goals.GoalBlock(pos.x, pos.y, pos.z));
                }
            });
        }
    });

    bot.on('goal_reached', () => {
        bot.chat('Got wood!');

        if (player) {
            bot.pathfinder.setMovements(defaultMovements);
            bot.pathfinder.setGoal(new goals.GoalFollow(player, 2));
        }
    });
});
Khaogamermain01 commented 2 years ago

Try bot.pathfinder.goto(the goal)