PrismarineJS / mineflayer-pathfinder

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

Bot goes to unexpected ways #322

Open MegalithOfficial opened 1 year ago

MegalithOfficial commented 1 year ago

I expected to bot go in a square but it just goes randomly and then leaves the server, simply bot dont obey to code and literally breaks/puts block randomly I also check that is the coordinates are true, yes the code gets the valid cordinates My server on 1.19.3

import g, { pathfinder, Movements } from "mineflayer-pathfinder"
import mcdata from "minecraft-data";
import { mineflayer as mineflayerViewer } from 'prismarine-viewer';
import mineflayer from "mineflayer";
import { API } from "./api.js"

const api = new API();
const GoalBlock = g.goals.GoalBlock;

const bot = mineflayer.createBot({
    host: "noip",
    username: "BOT"
});
let botJoinedToServer = false;

bot.once("spawn", async () => {
    pathfinder(bot);
    const Data = mcdata("1.19.3")
    console.log(bot.version)
    const movements = new Movements(bot, Data);
    bot.pathfinder.setMovements(movements);
    start(bot);
    mineflayerViewer(bot, { port: 3000 })
});

async function start(bot) {
    if (!botJoinedToServer) {
        botJoinedToServer = true;
        walk().then(() => {
            bot.quit();
            botJoinedToServer = false;
        });
    }
}

async function walk() {
     const startPos = bot.entity.position

    for (let i = 0; i < 10; i++) {
         await bot.pathfinder.goto(new GoalBlock(startPos.x.toFixed(0) + 1, 62, startPos.z.toFixed(0)));
         await bot.pathfinder.goto(new GoalBlock(startPos.x.toFixed(0) + 1, 62, startPos.z.toFixed(0) + 1));
         await bot.pathfinder.goto(new GoalBlock(startPos.x.toFixed(0), 62, startPos.z.toFixed(0) + 1));
         await bot.pathfinder.goto(new GoalBlock(startPos.x.toFixed(0), 62, startPos.z.toFixed(0)));
    };
};
MegalithOfficial commented 1 year ago

and bot gives timeout when it randomly moves