43 lines
2.8 KiB
Diff
43 lines
2.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrHua269 <mrhua269@gmail.com>
|
|
Date: Sun, 25 May 2025 23:05:15 +0800
|
|
Subject: [PATCH] Fix chunk iteration self modification
|
|
|
|
We use the old-like logics which is in 1.21.4.
|
|
Might fixes: https://github.com/PaperMC/Folia/issues/363
|
|
|
|
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
|
index f8322334fb6a0cea38c4d1981862ba673fd1b100..0e08512ce94435ca90a2344eefc761fa4fcdeb18 100644
|
|
--- a/net/minecraft/server/level/ServerChunkCache.java
|
|
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
|
@@ -173,14 +173,26 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
|
// 2. _removes_ are impossible at this stage in the tick
|
|
final LevelChunk[] raw = entityTickingChunks.getRawDataUnchecked();
|
|
final int size = entityTickingChunks.size(); foliaProfiler.addCounter(ca.spottedleaf.leafprofiler.LProfilerRegistry.RANDOM_CHUNK_TICK_COUNT, (long)size); // Folia - profiler
|
|
+ // Luminol start - Fix chunk iteration self modification - use copy of raw array
|
|
+ final LevelChunk[] rawCopy = new LevelChunk[size];
|
|
+ System.arraycopy(raw, 0, rawCopy, 0, size);
|
|
+ // Luminol end
|
|
|
|
- java.util.Objects.checkFromToIndex(0, size, raw.length);
|
|
+ this.level.getServer().moonrise$executeMidTickTasks(); // Luminol - Fix chunk iteration self modification - try executing mid-tick tasks for once chunk system task parsing
|
|
+ java.util.Objects.checkFromToIndex(0, size, rawCopy.length); // Luminol - Fix chunk iteration self modification - use copy of raw array
|
|
for (int i = 0; i < size; ++i) {
|
|
- world.tickChunk(raw[i], randomTickSpeed);
|
|
+ // Luminol start - Fix chunk iteration self modification
|
|
+ final LevelChunk chunk = rawCopy[i];
|
|
+
|
|
+ if (!chunk.getFullStatus().isOrAfter(FullChunkStatus.ENTITY_TICKING)) {
|
|
+ continue; // skip chunks which are not entity ticking(probably downgraded from last iteration)
|
|
+ }
|
|
+ // Luminol end
|
|
+ world.tickChunk(chunk, randomTickSpeed); // Luminol - Fix chunk iteration self modification - use copy of raw array
|
|
|
|
// call mid-tick tasks for chunk system
|
|
if ((i & 7) == 0) {
|
|
- //((ca.spottedleaf.moonrise.patches.chunk_system.server.ChunkSystemMinecraftServer)this.level.getServer()).moonrise$executeMidTickTasks(); // Folia - TODO restore this
|
|
+ ((ca.spottedleaf.moonrise.patches.chunk_system.server.ChunkSystemMinecraftServer)this.level.getServer()).moonrise$executeMidTickTasks(); // Folia - TODO restore this // Luminol - Fix chunk iteration self modification - restore mid tasks here
|
|
continue;
|
|
}
|
|
}
|