mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 08:59:23 +00:00
84 lines
3.6 KiB
Diff
84 lines
3.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: wangxyper <wangxyper@163.com>
|
|
Date: Sun, 22 Jan 2023 13:32:24 +0800
|
|
Subject: [PATCH] Hearse: Fix a threading issue and ingore an error
|
|
|
|
Original license: MIT
|
|
Original project: https://github.com/Era4FunMC/Hearse
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java b/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java
|
|
index d9cee42da1b097590e627142d3c5dccbc180b5ae..23c32a06dce8f0c45647c3619c98ba95290cfa7d 100644
|
|
--- a/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java
|
|
+++ b/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java
|
|
@@ -518,6 +518,7 @@ public final class PlayerChunkLoader {
|
|
protected static final AtomicInteger concurrentChunkSends = new AtomicInteger();
|
|
protected final Reference2IntOpenHashMap<PlayerLoaderData> sendingChunkCounts = new Reference2IntOpenHashMap<>();
|
|
private static long nextChunkSend;
|
|
+
|
|
private void trySendChunks() {
|
|
final long time = System.nanoTime();
|
|
if (time < nextChunkSend) {
|
|
@@ -560,7 +561,7 @@ public final class PlayerChunkLoader {
|
|
}
|
|
|
|
if (!this.isChunkPlayerLoaded(queuedSend.chunkX, queuedSend.chunkZ)) {
|
|
- throw new IllegalStateException();
|
|
+ continue;
|
|
}
|
|
|
|
data.nextChunkSendTarget = nextPlayerDeadline;
|
|
@@ -722,12 +723,13 @@ public final class PlayerChunkLoader {
|
|
}
|
|
}
|
|
|
|
+
|
|
public void tickMidTick() {
|
|
- // try to send more chunks
|
|
- this.trySendChunks();
|
|
+ // try to send more chunks
|
|
+ this.trySendChunks();
|
|
|
|
- // try to queue more chunks to load
|
|
- this.tryLoadChunks();
|
|
+ // try to queue more chunks to load
|
|
+ this.tryLoadChunks();
|
|
}
|
|
|
|
static final class ChunkPriorityHolder {
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
index becac3c1087c77b289c3b0a721c4146bea046e51..2caa5ab3a7b4bf0c535863f5ff54fcb8c0dc3c59 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
@@ -937,6 +937,8 @@ public class ServerChunkCache extends ChunkSource {
|
|
this.spawnFriendlies = spawnAnimals;
|
|
}
|
|
|
|
+ private final Object pollTaskLock = new Object();
|
|
+
|
|
public String getChunkDebugData(ChunkPos pos) {
|
|
return this.chunkMap.getChunkDebugData(pos);
|
|
}
|
|
@@ -963,6 +965,7 @@ public class ServerChunkCache extends ChunkSource {
|
|
this.distanceManager.removeTicketsOnClosing();
|
|
}
|
|
|
|
+
|
|
public final class MainThreadExecutor extends BlockableEventLoop<Runnable> {
|
|
|
|
MainThreadExecutor(Level world) {
|
|
@@ -998,9 +1001,11 @@ public class ServerChunkCache extends ChunkSource {
|
|
@Override
|
|
// CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task
|
|
public boolean pollTask() {
|
|
- ServerChunkCache.this.chunkMap.playerChunkManager.tickMidTick();
|
|
- if (ServerChunkCache.this.runDistanceManagerUpdates()) {
|
|
- return true;
|
|
+ synchronized (ServerChunkCache.this.pollTaskLock){
|
|
+ ServerChunkCache.this.chunkMap.playerChunkManager.tickMidTick();
|
|
+ if (ServerChunkCache.this.runDistanceManagerUpdates()) {
|
|
+ return true;
|
|
+ }
|
|
}
|
|
return super.pollTask() | ServerChunkCache.this.level.chunkTaskScheduler.executeMainThreadTask(); // Paper - rewrite chunk system
|
|
}
|