Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to follow entity indefinitely/until stopped #30

Closed
Garfield100 opened this issue Jul 24, 2020 · 7 comments
Closed

[Question] How to follow entity indefinitely/until stopped #30

Garfield100 opened this issue Jul 24, 2020 · 7 comments

Comments

@Garfield100
Copy link

I'm trying to pick up an item after mining, even if this item drops down to somewhere.
For this I am using the GoalFollow goal, but it doesn't seem to work. The bot stops after reaching the item's initial position and the goal_reached event is fired.
I tried this recursive approach but to no avail:

                           function keepFollowing() {
                                console.log("function keepFollowing called");
                                bot.pathfinder.setGoal(new GoalFollow(itemEntity, 0));
                                bot.once("goal_reached", () => {
                                    console.log("goal_reached fired");
                                    if (!itemGone) {
                                        keepFollowing();
                                    }
                                });
                            }

As you can see in this video, the bot never continues: https://youtu.be/VWl5RxJHCPk

The console output looks like this after the bot has stopped:

function keepFollowing called
goal_reached fired
function keepFollowing called

The bot stops trying to get to the item once it is picked up, by it or by me. This is expected.
Is there a better approach? Did I miss something?

@Garfield100 Garfield100 changed the title How to follow entity indefinitely/until stopped [Question] How to follow entity indefinitely/until stopped Jul 24, 2020
@TheDudeFromCI
Copy link
Member

In the setGoal function, you can assign a goal as dynamic to fix this.

const goal = new GoalFollow(entity, 0)
bot.pathfinder.setGoal(goal, true)

@Karang
Copy link
Collaborator

Karang commented Jul 25, 2020

This is a problem in mineflayer / prismarine-physics. The item entities movements should be updated by the client and it is not done atm. Can you open an issue in p-physics to request this new feature ? (its a bit more complicated than it sounds because the physic simulation should match exactly the server to not cause desync)

@TheDudeFromCI
Copy link
Member

Wait, is that an issue? I tried a similar script on my bot and it seemed to track the item entity fine.

@Karang
Copy link
Collaborator

Karang commented Jul 25, 2020

You can view the issue with p-viewer, only the first tick seems to be sent by the server (vanilla). Its the same with throwed potions, but i think arrows are updated. I saw that some time ago in 1.13, if someone can check what s going on also for other versions that would be great

@TheDudeFromCI
Copy link
Member

Oh, interesting. I didn't notice that before. Strange.
Wouldn't item drop physics triggered on entityMove events, though?

@Karang
Copy link
Collaborator

Karang commented Jul 25, 2020

Yeah it should, but the server only update the position once, so the event is called once.

https://github.com/PrismarineJS/prismarine-viewer/blob/master/lib/mineflayer.js#L82

@Garfield100
Copy link
Author

In the setGoal function, you can assign a goal as dynamic to fix this.

const goal = new GoalFollow(entity, 0)
bot.pathfinder.setGoal(goal, true)

Of course I missed something 🤦‍♂️ it works now, thank you very much.
Not sure what you mean @Karang, it fortunately doesn't seem to cause problems in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants