From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Sat, 2 Nov 2024 04:15:20 -0400 Subject: [PATCH] Cache chunk key Cache convert process between ChunkPos < - > chunkKey This patch didn't cahce SectionPos or BlockPos to chunkKey, since it needs to consider the mutable blockpos siutation. TODO: Cache block pos and section pos, whether need? diff --git a/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java b/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java index 1b8193587814225c2ef2c5d9e667436eb50ff6c5..d7d1d4b31043279753888b9c1e299acead7c91e1 100644 --- a/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java +++ b/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java @@ -127,7 +127,7 @@ public final class NearbyPlayers { } public TrackedChunk getChunk(final ChunkPos pos) { - return this.byChunk.get(CoordinateUtils.getChunkKey(pos)); + return this.byChunk.get(pos.chunkKey); // Leaf - Cache chunk key } public TrackedChunk getChunk(final BlockPos pos) { @@ -143,7 +143,7 @@ public final class NearbyPlayers { } public ReferenceList getPlayers(final ChunkPos pos, final NearbyMapType type) { - return this.directByChunk[type.ordinal()].get(CoordinateUtils.getChunkKey(pos)); + return this.directByChunk[type.ordinal()].get(pos.chunkKey); // Leaf - Cache chunk key } public ReferenceList getPlayersByChunk(final int chunkX, final int chunkZ, final NearbyMapType type) { diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java index b5817aa8f537593f6d9fc6b612c82ccccb250ac7..a43b8b9549b308c5143344b633aacda0e538510f 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java @@ -506,7 +506,7 @@ public final class ChunkHolderManager { public boolean addTicketAtLevel(final TicketType type, final ChunkPos chunkPos, final int level, final T identifier) { - return this.addTicketAtLevel(type, CoordinateUtils.getChunkKey(chunkPos), level, identifier); + return this.addTicketAtLevel(type, chunkPos.chunkKey, level, identifier); // Leaf - Cache chunk key } public boolean addTicketAtLevel(final TicketType type, final int chunkX, final int chunkZ, final int level, @@ -604,7 +604,7 @@ public final class ChunkHolderManager { } public boolean removeTicketAtLevel(final TicketType type, final ChunkPos chunkPos, final int level, final T identifier) { - return this.removeTicketAtLevel(type, CoordinateUtils.getChunkKey(chunkPos), level, identifier); + return this.removeTicketAtLevel(type, chunkPos.chunkKey, level, identifier); // Leaf - Cache chunk key } public boolean removeTicketAtLevel(final TicketType type, final int chunkX, final int chunkZ, final int level, final T identifier) { @@ -1224,7 +1224,7 @@ public final class ChunkHolderManager { } public static TicketOperation addOp(final ChunkPos chunk, final TicketType type, final int ticketLevel, final T identifier) { - return addOp(CoordinateUtils.getChunkKey(chunk), type, ticketLevel, identifier); + return addOp(chunk.chunkKey, type, ticketLevel, identifier); // Leaf - Cache chunk key } public static TicketOperation addOp(final int chunkX, final int chunkZ, final TicketType type, final int ticketLevel, final T identifier) { @@ -1236,7 +1236,7 @@ public final class ChunkHolderManager { } public static TicketOperation removeOp(final ChunkPos chunk, final TicketType type, final int ticketLevel, final T identifier) { - return removeOp(CoordinateUtils.getChunkKey(chunk), type, ticketLevel, identifier); + return removeOp(chunk.chunkKey, type, ticketLevel, identifier); // Leaf - Cache chunk key } public static TicketOperation removeOp(final int chunkX, final int chunkZ, final TicketType type, final int ticketLevel, final T identifier) { diff --git a/ca/spottedleaf/moonrise/patches/starlight/light/StarLightInterface.java b/ca/spottedleaf/moonrise/patches/starlight/light/StarLightInterface.java index 571db5f9bf94745a8afe2cd313e593fb15db5e37..108db549eeb4a33c9a9c0c19833766139f7625b4 100644 --- a/ca/spottedleaf/moonrise/patches/starlight/light/StarLightInterface.java +++ b/ca/spottedleaf/moonrise/patches/starlight/light/StarLightInterface.java @@ -818,7 +818,7 @@ public final class StarLightInterface { } public ServerChunkTasks queueChunkLightTask(final ChunkPos pos, final BooleanSupplier lightTask, final Priority priority) { - final ServerChunkTasks ret = this.chunkTasks.compute(CoordinateUtils.getChunkKey(pos), (final long keyInMap, ServerChunkTasks valueInMap) -> { + final ServerChunkTasks ret = this.chunkTasks.compute(pos.chunkKey, (final long keyInMap, ServerChunkTasks valueInMap) -> { // Leaf - Cache chunk key if (valueInMap == null) { valueInMap = new ServerChunkTasks( keyInMap, ServerLightQueue.this.lightInterface, ServerLightQueue.this, priority diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java index 9f3fe9ffdbd2973754898233cca60b7335d671c9..b588386ade7a23750dcf5f64b383760404359af2 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -508,7 +508,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @Override public final void moonrise$markChunkForPlayerTicking(final LevelChunk chunk) { final ChunkPos pos = chunk.getPos(); - if (!this.playerTickingRequests.containsKey(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(pos))) { + if (!this.playerTickingRequests.containsKey(pos.chunkKey)) { // Leaf - Cache chunk key return; } @@ -2568,7 +2568,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe public boolean isNaturalSpawningAllowed(ChunkPos chunkPos) { // Paper start - rewrite chunk system - final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(chunkPos)); + final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(chunkPos.chunkKey); // Leaf - Cache chunk key return chunkHolder != null && chunkHolder.isEntityTickingReady(); // Paper end - rewrite chunk system } diff --git a/net/minecraft/world/level/ChunkPos.java b/net/minecraft/world/level/ChunkPos.java index 6e2b2d258e47dcca30a5ad9f4f492598f2bc21fb..9b6db05fa2e8e667453e9b3c703ae1cd519e30d5 100644 --- a/net/minecraft/world/level/ChunkPos.java +++ b/net/minecraft/world/level/ChunkPos.java @@ -47,6 +47,7 @@ public class ChunkPos { public final int x; public final int z; public final long longKey; // Paper + public final long chunkKey; // Leaf - Cache chunk key private static final int HASH_A = 1664525; private static final int HASH_C = 1013904223; private static final int HASH_Z_XOR = -559038737; @@ -55,18 +56,21 @@ public class ChunkPos { this.x = x; this.z = y; this.longKey = asLong(this.x, this.z); // Paper + this.chunkKey = ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(this.x, this.z); // Leaf - Cache chunk key } public ChunkPos(BlockPos pos) { this.x = SectionPos.blockToSectionCoord(pos.getX()); this.z = SectionPos.blockToSectionCoord(pos.getZ()); this.longKey = asLong(this.x, this.z); // Paper + this.chunkKey = ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(this.x, this.z); // Leaf - Cache chunk key } public ChunkPos(long packedPos) { this.x = (int)packedPos; this.z = (int)(packedPos >> 32); this.longKey = asLong(this.x, this.z); // Paper + this.chunkKey = ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(this.x, this.z); // Leaf - Cache chunk key } public static ChunkPos minFromRegion(int chunkX, int chunkZ) {