9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-22 00:19:20 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0105-Cache-chunk-key.patch
Dreeam d06fb16da3 Updated Upstream (Paper/Gale/Purpur)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@30fdfb1a [ci/skip] Fix docs for DamageResistant (#11992)
PaperMC/Paper@6b7650d8 Only add goat horn once (#12001)
PaperMC/Paper@30046e04 Fix a rare crash with a concurrent modification of scaled health attributes (#12002)
PaperMC/Paper@88bbead1 Flush regionfiles on save configuration option
PaperMC/Paper@336ea9df Check for empty when sending equipment changes (#12008)
PaperMC/Paper@939bb782 Add RayTraceConfigurationBuilder (#11907)
PaperMC/Paper@81bb82f5 Fix wrong piston world border check (#12007)
PaperMC/Paper@ce95b5d6 Use proper default for setting null display background color (#12010)
PaperMC/Paper@2477f1f6 [ci/skip] fix and improvements for docs in ConsumeEffect component (#11998)
PaperMC/Paper@fb5b173c Add PlayerClientLoadedWorldEvent (#11940)
PaperMC/Paper@3af5e771 Add Player#give (#11995)
PaperMC/Paper@7e21cb81 fix PlayerChangedMainHandEvent javadoc (#12020)
PaperMC/Paper@5a34bf04 Correctly retrun true for empty input shapes in EntityGetter#isUnobstructed
PaperMC/Paper@a392d475 Make Watchdog thread extend TickThread

Gale Changes:
Dreeam-qwq/Gale@f9080a7e Updated Upstream (Paper)
Dreeam-qwq/Gale@ff0596c1 [ci/skip] Fix upstream commit sh on mac
Dreeam-qwq/Gale@24970274 [ci/skip] Hermanez - Wutaf
Dreeam-qwq/Gale@85eabf60 [ci/skip] cleanup
Dreeam-qwq/Gale@7d9faf00 [ci/skip] cleanup & drop xor-shift random
Dreeam-qwq/Gale@7af04981 [ci/skip] cleanup
Dreeam-qwq/Gale@4d5d39df [ci/skip] Remove useless params standardize in upstream commit generator
Dreeam-qwq/Gale@964f16ff Updated Upstream (Paper)
Dreeam-qwq/Gale@0566a223 [ci/skip] cleanup
Dreeam-qwq/Gale@5e3f6740 [ci/skip] cleanup work finished
Dreeam-qwq/Gale@98a66cfb Updated Upstream (Paper)
Dreeam-qwq/Gale@f7736578 [ci/skip] Update upstreamCommit.sh
Dreeam-qwq/Gale@1c46c816 Updated Upstream (Paper)
Dreeam-qwq/Gale@2b0a4c09 [ci/skip] Skip tests during auto update validate phase

Purpur Changes:
PurpurMC/Purpur@4a0a86b9 Updated Upstream (Paper)
PurpurMC/Purpur@7399988c Fix hover in /plugins
PurpurMC/Purpur@5e5857dc [ci/skip] modify ci skip references in paper upstream commits
PurpurMC/Purpur@5583a3f1 Updated Upstream (Paper)
2025-01-27 20:08:18 -05:00

142 lines
8.6 KiB
Diff

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<ServerPlayer> 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<ServerPlayer> 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 <T> boolean addTicketAtLevel(final TicketType<T> 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 <T> boolean addTicketAtLevel(final TicketType<T> type, final int chunkX, final int chunkZ, final int level,
@@ -604,7 +604,7 @@ public final class ChunkHolderManager {
}
public <T> boolean removeTicketAtLevel(final TicketType<T> 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 <T> boolean removeTicketAtLevel(final TicketType<T> type, final int chunkX, final int chunkZ, final int level, final T identifier) {
@@ -1224,7 +1224,7 @@ public final class ChunkHolderManager {
}
public static <T> TicketOperation<T, T> addOp(final ChunkPos chunk, final TicketType<T> 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 <T> TicketOperation<T, T> addOp(final int chunkX, final int chunkZ, final TicketType<T> type, final int ticketLevel, final T identifier) {
@@ -1236,7 +1236,7 @@ public final class ChunkHolderManager {
}
public static <T> TicketOperation<T, T> removeOp(final ChunkPos chunk, final TicketType<T> 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 <T> TicketOperation<T, T> removeOp(final int chunkX, final int chunkZ, final TicketType<T> 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) {