PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.96k stars 904 forks source link

Bring nearestEntity() function from examples/looker.js into mineflayer #1231

Closed ranguli closed 4 years ago

ranguli commented 4 years ago

Is your feature request related to a problem? Please describe.

In order to get the nearest entity to a bot, (to my knowledge) one must implement a nearestEntity() function something like in examples/looker.js, seen here. I think this task is fairly common, and we could prevent code re-use by adding it to the library.

Describe the solution you'd like

It would be great if something like bot.nearestEntity() existed that simply did what is done in the looker.js example. I'd be happy to make a PR copying that function over if someone can advise on what the appropriate place would be in the codebase for it to go.

Describe alternatives you've considered

The main alternative I considered is to simply re-implement that function on each project every time myself or someone else needs it, or stuff it in some sort of 'misc' plugin.

rom1504 commented 4 years ago

Sure why not, you can add it there https://github.com/PrismarineJS/mineflayer/blob/master/lib/plugins/entities.js

Karang commented 4 years ago

optionally, we can add a matcher function parameter like bot.nearestEntity(matcher=(entity)=>true) so we can customize the type and attributes of returned entities (default to all entities)

TheDudeFromCI commented 4 years ago

I second the matching function idea. This function could basically be treated as a sibling to findBlock.