PrismarineJS / mineflayer

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

Add entity in sight #576

Open KittenPopo opened 7 years ago

KittenPopo commented 7 years ago

Hey, I started work again on my Mineflayer PvP bot, but could not figure out how to test if the bot was looking at the player before it attacked.

Would I need to make a script to tell if the rotation of the bot is somewhat at the needed rotation to point at the player, or can I get this from something not listed in the API?

roblabla commented 7 years ago

It doesn't look like we have anything to make sure we're pointing at a certain entity. We do have a lookAt function to change our yaw/pitch. You might be able to reuse some of it to make such a function.

To make a isLookingAt(ent) -> bool function, we'd basically need to make sure that the first entity in our line of sight is the one passed as an argument. We'd also have to take into account bounding boxes (do we have them ? I can see width/height in the entities of minecraft-data, but I can't find a "player" entity. This should probably be fixed ? @rom1504 ).

This is very much a PR welcome issue :) If you need some help to write it, feel free to ask :)

rom1504 commented 7 years ago

I believe we have a line of sight function in mineflayer now

On Sat, Aug 5, 2017, 15:13 Robin Lambertz notifications@github.com wrote:

It doesn't look like we have anything to make sure we're pointing at a certain entity. We do have a lookAt https://github.com/PrismarineJS/mineflayer/blob/2d5e3e98360cc510afdb96182f58d2c2bf86f634/lib/plugins/physics.js#L332 function to change our yaw/pitch. You might be able to reuse some of it to make such a function.

To make a isLookingAt(ent) -> bool function, we'd basically need to make sure that the first entity in our line of sight is the one passed as an argument. We'd also have to take into account bounding boxes (do we have them ? I can see width/height in the entities of minecraft-data, but I can't find a "player" entity. This should probably be fixed ? @rom1504 https://github.com/rom1504 ).

This is very much a PR welcome issue :) If you need some help to write it, feel free to ask :)

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/576#issuecomment-320443015, or mute the thread https://github.com/notifications/unsubscribe-auth/ACPN_j-p2Gtu4GkizjclznYT1agXtxKvks5sVGpvgaJpZM4Oucwo .

KittenPopo commented 7 years ago

Ok cool!

I am looking for something to act like a Trigger Bot from a hacked client that will hit any entity it is looking at.

Something that would also work is getting the bot to use the Hit-Input (a.k.a. the left mouse button) and it would act like a regular MC client where the bot would just swing its arm if it missed and hit the player if it was looking at it.

rom1504 commented 7 years ago

Ok so we have https://github.com/PrismarineJS/mineflayer/blob/master/doc/api.md#botcanseeblockblock for the line of sight test. About doing an archerbot, have a look at https://github.com/andrewrk/archerbot

have a look at https://github.com/rom1504/rbot/blob/f9bb366f6d01f77ff15cb346173ed2862d495901/lib/nearest.js#L113 too

https://github.com/rom1504/rbot#interesting-use-of-commands

repeat shoot me done is basically what you want

@roblabla Player is not really an entity. But I think we have the bounding box data somewhere (in physics.js probably)

TheDudeFromCI commented 4 years ago

Related PR: https://github.com/PrismarineJS/mineflayer/pull/1371