Jump to content

Vanilla entity and player collision detection


DocBrian

Recommended Posts

I can easily detect collisions with other entities in my custom entities, but I'm trying to detect them in vanilla entities.  Since there's no EntityCollision event, I've heard of people polling for collisions via player update events or entityLiving update events, but so far I'm not seeing how I'd go about grabbing that info.  I have a pretty decent understanding of Java and the Minecraft API, so I don't need a lot of details on how to code it; I just need someone to point me in the right direction.  I'm looking for entity/entity collisions and entity/player collisions.

 

By the way, I'd like to make this work with both 1.7 and 1.12.  Would it require similar or different techniques for each version?

 

Thanks in advance!

Link to comment
Share on other sites

By the way, the way I'm currently trying is Minecraft.getMinecraft().theWorld.getEntitiesWithinAABBExcludingEntity() and setting the AABB to the bounding box of the entity and excluding itself.  Seems to work most of the time, but not always.

 

Is there a better way?

Link to comment
Share on other sites

10 hours ago, DocBrian said:

Minecraft.getMinecraft().theWorld.getEntitiesWithinAABBExcludingEntity() and setting the AABB to the bounding box of the entity and excluding itself.  Seems to work most of the time, but not always.

You could try interpolating the bounding boxes based on time, this might not work very well though.

10 hours ago, DocBrian said:

1.7

Sorry we don't support 1.7 on this forum anymore due to its age (4+ years old). We simply don't know how to help you anymore.

I think theres an onEntityCollideWithEntity method or something that you can override?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

13 hours ago, DocBrian said:

I'm currently trying is Minecraft.getMinecraft().theWorld.getEntitiesWithinAABBExcludingEntity() and setting the AABB to the bounding box of the entity and excluding itself.  Seems to work most of the time, but not always.

One reason that it may not always work is that I'm guessing the method only looks for entities that have their origin point within that range.  Ie. something with a large bounding box (like the ender dragon) could have its origin point (the point referred to by its posX, etc) outside your entity's bounding box, but still have a (large) part of its own bounding box overlapping that of your entity.

 

This is all assuming the method you posted doesn't account for entity bounding boxes when you give it a range.

Link to comment
Share on other sites

26 minutes ago, Laike_Endaril said:

One reason that it may not always work is that I'm guessing the method only looks for entities that have their origin point within that range

World#getEntitiesWithinAABBExcludingEntity(or rather Chunk#getEntitiesWithinAABBForEntity) iterates all entities and checks whether their bounding boxes intersect with the passed one.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.