9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-06 15:51:31 +00:00

fix sent chunks data race

This commit is contained in:
hayanesuru
2025-08-15 05:36:10 +09:00
parent 66ddf9f50c
commit de0e0f98a0
3 changed files with 326 additions and 700 deletions

View File

@@ -98,7 +98,7 @@ index 1b8193587814225c2ef2c5d9e667436eb50ff6c5..2a2626e90836ae52a8a686b2040843c6
if (list == null) {
throw new IllegalStateException("Does not contain player " + player);
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
index bdc1200ef5317fdaf58973bf580b0a672aee800f..20b1186f53c267f69ed7852f5cf3dd2460f8200d 100644
index bdc1200ef5317fdaf58973bf580b0a672aee800f..e36086cd3c205e66ba1028343028af2239c1d93f 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
@@ -344,7 +344,7 @@ public final class RegionizedPlayerChunkLoader {
@@ -106,7 +106,7 @@ index bdc1200ef5317fdaf58973bf580b0a672aee800f..20b1186f53c267f69ed7852f5cf3dd24
private final ArrayDeque<ChunkHolderManager.TicketOperation<?, ?>> delayedTicketOps = new ArrayDeque<>();
- private final LongOpenHashSet sentChunks = new LongOpenHashSet();
+ private final LongOpenHashSet sentChunks = org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled ? new org.dreeam.leaf.util.map.ConcurrentLongHashSet() : new LongOpenHashSet(); // Leaf - Multithreaded tracker
+ private final LongOpenHashSet sentChunks = org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled ? new org.dreeam.leaf.util.map.SyncLongOpenHashSet() : new LongOpenHashSet(); // Leaf - Multithreaded tracker
private static final byte CHUNK_TICKET_STAGE_NONE = 0;
private static final byte CHUNK_TICKET_STAGE_LOADING = 1;
@@ -125,6 +125,36 @@ index bdc1200ef5317fdaf58973bf580b0a672aee800f..20b1186f53c267f69ed7852f5cf3dd24
return;
}
throw new IllegalStateException();
diff --git a/io/papermc/paper/FeatureHooks.java b/io/papermc/paper/FeatureHooks.java
index df6fbb35e5023b42de0b97434712e04a6b3e66a3..83b29ec533158cc04cc1bab1fe96c1235778a2cd 100644
--- a/io/papermc/paper/FeatureHooks.java
+++ b/io/papermc/paper/FeatureHooks.java
@@ -85,10 +85,22 @@ public final class FeatureHooks {
final LongOpenHashSet rawChunkKeys = player.moonrise$getChunkLoader().getSentChunksRaw();
final ObjectSet<org.bukkit.Chunk> chunks = new ObjectOpenHashSet<>(rawChunkKeys.size());
final World world = player.level().getWorld();
- final LongIterator iter = player.moonrise$getChunkLoader().getSentChunksRaw().longIterator();
- while (iter.hasNext()) {
- chunks.add(world.getChunkAt(iter.nextLong(), false));
+ // Leaf start - Multithreaded tracker
+ if (org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled) {
+ final LongOpenHashSet set = player.moonrise$getChunkLoader().getSentChunksRaw();
+ synchronized (set) {
+ final LongIterator iter = set.longIterator();
+ while (iter.hasNext()) {
+ chunks.add(world.getChunkAt(iter.nextLong(), false));
+ }
+ }
+ } else {
+ final LongIterator iter = player.moonrise$getChunkLoader().getSentChunksRaw().longIterator();
+ while (iter.hasNext()) {
+ chunks.add(world.getChunkAt(iter.nextLong(), false));
+ }
}
+ // Leaf end - Multithreaded tracker
// Paper end - rewrite chunk system
return ObjectSets.unmodifiable(chunks);
}
diff --git a/net/minecraft/network/protocol/game/ClientboundUpdateAttributesPacket.java b/net/minecraft/network/protocol/game/ClientboundUpdateAttributesPacket.java
index 9c0c99b936b4a82ebfe924866e53ec71f7bbe9ad..2ccff968cb2065d34fad4d27573f9e3081edb2f2 100644
--- a/net/minecraft/network/protocol/game/ClientboundUpdateAttributesPacket.java