mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 02:57:37 +01:00
Fix nearbyEntities not working with chunk borders
This commit is contained in:
parent
9a7d5039a7
commit
69ab2c0045
@ -112,7 +112,14 @@ final class EntityTrackerImpl implements EntityTracker {
|
|||||||
@Override
|
@Override
|
||||||
public <T extends Entity> void nearbyEntities(@NotNull Point point, double range, @NotNull Target<T> target, @NotNull Consumer<T> query) {
|
public <T extends Entity> void nearbyEntities(@NotNull Point point, double range, @NotNull Target<T> target, @NotNull Consumer<T> query) {
|
||||||
final TargetEntry<Entity> entry = entries[target.ordinal()];
|
final TargetEntry<Entity> entry = entries[target.ordinal()];
|
||||||
final int chunkRange = (int) (range / Chunk.CHUNK_SECTION_SIZE);
|
final int chunkRange;
|
||||||
|
// No need to loop through neighbor chunk if the point is a chunk coordinate
|
||||||
|
if (point.x() % 16 == 0 && point.z() % 16 == 0) {
|
||||||
|
chunkRange = (int) (range / Chunk.CHUNK_SECTION_SIZE);
|
||||||
|
} else {
|
||||||
|
chunkRange = (int) (range / Chunk.CHUNK_SECTION_SIZE) + 1;
|
||||||
|
}
|
||||||
|
// Loop through range
|
||||||
if (range % 16 == 0) {
|
if (range % 16 == 0) {
|
||||||
// Fast path for exact chunk range
|
// Fast path for exact chunk range
|
||||||
forChunksInRange(point, chunkRange, (chunkX, chunkZ) -> {
|
forChunksInRange(point, chunkRange, (chunkX, chunkZ) -> {
|
||||||
|
@ -169,6 +169,12 @@ public class EntityTrackerTest {
|
|||||||
entities.add(ent3);
|
entities.add(ent3);
|
||||||
tracker.nearbyEntities(Vec.ZERO, 50, EntityTracker.Target.ENTITIES, entity -> assertTrue(entities.remove(entity)));
|
tracker.nearbyEntities(Vec.ZERO, 50, EntityTracker.Target.ENTITIES, entity -> assertTrue(entities.remove(entity)));
|
||||||
assertEquals(0, entities.size());
|
assertEquals(0, entities.size());
|
||||||
|
|
||||||
|
// Chunk border
|
||||||
|
tracker.move(ent1, new Vec(16, 0, 0), EntityTracker.Target.ENTITIES, updater);
|
||||||
|
entities.add(ent1);
|
||||||
|
tracker.nearbyEntities(new Vec(15, 0, 0), 2, EntityTracker.Target.ENTITIES, entity -> assertTrue(entities.remove(entity)));
|
||||||
|
assertEquals(0, entities.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user