Fix some issues around folia

This commit is contained in:
MrHua269
2025-05-25 23:07:06 +08:00
parent 4240ffc3b9
commit 71ebc63ee2
2 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <mrhua269@gmail.com>
Date: Sun, 25 May 2025 23:01:35 +0800
Subject: [PATCH] Fix forgotten chunk pos shift
Fixes: https://github.com/PaperMC/Folia/issues/364
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index 12647b44edf4794dfba0fe997c3b45555d7bdcb5..0b8b9a864b27997436cf598a61eed97dff9ac1dd 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -2371,11 +2371,11 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
Optional<Holder<PoiType>> optional1 = PoiTypes.forState(newState);
if (!Objects.equals(optional, optional1)) {
BlockPos blockPos = pos.immutable();
- optional.ifPresent(holder -> io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueChunkTask(this, blockPos.getX(), blockPos.getZ(), () -> { // Folia - region threading
+ optional.ifPresent(holder -> io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueChunkTask(this, blockPos.getX() >> 4, blockPos.getZ() >> 4, () -> { // Folia - region threading // Luminol - Fix forgotten chunk pos shift
this.getPoiManager().remove(blockPos);
DebugPackets.sendPoiRemovedPacket(this, blockPos);
}));
- optional1.ifPresent(holder -> io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueChunkTask(this, blockPos.getX(), blockPos.getZ(), () -> { // Folia - region threading
+ optional1.ifPresent(holder -> io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueChunkTask(this, blockPos.getX() >> 4, blockPos.getZ() >> 4, () -> { // Folia - region threading // Luminol - Fix forgotten chunk pos shift
// Paper start - Remove stale POIs
if (optional.isEmpty() && this.getPoiManager().exists(blockPos, ignored -> true)) {
this.getPoiManager().remove(blockPos);

View File

@@ -0,0 +1,29 @@
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 6dc5b1a8bdba998e11bcdf352bcc0fc7161a484c..753b36a7b1c2627540c62bea78565b880803a175 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -173,10 +173,14 @@ 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);
+ 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);
+ world.tickChunk(rawCopy[i], randomTickSpeed); // Luminol - Fix chunk iteration self modification - use copy of raw array
// call mid-tick tasks for chunk system
if ((i & 7) == 0) {