PrismarineJS / mineflayer-pathfinder

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

Callback upon goal reached #25

Closed Garfield100 closed 4 years ago

Garfield100 commented 4 years ago

I know the mineflayer stuff is more event-based but being able to set a callback would be very useful to more easily string together actions. It's very easy to add to the inject function. Should I make a pull request?

Karang commented 4 years ago

The dynamic goals can emit the goal_reached event multiple time, that would not fit well with callbacks. The choice of using events was made to work with all types of goals.

It is easy enough to wrap the plugin to use callback in your code:

function gotoGoalCallback(goal, callback) {
  bot.pathfinder.setGoal(goal)
  bot.once('goal_reached', callback)
}
Garfield100 commented 4 years ago

Forgive me, I was unaware that .once could be used like that. That actually makes all of mineflayer a lot easier 😅 thank you