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

Add entityAtCursor function #2077

Merged
merged 11 commits into from
Aug 7, 2022
Merged

Add entityAtCursor function #2077

merged 11 commits into from
Aug 7, 2022

Conversation

Chitasa
Copy link
Contributor

@Chitasa Chitasa commented Aug 4, 2021

No description provided.

@u9g
Copy link
Member

u9g commented Aug 4, 2021

needs a lint

@u9g u9g requested a review from Karang August 4, 2021 20:42
lib/plugins/ray_trace.js Outdated Show resolved Hide resolved
@u9g
Copy link
Member

u9g commented Aug 4, 2021

shouldnt this be entityAtCursor instead? since you will hit any entity first even if you have a player in range of your cursor?

@Chitasa
Copy link
Contributor Author

Chitasa commented Aug 4, 2021

I used bot.players rather than bot.entities so it should only target players.

@u9g
Copy link
Member

u9g commented Aug 4, 2021

I used bot.players rather than bot.entities so it should only target players.

why? defeats the purpose of this since if you have a mob infront of the player you wont notice

@Chitasa
Copy link
Contributor Author

Chitasa commented Aug 4, 2021

I used bot.players rather than bot.entities so it should only target players.

why? defeats the purpose of this since if you have a mob infront of the player you wont notice

