9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-archived-patches/removed/1.21.3/server/0110-Fix-MC-183518.patch
2025-06-29 23:39:55 +08:00

54 lines
2.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Fri, 14 Jun 2024 17:34:17 -0400
Subject: [PATCH] Fix-MC-183518
Removed since Leaf 1.21.3, Mojang fixed in 1.21.2 24w33a
Related MC issue: https://bugs.mojang.com/browse/MC-183518
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 2445d549fbf972620f2cc13860f826562ff3f4d0..9dce5c34f67799285ee395a9c5d0db5ee6319536 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -311,6 +311,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("Leaf Async Mob Spawn Thread"); // Pufferfish - optimize mob spawning // Leaf - Unify thread name
public final Set<Entity> entitiesWithScheduledTasks = java.util.concurrent.ConcurrentHashMap.newKeySet(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run (concurrent because plugins may schedule tasks async)
+ private boolean waitingForNextTick = false; // Leaf - Fix MC-183518
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> atomicreference = new AtomicReference();
@@ -1494,9 +1495,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
protected void waitUntilNextTick() {
long tickOversleepStart = System.nanoTime(); // Gale - YAPFA - last tick time
- this.managedBlock(() -> {
- return !this.canSleepForTickNoOversleep(); // Paper - move oversleep into full server tick
- });
+ // Leaf start - Fix MC-183518
+ this.waitingForNextTick = true;
+ try {
+ this.managedBlock(() -> {
+ return !this.canSleepForTickNoOversleep(); // Paper - move oversleep into full server tick
+ });
+ } finally {
+ this.waitingForNextTick = false;
+ }
+ // Leaf end - Fix MC-183518
lastTickOversleepTime = (System.nanoTime() - tickOversleepStart) / 1000000L; // Gale - YAPFA - last tick time
}
@@ -1505,7 +1513,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
boolean flag = this.isTickTimeLoggingEnabled();
long i = flag ? Util.getNanos() : 0L;
- super.waitForTasks();
+ // Leaf start - Fix MC-183518
+ long ms = this.waitingForNextTick ? this.nextTickTimeNanos - Util.getNanos() : 100_000L;
+ java.util.concurrent.locks.LockSupport.parkNanos("waiting for tasks", ms);
+ // Leaf end - Fix MC-183518
if (flag) {
this.idleTimeNanos += Util.getNanos() - i;
}