Getting Nearby Entities

Hey there!

Is there any way to get nearby entities in Sponge? In Spigot, there’s just a simple .getNearbyEntities(…) that does it for you. I’m having a hard time finding it in Sponge. I see there’s an Extent#getEntities(). I’m not too sure what an Extent is, but isn’t it more or less like a Chunk, but with more info?

Any help is appreciated!

An Extent is any generic area of a world. Both World and Chunk extend Extent.

Hmmm, okay. So is there a way to create an “extent” area of size X x Y x Z and Extent#getEntities()? That could be a possible way to get nearby entities, but there’s probably an easier way xD

You can use extent.getExtentView to get a subsection view of the parent extent.

There are several useful methods to get entities. getEntities can take a predicate to filter through the list of entities. (you could filter for a nearby location for example)
Also you could use getIntersectingEntities, give the method an AABB (axis aligned bounding box) and it will return all entities within that box.

1 Like

Is this what you are looking for? Given an entity you can grab nearby entities within a certain distance.

1 Like

Thanks everyone. Simon, that’s definitely good info I’ll keep in mind. But in this particular case, Zerthick, that’s exactly what I was looking for! :smiley: