How does sponge retrieve entities with e.g. getEntities? Distance checks?

Does sponge keep an internal list of entities contained in a chunk or does it simply do a distance check on all entities in the world when using Chunk.getEntities()? The same can be asked about Player.getNearbyEntities() (simply a distance check in O(n) time where n is ALL entities?).

Want to know the best way to retrieve entities (i.e. if I should implement my own system or if sponge already keeps internal lists in some classes) (I guess the “best” way is to directly use the UUID since it’s probably implemented using a hashset, but that isn’t an option in my scenario).

Chunk.getEntities() uses Minecraft’s internal list of entities in each chunk. Currently, Entity.getNearbyEntities() does seem to check every entity in the world; I’ll look into using the per-chunk lists to make it faster.

1 Like

Thanks a lot, that’s really helpful!

I will look into using chunks instead in my code.

You should be able to use Entity.getNearbyEntities() for the same performance soon.

1 Like