From 842373da7d19ee5b4523536734393f2a92078d5f Mon Sep 17 00:00:00 2001 From: themode Date: Thu, 24 Feb 2022 23:07:36 +0100 Subject: [PATCH] Static import in entity tracker --- .../minestom/server/instance/EntityTrackerImpl.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/EntityTrackerImpl.java b/src/main/java/net/minestom/server/instance/EntityTrackerImpl.java index 285d9a286..283ffc45d 100644 --- a/src/main/java/net/minestom/server/instance/EntityTrackerImpl.java +++ b/src/main/java/net/minestom/server/instance/EntityTrackerImpl.java @@ -3,7 +3,6 @@ package net.minestom.server.instance; import net.minestom.server.MinecraftServer; import net.minestom.server.coordinate.Point; import net.minestom.server.entity.Entity; -import net.minestom.server.utils.chunk.ChunkUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; @@ -18,8 +17,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import java.util.function.Supplier; -import static net.minestom.server.utils.chunk.ChunkUtils.forDifferingChunksInRange; -import static net.minestom.server.utils.chunk.ChunkUtils.getChunkIndex; +import static net.minestom.server.utils.chunk.ChunkUtils.*; final class EntityTrackerImpl implements EntityTracker { static final AtomicInteger TARGET_COUNTER = new AtomicInteger(); @@ -140,11 +138,11 @@ final class EntityTrackerImpl implements EntityTracker { // This is used to avoid a map lookup per chunk final TargetEntry entry = (TargetEntry) entries[target.ordinal()]; var rangeRef = entry.references.computeIfAbsent(range, integer -> Long2ObjectSyncMap.hashmap()); - return rangeRef.computeIfAbsent(ChunkUtils.getChunkIndex(chunkX, chunkZ), + return rangeRef.computeIfAbsent(getChunkIndex(chunkX, chunkZ), chunkIndex -> { - final int count = ChunkUtils.getChunkCount(range); + final int count = getChunkCount(range); List> entities = new ArrayList<>(count); - ChunkUtils.forChunksInRange(ChunkUtils.getChunkCoordX(chunkIndex), ChunkUtils.getChunkCoordZ(chunkIndex), range, + forChunksInRange(chunkX, chunkZ, range, (x, z) -> entities.add(entry.chunkEntities.computeIfAbsent(getChunkIndex(x, z), i -> (List) LIST_SUPPLIER.get()))); assert entities.size() == count : "Expected " + count + " chunks, got " + entities.size(); return List.copyOf(entities); @@ -155,7 +153,7 @@ final class EntityTrackerImpl implements EntityTracker { public void nearbyEntities(@NotNull Point point, double range, @NotNull Target target, @NotNull Query query) { final int chunkRange = Math.abs((int) (range / Chunk.CHUNK_SECTION_SIZE)) + 1; final double squaredRange = range * range; - ChunkUtils.forChunksInRange(point, chunkRange, (chunkX, chunkZ) -> { + forChunksInRange(point, chunkRange, (chunkX, chunkZ) -> { var chunkEntities = chunkEntities(chunkX, chunkZ, target); chunkEntities.forEach(entity -> { final Point position = entityPositions.get(entity.getEntityId());