It's mostly because I haven't played around with bounding boxes of other entities (and the use case I had in mind didn't have other entities), but I can always make changes to it so it uses different entities as well.

@Chitasa Chitasa changed the title Add playerAtCursor function Add entityAtCursor function Aug 4, 2021
@rom1504 rom1504 added this to Needs triage in PR Triage Aug 7, 2021
@rom1504 rom1504 moved this from Needs triage to Waiting for user input in PR Triage Aug 7, 2021
@Chitasa
Copy link
Contributor Author

Chitasa commented Aug 7, 2021

Seeing as there's no changes requested, is there anything I need to do?

lib/plugins/ray_trace.js Outdated Show resolved Hide resolved
@Chitasa
Copy link
Contributor Author

Chitasa commented Aug 9, 2021

There seems to be a weird bug in RaycastIterator.intersect where an intersection is detected at

{
  pos: Vec3 {
    x: -1.4554090302898173,
    y: 83.76438681030076,
    z: 6.829271060309972
  },
  face: 3
}

when pos is

{ x: -2, y: 83, z: 3, face: 3 }

Am I just using the function wrong, or is it an actual bug?

@Karang
Copy link
Contributor

Karang commented Aug 9, 2021

There seems to be a weird bug in RaycastIterator.intersect where an intersection is detected at

{
  pos: Vec3 {
    x: -1.4554090302898173,
    y: 83.76438681030076,
    z: 6.829271060309972
  },
  face: 3
}

when pos is

{ x: -2, y: 83, z: 3, face: 3 }

Am I just using the function wrong, or is it an actual bug?

What do you mean ? It's unlikely that the position returned by intersect has only integer coordinates, so the first one seems more legit.
The intersect method returns the exact point of intersection of the bounding box with the ray, not the center of the entity.

@Chitasa
Copy link
Contributor Author

Chitasa commented Aug 9, 2021

There seems to be a weird bug in RaycastIterator.intersect where an intersection is detected at

{
  pos: Vec3 {
    x: -1.4554090302898173,
    y: 83.76438681030076,
    z: 6.829271060309972
  },
  face: 3
}

when pos is

{ x: -2, y: 83, z: 3, face: 3 }

Am I just using the function wrong, or is it an actual bug?

What do you mean ? It's unlikely that the position returned by intersect has only integer coordinates, so the first one seems more legit.
The intersect method returns the exact point of intersection of the bounding box with the ray, not the center of the entity.

I'm more focused on the distance between the 2 points rather than the position being only integer coordinates. The first coordinate I posted was the intersection while the second one was the pos returned by RaycastIterator.next() (I probably should have explained that earlier oops). There is an approx 3 block distance between the 2 points, while at most it should be roughly 1-2 blocks, so it really should not be intersecting.

I forgot to mention, but this was primarily looked into cause I noticed the bot was attacking behind itself.

lib/plugins/ray_trace.js Outdated Show resolved Hide resolved
lib/plugins/ray_trace.js Outdated Show resolved Hide resolved
lib/plugins/ray_trace.js Outdated Show resolved Hide resolved
@Karang
Copy link
Contributor

Karang commented Aug 10, 2021

There seems to be a weird bug in RaycastIterator.intersect where an intersection is detected at

{
  pos: Vec3 {
    x: -1.4554090302898173,
    y: 83.76438681030076,
    z: 6.829271060309972
  },
  face: 3
}

when pos is

{ x: -2, y: 83, z: 3, face: 3 }

Am I just using the function wrong, or is it an actual bug?

What do you mean ? It's unlikely that the position returned by intersect has only integer coordinates, so the first one seems more legit.
The intersect method returns the exact point of intersection of the bounding box with the ray, not the center of the entity.

I'm more focused on the distance between the 2 points rather than the position being only integer coordinates. The first coordinate I posted was the intersection while the second one was the pos returned by RaycastIterator.next() (I probably should have explained that earlier oops). There is an approx 3 block distance between the 2 points, while at most it should be roughly 1-2 blocks, so it really should not be intersecting.

I forgot to mention, but this was primarily looked into cause I noticed the bot was attacking behind itself.

Now that i looked the code it makes sense. The 2 pos you are talking about are unrelated.

For the bot attacking behind itself you need to check the sign of the dot product of (pos-eyePosition) and viewDirection

@Chitasa Chitasa requested a review from Karang August 13, 2021 04:11
@rom1504
Copy link
Member

rom1504 commented Aug 15, 2021

is this ready @Karang @O-of ?

@Chitasa
Copy link
Contributor Author

Chitasa commented Aug 15, 2021

Waiting for @Karang to verify, but it's all right on my part.

Copy link
Member

@extremeheat extremeheat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I think this would be better suited to go into prismarine-world like bot.blockAtCursor.

const entity = entities[i]
const w = entity.width / 2

const shapes = [[-w, 0, -w, w, entity.height + (entity.type === 'player' ? 0.18 : 0), w]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does the 0.18 constant come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the 0.18 constant comes is due to this where the bot's height is set to its eye height, 1.62, rather than the bot's actual height 1.80.

@Chitasa
Copy link
Contributor Author

Chitasa commented Aug 31, 2021

LGTM, but I think this would be better suited to go into prismarine-world like bot.blockAtCursor.

I thought that bot.blockAtCursor is also in ray_trace.js too?

@rom1504
Copy link
Member

rom1504 commented Sep 26, 2021

this needs docs

@rom1504 rom1504 moved this from Waiting for user input to Almost too old in PR Triage Sep 26, 2021
@Karang
Copy link
Contributor

Karang commented Sep 26, 2021

LGTM, but I think this would be better suited to go into prismarine-world like bot.blockAtCursor.

I thought that bot.blockAtCursor is also in ray_trace.js too?

pworld doesn't have entities yet, so it makes sense to be in mineflayer for now. can be moved later

Copy link
Contributor

@Saiv46 Saiv46 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@amoraschi
Copy link
Contributor

Can you also add it in index.d.ts?

@Pix3lPirat3
Copy link

One issue I've ran into with this myself (which I just added a blacklist argument for my own purposes) is that it likes to target experience orbs, which may create unwanted results for some users of this function, as you can interact through experience orbs and such.

@rom1504 rom1504 merged commit 3304ca0 into PrismarineJS:master Aug 7, 2022
PR Triage automation moved this from Almost too old to Closed Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PR Triage
  
Closed
Development

Successfully merging this pull request may close these issues.

None yet

8 participants