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

[B+C] Add Location.getNearbyEntities. Adds BUKKIT-3868 #1068

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

NathanWolf
Copy link

The Issue

There is currently an Entity.getNearbyEntities() method, but no way to perform a similar check on an arbitrary Location without an Entity.

Justification for this PR

This PR adds the Location.getNearbyEntities method requested in BUKKIT-3868, as well as a World.getEntities(Location, x, y, z) method that backs it. These additional utility methods provide a way for developers to efficiently query for entities within a given area, without needing a source Entity.

PR Breakdown

Bukkit

Add Location.getNearbyEntities(double x, double y, double z) and World.getEntities(Location center, double x, double y, double z)

CraftBukkit

CraftWorld implements getEntities similarly to CraftEntity, except it passes in a null source Entity (given current NMS code, this is safe, the entity parameter is only used with "==" to filter out the source entity) and it creates an AABB rather than using a modified Entity BB.

Testing Results and Materials

A test plugin can be found here:

https://github.com/NathanWolf/Bukkit-Unit-Tests/tree/Fix-BUKKIT-3868
http://mine.elmakers.com/share/Test-Fix-BUKKIT-3868.jar

This plugin will search for entities at your target block (block under cursor) when you swing (left-click) a stick or blaze rod.

A stick will check within 8 blocks, a blaze rod within 64. It will print a list of entity counts by type in the area, and can be used to validate that the correct entities are found.

Relevant PR(s)

CB-1384: Bukkit/CraftBukkit#1384 - Associated CB PR

JIRA Ticket

https://bukkit.atlassian.net/browse/BUKKIT-3868

This also adds World.getEntities(Location, x, y, z) - which will be
implemented in a corresponding CB branch.
@turt2live
Copy link
Contributor

I would almost say that specifying a bounding box instead of a center with distance on each access would be better. I say this for the sole purpose of being able to call the API without having to potentially translate locations, and it would make implementation in plugins a bit more seamless.

(I hope that made sense. Smartphones should not be used for reviewing prs)

@NathanWolf
Copy link
Author

That makes sense to me, and I agree.

I was aiming to implement the interface requested in the BUKKIT-3868 (not my request). It does make sense in the context of Entity.getNearbyEntities().

What about adding a BoundingBox method in addition to the (center, x, y, z)?

@turt2live
Copy link
Contributor

Honestly I thought that was more an offset method, such as "origin, offX,
offY, offZ" , not a center. But I guess that can happen if you don't read
things like variable names.

Either way, I don't think having the method is worthwhile if there was a
bounding box method (two location objects would be fine. No need for a new
class). Having a single method for boxes and a single method for "radius"
should suffice 99% of people. Then again I suppose a center oriented box
may be useful.

sent from mobile
On May 29, 2014 3:55 PM, "Nathan Wolf" notifications@github.com wrote:

That makes sense to me, and I agree.

I was aiming to implement the interface requested in the BUKKIT-3868 (not
my request). It does make sense in the context of
Entity.getNearbyEntities().

What about adding a BoundingBox method in addition to the (center, x, y,
z)?


Reply to this email directly or view it on GitHub
#1068 (comment).

Also return a Collection instead of a List
import org.bukkit.util.NumberConversions;
import org.bukkit.util.Vector;

import java.util.Collection;
Copy link
Contributor

Choose a reason for hiding this comment

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

This import is in the wrong spot

@turt2live turt2live self-assigned this Jul 20, 2014
@turt2live
Copy link
Contributor

I've created my own testing materials as the ones provided do not operate.

Google Drive

@turt2live turt2live removed their assignment Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants