mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-06 15:51:31 +00:00
Fix
This commit is contained in:
@@ -23,7 +23,7 @@ But it is still recommending to use those packet based, virtual entity
|
||||
based NPC plugins, e.g. ZNPC Plus, Adyeshach, Fancy NPC, etc.
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
||||
index e42677bb004201efe1702779a78cc8d0ca05e80f..3fa04bad6f5263c626c22ef0a795947391e1e710 100644
|
||||
index e42677bb004201efe1702779a78cc8d0ca05e80f..6676be8304e9415099ed423d3315180cafebd928 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
||||
@@ -42,6 +42,12 @@ class PaperEventManager {
|
||||
@@ -31,7 +31,7 @@ index e42677bb004201efe1702779a78cc8d0ca05e80f..3fa04bad6f5263c626c22ef0a7959473
|
||||
throw new IllegalStateException(event.getEventName() + " may only be triggered asynchronously.");
|
||||
} else if (!event.isAsynchronous() && !this.server.isPrimaryThread() && !this.server.isStopping()) {
|
||||
+ // Leaf start - Multithreaded tracker
|
||||
+ if (org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled && Thread.currentThread() instanceof org.dreeam.leaf.async.tracker.MultithreadedTracker.MultithreadedTrackerThread) {
|
||||
+ if (org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled) {
|
||||
+ net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(event::callEvent);
|
||||
+ return;
|
||||
+ }
|
||||
|
||||
@@ -7,7 +7,7 @@ This patch was ported from project: https://github.com/snackbag/TT20
|
||||
Project license: AGPL-3.0
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 09e55f62b4cea5b058e04356252f4f56957646b8..279289e0c3dc65fed0ee4b2f5b0ef077ab433d5e 100644
|
||||
index 37c377761b45eefab39164a7e714e585a02a4447..f268001f7a821ad1d0db8a02de19e80cc951d0fd 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -1628,6 +1628,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -19,7 +19,7 @@ index 11b7f15755dde766140c29bedca456c80d53293f..749d00449ac3f3c79bfc73a5517ea3a0
|
||||
this.id = id;
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
||||
index 3fa04bad6f5263c626c22ef0a795947391e1e710..411bc27324c34e4cad1849512a4531214d7fe9d2 100644
|
||||
index 6676be8304e9415099ed423d3315180cafebd928..30b56382e9574004e344c1c8289d7dcbb177386b 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
||||
@@ -48,6 +48,12 @@ class PaperEventManager {
|
||||
@@ -27,7 +27,7 @@ index 3fa04bad6f5263c626c22ef0a795947391e1e710..411bc27324c34e4cad1849512a453121
|
||||
}
|
||||
// Leaf end - Multithreaded tracker
|
||||
+ // Leaf start - Async locator
|
||||
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && Thread.currentThread() instanceof org.dreeam.leaf.async.locate.AsyncLocator.AsyncLocatorThread) {
|
||||
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled) {
|
||||
+ net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(event::callEvent);
|
||||
+ return;
|
||||
+ }
|
||||
@@ -5,10 +5,10 @@ Subject: [PATCH] Virtual thread for chat executor
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 37c377761b45eefab39164a7e714e585a02a4447..09e55f62b4cea5b058e04356252f4f56957646b8 100644
|
||||
index f268001f7a821ad1d0db8a02de19e80cc951d0fd..279289e0c3dc65fed0ee4b2f5b0ef077ab433d5e 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -2894,7 +2894,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -2900,7 +2900,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
}
|
||||
|
||||
public final java.util.concurrent.ExecutorService chatExecutor = java.util.concurrent.Executors.newCachedThreadPool(
|
||||
@@ -1,216 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Mon, 1 Nov 2077 00:00:00 +0800
|
||||
Subject: [PATCH] TT20 Lag compensation
|
||||
|
||||
This patch was ported from project: https://github.com/snackbag/TT20
|
||||
Project license: AGPL-3.0
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 09e55f62b4cea5b058e04356252f4f56957646b8..279289e0c3dc65fed0ee4b2f5b0ef077ab433d5e 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -1628,6 +1628,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
this.server.spark.tickStart(); // Paper - spark
|
||||
new com.destroystokyo.paper.event.server.ServerTickStartEvent(this.tickCount+1).callEvent(); // Paper - Server Tick Events
|
||||
|
||||
+ // Leaf start - Lag compensation tick hook
|
||||
+ if (org.dreeam.leaf.config.modules.misc.LagCompensation.enabled) {
|
||||
+ org.dreeam.leaf.misc.LagCompensation.TPSCalculator.onTick();
|
||||
+ }
|
||||
+ // Leaf end - Lag Compensation tick hook
|
||||
+
|
||||
++this.tickCount;
|
||||
this.tickRateManager.tick();
|
||||
this.tickChildren(shouldKeepTicking);
|
||||
diff --git a/src/main/java/net/minecraft/world/level/material/LavaFluid.java b/src/main/java/net/minecraft/world/level/material/LavaFluid.java
|
||||
index 2d492d849ff73a738dfbcb16507feb89bf19a962..0e70f0b88d67c2da4094fd73998d1bddf835b724 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/material/LavaFluid.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/material/LavaFluid.java
|
||||
@@ -180,7 +180,13 @@ public abstract class LavaFluid extends FlowingFluid {
|
||||
|
||||
@Override
|
||||
public int getTickDelay(LevelReader world) {
|
||||
- return world.dimensionType().ultraWarm() ? world.getWorldBorder().world.purpurConfig.lavaSpeedNether : world.getWorldBorder().world.purpurConfig.lavaSpeedNotNether; // Purpur
|
||||
+ // Leaf start - Lag compensation
|
||||
+ if (org.dreeam.leaf.config.modules.misc.LagCompensation.enabled && org.dreeam.leaf.config.modules.misc.LagCompensation.enableForLava) {
|
||||
+ return world.dimensionType().ultraWarm() ? org.dreeam.leaf.misc.LagCompensation.tt20(world.getWorldBorder().world.purpurConfig.lavaSpeedNether, true) : org.dreeam.leaf.misc.LagCompensation.tt20(world.getWorldBorder().world.purpurConfig.lavaSpeedNotNether, true); // Purpur // Leaf
|
||||
+ } else {
|
||||
+ return world.dimensionType().ultraWarm() ? world.getWorldBorder().world.purpurConfig.lavaSpeedNether : world.getWorldBorder().world.purpurConfig.lavaSpeedNotNether; // Purpur
|
||||
+ }
|
||||
+ // Leaf end - Lag compensation
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/net/minecraft/world/level/material/WaterFluid.java b/src/main/java/net/minecraft/world/level/material/WaterFluid.java
|
||||
index 9dcdb2f4001115db0c26fdbf86531dbe6098485d..53a28a4026c50a66e53241ffe660b4d72600db39 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/material/WaterFluid.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/material/WaterFluid.java
|
||||
@@ -122,7 +122,13 @@ public abstract class WaterFluid extends FlowingFluid {
|
||||
|
||||
@Override
|
||||
public int getTickDelay(LevelReader world) {
|
||||
- return 5;
|
||||
+ // Leaf start - Lag compensation
|
||||
+ if (org.dreeam.leaf.config.modules.misc.LagCompensation.enabled && org.dreeam.leaf.config.modules.misc.LagCompensation.enableForWater) {
|
||||
+ return org.dreeam.leaf.misc.LagCompensation.tt20(5, true);
|
||||
+ } else {
|
||||
+ return 5;
|
||||
+ }
|
||||
+ // Leaf end - Lag compensation
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/LagCompensation.java b/src/main/java/org/dreeam/leaf/config/modules/misc/LagCompensation.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..d90ab4cb8c69318f8bf77af12e2840fb5d519931
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/LagCompensation.java
|
||||
@@ -0,0 +1,26 @@
|
||||
+package org.dreeam.leaf.config.modules.misc;
|
||||
+
|
||||
+import org.dreeam.leaf.config.ConfigModules;
|
||||
+import org.dreeam.leaf.config.EnumConfigCategory;
|
||||
+
|
||||
+public class LagCompensation extends ConfigModules {
|
||||
+
|
||||
+ public String getBasePath() {
|
||||
+ return EnumConfigCategory.MISC.getBaseKeyName() + ".lag-compensation";
|
||||
+ }
|
||||
+
|
||||
+ public static boolean enabled = false;
|
||||
+ public static boolean enableForWater = false;
|
||||
+ public static boolean enableForLava = false;
|
||||
+
|
||||
+ @Override
|
||||
+ public void onLoaded() {
|
||||
+ config.addComment(getBasePath(), """
|
||||
+ This section contains lag compensation features,
|
||||
+ which could ensure basic playing experience during a lag.""");
|
||||
+
|
||||
+ enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
|
||||
+ enableForWater = config.getBoolean(getBasePath() + ".enable-for-water", enableForWater);
|
||||
+ enableForLava = config.getBoolean(getBasePath() + ".enable-for-lava", enableForLava);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/dreeam/leaf/misc/LagCompensation.java b/src/main/java/org/dreeam/leaf/misc/LagCompensation.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..6ec73caf7163ed0a66fc2dfec781e190163d06b8
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/misc/LagCompensation.java
|
||||
@@ -0,0 +1,114 @@
|
||||
+package org.dreeam.leaf.misc;
|
||||
+
|
||||
+import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
|
||||
+
|
||||
+import java.util.Collections;
|
||||
+import java.util.List;
|
||||
+
|
||||
+public class LagCompensation {
|
||||
+
|
||||
+ public static float tt20(float ticks, boolean limitZero) {
|
||||
+ float newTicks = (float) rawTT20(ticks);
|
||||
+
|
||||
+ if (limitZero) return newTicks > 0 ? newTicks : 1;
|
||||
+ else return newTicks;
|
||||
+ }
|
||||
+
|
||||
+ public static int tt20(int ticks, boolean limitZero) {
|
||||
+ int newTicks = (int) Math.ceil(rawTT20(ticks));
|
||||
+
|
||||
+ if (limitZero) return newTicks > 0 ? newTicks : 1;
|
||||
+ else return newTicks;
|
||||
+ }
|
||||
+
|
||||
+ public static double tt20(double ticks, boolean limitZero) {
|
||||
+ double newTicks = rawTT20(ticks);
|
||||
+
|
||||
+ if (limitZero) return newTicks > 0 ? newTicks : 1;
|
||||
+ else return newTicks;
|
||||
+ }
|
||||
+
|
||||
+ public static double rawTT20(double ticks) {
|
||||
+ return ticks == 0 ? 0 : ticks * TPSCalculator.getMostAccurateTPS() / TPSCalculator.MAX_TPS;
|
||||
+ }
|
||||
+
|
||||
+ public static class TPSCalculator {
|
||||
+ public static Long lastTick;
|
||||
+ public static Long currentTick;
|
||||
+ private static double allMissedTicks = 0;
|
||||
+ private static final List<Double> tpsHistory = Collections.synchronizedList(new DoubleArrayList());
|
||||
+ private static final int historyLimit = 40;
|
||||
+
|
||||
+ public static final int MAX_TPS = 20;
|
||||
+ public static final int FULL_TICK = 50;
|
||||
+
|
||||
+ private TPSCalculator() {}
|
||||
+
|
||||
+ public static void onTick() {
|
||||
+ if (currentTick != null) {
|
||||
+ lastTick = currentTick;
|
||||
+ }
|
||||
+
|
||||
+ currentTick = System.currentTimeMillis();
|
||||
+ addToHistory(getTPS());
|
||||
+ clearMissedTicks();
|
||||
+ missedTick();
|
||||
+ }
|
||||
+
|
||||
+ private static void addToHistory(double tps) {
|
||||
+ if (tpsHistory.size() >= historyLimit) {
|
||||
+ tpsHistory.removeFirst();
|
||||
+ }
|
||||
+
|
||||
+ tpsHistory.add(tps);
|
||||
+ }
|
||||
+
|
||||
+ public static long getMSPT() {
|
||||
+ return currentTick - lastTick;
|
||||
+ }
|
||||
+
|
||||
+ public static double getAverageTPS() {
|
||||
+ double sum = 0.0;
|
||||
+ for (double value : tpsHistory) {
|
||||
+ sum += value;
|
||||
+ }
|
||||
+ return tpsHistory.isEmpty() ? 0.1 : sum / tpsHistory.size();
|
||||
+ }
|
||||
+
|
||||
+ public static double getTPS() {
|
||||
+ if (lastTick == null) return -1;
|
||||
+ if (getMSPT() <= 0) return 0.1;
|
||||
+
|
||||
+ double tps = 1000 / (double) getMSPT();
|
||||
+ return tps > MAX_TPS ? MAX_TPS : tps;
|
||||
+ }
|
||||
+
|
||||
+ public static void missedTick() {
|
||||
+ if (lastTick == null) return;
|
||||
+
|
||||
+ long mspt = getMSPT() <= 0 ? 50 : getMSPT();
|
||||
+ double missedTicks = (mspt / (double) FULL_TICK) - 1;
|
||||
+ allMissedTicks += missedTicks <= 0 ? 0 : missedTicks;
|
||||
+ }
|
||||
+
|
||||
+ public static double getMostAccurateTPS() {
|
||||
+ return Math.min(getTPS(), getAverageTPS());
|
||||
+ }
|
||||
+
|
||||
+ public double getAllMissedTicks() {
|
||||
+ return allMissedTicks;
|
||||
+ }
|
||||
+
|
||||
+ public static int applicableMissedTicks() {
|
||||
+ return (int) Math.floor(allMissedTicks);
|
||||
+ }
|
||||
+
|
||||
+ public static void clearMissedTicks() {
|
||||
+ allMissedTicks -= applicableMissedTicks();
|
||||
+ }
|
||||
+
|
||||
+ public void resetMissedTicks() {
|
||||
+ allMissedTicks = 0;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
Reference in New Issue
Block a user