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

Paper Changes:
PaperMC/Paper@1fcc4162 Implement FeatureHooks#isChunkSent for Moonrise chunk system
PaperMC/Paper@e4d7178a Implement WaypointTransmitter#isChunkVisible
PaperMC/Paper@8980ead7 Directly walk text component after converting from JSON
PaperMC/Paper@5613ed6d Provide env environment variable and copy spigots sys prop for overriding default repository
PaperMC/Paper@62b7f86d Avoid and discourage use of Maven Central as a CDN (#12689)
PaperMC/Paper@f5534cb7 [ci/skip] Run generators (#12691)
PaperMC/Paper@4781d28b Re-add Log4j Javadocs (#12693)
PaperMC/Paper@74fbcce5 Check type of Material in get/set stats (#12607)
PaperMC/Paper@4b3f967e Improve Fix MC-44654 (#12703)
PaperMC/Paper@a7dd2635 Enable spigot obfuscation support (#12695)
PaperMC/Paper@6a51c44e Cleanup Primed TNT Fix (#12704)
PaperMC/Paper@839c6a18 Fix #11169 (#12706)
PaperMC/Paper@c77d5f99 Fix MC-297591
PaperMC/Paper@219f86ee Implement chunk unload delay config option
PaperMC/Paper@e4eb69b8 Do not allow ticket level decreases to be processed asynchronously
PaperMC/Paper@71b0c768 Adds support for vanilla negative explosions (#12705)
PaperMC/Paper@3750927a [ci/skip] Fix PermissionManager#clearPermissions() docs bad wording (#12657)
PaperMC/Paper@d61a51e8 Add ItemType#getBurnDuration() (#12604)
PaperMC/Paper@29fc8532 Allow empty paths in namespaced keys (#12687)
PaperMC/Paper@4419afb9 fix: Safely handle nanosecond overflow in ClickCallback (#12686)
PaperMC/Paper@56528821 Add `isProxyEnabled` method to ServerConfiguration (#12664)
PaperMC/Paper@c0dda0ea Add `isForceDefaultGameMode` method (#12673)
PaperMC/Paper@e714de63 Fix excess slot updates
PaperMC/Paper@6d0821d2 [ci/skip] Fix docs for Spawner class and cleanup (#12710)
PaperMC/Paper@cceffe3d Release ItemType and BlockType (#12708)
PaperMC/Paper@186e9e33 Relocate CommandMap#registerServerAliases() call to after lifecycle events have been run (#12601)
PaperMC/Paper@5edcf6dd Cleanup/command dispatching (#12713)

Purpur Changes:
PurpurMC/Purpur@baa196f5 Updated Upstream (Paper)
PurpurMC/Purpur@fdd1e980 Updated Upstream (Paper)
PurpurMC/Purpur@439f15db Updated Upstream (Paper)
PurpurMC/Purpur@46a28b93 [ci/skip] update version in README
PurpurMC/Purpur@162bd288 Updated Upstream (Paper)
PurpurMC/Purpur@afcdf9bb Updated Upstream (Paper)
2025-06-22 13:51:17 +08:00

166 lines
10 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 4200d22606c6a3dbdf282792a4007a51df66963b..4b258f048c73107d0d050a9aa4b4a39788145b17 100644
--- a/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
+++ b/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
@@ -136,7 +136,7 @@ public final class NearbyPlayers {
}
public TrackedChunk getChunk(final ChunkPos pos) {
- return this.byChunk.get(CoordinateUtils.getChunkKey(pos));
+ return this.byChunk.get(pos.longKey); // Leaf - Cache chunk key
}
public TrackedChunk getChunk(final BlockPos pos) {
@@ -152,7 +152,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.longKey); // 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 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..0f5966932c4211922eccac09ab164fcb69dad582 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
@@ -542,7 +542,7 @@ public final class ChunkHolderManager {
public <T> 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.longKey, level, identifier); // Leaf - Cache chunk key
}
public <T> boolean addTicketAtLevel(final TicketType type, final int chunkX, final int chunkZ, final int level,
@@ -689,7 +689,7 @@ public final class ChunkHolderManager {
}
public <T> 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.longKey, level, identifier); // Leaf - Cache chunk key
}
public <T> boolean removeTicketAtLevel(final TicketType type, final int chunkX, final int chunkZ, final int level, final T identifier) {
@@ -1330,7 +1330,7 @@ public final class ChunkHolderManager {
}
public static <T> TicketOperation<T, T> addOp(final ChunkPos chunk, final TicketType type, final int ticketLevel, final T identifier) {
- return addOp(CoordinateUtils.getChunkKey(chunk), type, ticketLevel, identifier);
+ return addOp(chunk.longKey, type, ticketLevel, identifier); // Leaf - Cache chunk key
}
public static <T> TicketOperation<T, T> addOp(final int chunkX, final int chunkZ, final TicketType type, final int ticketLevel, final T identifier) {
@@ -1342,7 +1342,7 @@ public final class ChunkHolderManager {
}
public static <T> TicketOperation<T, T> removeOp(final ChunkPos chunk, final TicketType type, final int ticketLevel, final T identifier) {
- return removeOp(CoordinateUtils.getChunkKey(chunk), type, ticketLevel, identifier);
+ return removeOp(chunk.longKey, type, ticketLevel, identifier); // Leaf - Cache chunk key
}
public static <T> TicketOperation<T, T> 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 51f4dd4f583dfbd16cb00f1cb4418d1044cecb1c..e1812910d7c3941dec3d4f1c90f4cf966a631de3 100644
--- a/ca/spottedleaf/moonrise/patches/starlight/light/StarLightInterface.java
+++ b/ca/spottedleaf/moonrise/patches/starlight/light/StarLightInterface.java
@@ -817,7 +817,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.longKey, (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/DistanceManager.java b/net/minecraft/server/level/DistanceManager.java
index fd3d0f6cb53bc8b6186f0d86575f21007b2c20ed..cddeeab73e7b981701a42c5aad6b47778d46b792 100644
--- a/net/minecraft/server/level/DistanceManager.java
+++ b/net/minecraft/server/level/DistanceManager.java
@@ -178,7 +178,7 @@ public abstract class DistanceManager implements ca.spottedleaf.moonrise.patches
for (int i = 0; i < size; ++i) {
final LevelChunk chunk = raw[i];
- action.accept(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(chunk.getPos()));
+ action.accept(chunk.coordinateKey); // Leaf - Cache chunk key
}
// Paper end - rewrite chunk system
}
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index c5949a0e852ca6de84e8dd12e3d4ed8527b60e25..0f311e603c8df175576a33d5d20369cbcda2be55 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -507,7 +507,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.longKey)) { // Leaf - Cache chunk key
return;
}
@@ -2610,7 +2610,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
public boolean areEntitiesActuallyLoadedAndTicking(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.longKey); // Leaf - Cache chunk key
return chunkHolder != null && chunkHolder.isEntityTickingReady();
// Paper end - rewrite chunk system
}
@@ -2625,7 +2625,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
public boolean canSpawnEntitiesInChunk(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.longKey); // Leaf - Cache chunk key
return chunkHolder != null && chunkHolder.isEntityTickingReady() && this.getWorldBorder().isWithinBounds(chunkPos);
// Paper end - rewrite chunk system
}
diff --git a/net/minecraft/world/level/ChunkPos.java b/net/minecraft/world/level/ChunkPos.java
index 6e2b2d258e47dcca30a5ad9f4f492598f2bc21fb..f9af074e833a6dab96414750314a27b35ec07bfc 100644
--- a/net/minecraft/world/level/ChunkPos.java
+++ b/net/minecraft/world/level/ChunkPos.java
@@ -54,19 +54,19 @@ public class ChunkPos {
public ChunkPos(int x, int y) {
this.x = x;
this.z = y;
- this.longKey = asLong(this.x, this.z); // Paper
+ this.longKey = asLong(this.x, this.z); // Paper // Leaf - Cache chunk key - diff on change
}
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.longKey = asLong(this.x, this.z); // Paper // Leaf - Cache chunk key - diff on change
}
public ChunkPos(long packedPos) {
this.x = (int)packedPos;
this.z = (int)(packedPos >> 32);
- this.longKey = asLong(this.x, this.z); // Paper
+ this.longKey = asLong(this.x, this.z); // Paper // Leaf - Cache chunk key - diff on change
}
public static ChunkPos minFromRegion(int chunkX, int chunkZ) {
@@ -82,7 +82,7 @@ public class ChunkPos {
}
public static long asLong(int x, int z) {
- return x & 4294967295L | (z & 4294967295L) << 32;
+ return x & 4294967295L | (z & 4294967295L) << 32; // Leaf - Cache chunk key - diff on change
}
public static long asLong(BlockPos pos) {