PrismarineJS/mineflayer-pathfinder

Pathfinder goes to last death position of target instead to new positions #128

SinanAkkoyun posted onGitHub

Hi, these are relevant code snippets: Basically the normal following works great, but (default behaviour) when the target disconnects the bot just stays where it was. So, I tried this by setting a new goal after the target joins again. After 3 seconds (delay) the bot runs for half a sec towards the target BUT then stops, stays in place and says: "I can get there in 1 moves. Computation took 2115.72 ms" with increasing ms up to around 5000.

What is going on? Also, the bot just stays there after the target died, even if it respawns right next to him. Is there some callback to catch for the entity going missing instead of manually tracking who joined or died?

My code:

//Follow command, works everytime after being called:
goal_memory = [new goals.GoalFollow(target, 2), (cmd[2] ? (isYes(cmd[2]) ? true : false) : true)]
                bot.pathfinder.setGoal(goal_memory[0], goal_memory[1])
//Event, doesnt work at all in very strage way.
//Note that the getPlayer function is somewhat a bot.players[username]
//The log of the entity returns the valid entity as json
//goal_memory[1] stores if its dynamic (which it is everytime in this scenario)
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(!p.entity)) would be better
                if(getPlayer(player.username) && getPlayer(player.username).entity) {
                    log(JSON.stringify(getPlayer(player.username).entity, null, 2))
                    //log(getPlayer(player.username).entity.username)
                    //bot.pathfinder.setGoal(null)
                    bot.pathfinder.setGoal(null)
                    bot.pathfinder.setGoal(new goals.GoalFollow(getPlayer(player.username).entity), goal_memory[1])
                    //let walk_pos = bot.spawnPoint
                    //bot.pathfinder.setGoal(new goals.GoalXZ(walk_pos.x, walk_pos.z, 0))
                    log("[Pathfinder] Set goal to last memory.")
                } else {
                    log("[Memory] Error, could not get entity of " + player.username + ".")
                }
            }, 3000);
        }
    })

Here, it thinks it arrived but when I move away it stays there and this happens:

