PrismarineJS / mineflayer-pathfinder

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

Crash stateGoal.hasChanged not a function #127

Closed SinanAkkoyun closed 3 years ago

SinanAkkoyun commented 3 years ago

Hi, why is this happening?

C:\Users\X\Desktop\SAVE\Minecraft\NodeJS-Bot\node_modules\mineflayer-pathfinder\index.js:313
    if (stateGoal && stateGoal.hasChanged()) {
                               ^

TypeError: stateGoal.hasChanged is not a function
    at EventEmitter.monitorMovement (C:\Users\X\Desktop\SAVE\Minecraft\NodeJS-Bot\node_modules\mineflayer-pathfinder\index.js:313:32)
    at EventEmitter.emit (node:events:390:22)
    at Timeout.doPhysics [as _onTimeout] (C:\Users\Xyun\Desktop\SAVE\Minecraft\NodeJS-Bot\node_modules\mineflayer\lib\plugins\physics.js:63:13)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)
SinanAkkoyun commented 3 years ago

My code:

bot.on("playerJoined", (player) => {
        if(goal_memory && goal_memory[0] instanceof goals.GoalFollow && goal_memory[0].entity.username.trim() === player.username.trim()) {
            setTimeout(() => {  //Non blocking while would be better
                if(bot.players[player.username] && bot.players[player.username].entity) {

                    bot.pathfinder.setGoal(bot.players[player.username].entity, goal_memory[1])

                log("[Pathfinder] Set goal to last memory.")
                } else {
                    log("[Memory] Error, could not get entity of " + player.username + ".")
                }
            }, 3000);
        }
    })

btw the bot loses track after a disconnect or world change of the target, likely the entity gets set new then or something

do you know any better way to keep the goal in the bots "memory"?

SinanAkkoyun commented 3 years ago

And why is there no function to get the current goal of the pathfinder? Would be so useful

Karang commented 3 years ago

You need to read the documentation: https://github.com/PrismarineJS/mineflayer-pathfinder#botpathfindersetgoalgoal-dynamic

setGoal expect a goal instance and a boolean, you are giving it an entity and a goal instance. Parameters order and type are not optional, you need to follow the doc and example.

You can get the current goal with bot.pathfinder.goal

SinanAkkoyun commented 3 years ago

Oh man I am so dumb XD Thank you!!!!