[Pathfinder] I can get there in 2 moves. Computation took 40.44 ms.
[Pathfinder] I can get there in 2 moves. Computation took 94.30 ms.
[Pathfinder] I can get there in 2 moves. Computation took 161.60 ms.
[Pathfinder] I can get there in 2 moves. Computation took 203.47 ms.
[Pathfinder] I can get there in 1 moves. Computation took 249.68 ms.
[Pathfinder] I can get there in 1 moves. Computation took 311.29 ms.
[Pathfinder] I can get there in 1 moves. Computation took 352.61 ms.
[Pathfinder] I can get there in 1 moves. Computation took 393.60 ms.
[Pathfinder] I can get there in 1 moves. Computation took 449.94 ms.
[Pathfinder] I can get there in 1 moves. Computation took 512.24 ms.
[Pathfinder] I can get there in 1 moves. Computation took 553.87 ms.
[Pathfinder] I can get there in 1 moves. Computation took 595.18 ms.
[Pathfinder] I can get there in 1 moves. Computation took 652.28 ms.
[Pathfinder] I can get there in 1 moves. Computation took 715.80 ms.
[Pathfinder] I can get there in 1 moves. Computation took 757.57 ms.
[Pathfinder] I can get there in 1 moves. Computation took 799.94 ms.
[Pathfinder] I can get there in 1 moves. Computation took 853.86 ms.
[Pathfinder] I can get there in 1 moves. Computation took 915.52 ms.
[Pathfinder] I can get there in 1 moves. Computation took 957.69 ms.
[Pathfinder] I can get there in 1 moves. Computation took 998.88 ms.
[Pathfinder] I can get there in 0 moves. Computation took 40.43 ms.
[Pathfinder] I can get there in 0 moves. Computation took 41.09 ms.
[Pathfinder] I can get there in 0 moves. Computation took 40.09 ms.
[Pathfinder] I can get there in 0 moves. Computation took 40.66 ms.
[Pathfinder] I can get there in 0 moves. Computation took 81.38 ms.
[Pathfinder] I can get there in 0 moves. Computation took 128.63 ms.
[Pathfinder] I can get there in 0 moves. Computation took 40.29 ms.
[Pathfinder] I can get there in 0 moves. Computation took 107.02 ms.
[Pathfinder] I can get there in 0 moves. Computation took 148.00 ms.
[Pathfinder] I can get there in 0 moves. Computation took 188.93 ms.
[Pathfinder] I can get there in 0 moves. Computation took 243.91 ms.
[Pathfinder] I can get there in 0 moves. Computation took 304.13 ms.
[Pathfinder] I can get there in 0 moves. Computation took 345.77 ms.
[Pathfinder] I can get there in 0 moves. Computation took 387.00 ms.
[Pathfinder] I can get there in 0 moves. Computation took 436.55 ms.
[Pathfinder] I can get there in 0 moves. Computation took 494.13 ms.
[Pathfinder] I can get there in 0 moves. Computation took 556.67 ms.
[Pathfinder] I can get there in 0 moves. Computation took 598.19 ms.
[Pathfinder] I can get there in 0 moves. Computation took 638.71 ms.
[Pathfinder] I can get there in 0 moves. Computation took 698.44 ms.
[Pathfinder] I can get there in 0 moves. Computation took 739.00 ms.
[Pathfinder] I can get there in 0 moves. Computation took 780.43 ms.
[Pathfinder] I can get there in 0 moves. Computation took 837.93 ms.
[Pathfinder] I can get there in 0 moves. Computation took 899.68 ms.
[Pathfinder] I can get there in 0 moves. Computation took 940.65 ms.
[Pathfinder] I can get there in 0 moves. Computation took 981.95 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1042.17 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1103.71 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1145.34 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1186.64 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1241.06 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1303.01 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1344.68 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1385.92 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1445.09 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1506.72 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1547.71 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1588.29 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1648.49 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1710.68 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1752.28 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1793.35 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1851.09 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1892.45 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1933.16 ms.
[Pathfinder] I can get there in 0 moves. Computation took 1989.95 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2054.47 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2096.29 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2137.81 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2192.01 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2255.52 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2296.03 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2336.80 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2397.22 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2461.22 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2502.55 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2545.64 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2602.93 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2643.72 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2684.44 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2740.14 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2804.34 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2844.98 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2887.05 ms.
[Pathfinder] I can get there in 0 moves. Computation took 2942.66 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3004.59 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3045.04 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3086.52 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3143.37 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3205.62 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3247.10 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3288.34 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3347.08 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3408.05 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3450.61 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3491.12 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3549.59 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3590.37 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3632.21 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3682.59 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3733.64 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3796.29 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3860.76 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3902.05 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3942.99 ms.
[Pathfinder] I can get there in 0 moves. Computation took 3995.64 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4061.45 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4102.83 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4143.82 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4197.15 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4259.91 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4301.08 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4341.87 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4401.95 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4443.10 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4484.13 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4536.47 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4589.41 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4650.02 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4690.99 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4732.09 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4789.39 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4851.83 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4892.89 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4934.01 ms.
[Pathfinder] I can get there in 0 moves. Computation took 4985.22 ms.
[Pathfinder] I can get there in 0 moves. Computation took 5000.15 ms.
posted by SinanAkkoyun almost 4 years ago

ok, strangely I fixed the respawn target issue with this:

let target = getPlayer(player.username).entity

                    goal_memory[0] = new goals.GoalFollow(target, 2)
                    bot.pathfinder.setGoal(goal_memory[0], goal_memory[1])

If somebody knows why it fixed it please tell me

And the running to the last spot (when target dies) is due to that the bot saves the last copy of the entity when the entity is null, right? I would change that to eiter make the goal finish or let it abrupt. But this way you cant have an event when this happens.

posted by SinanAkkoyun almost 4 years ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests