mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-30 12:29:13 +00:00
ClassInstanceMultiMap belongs to Minecraft vanilla entity storage. And is unused, since replaced by spottedleaf's entity storage (rewrite chunk system). However these patches might be useful for vanilla entity storage if is used.
130 lines
6.0 KiB
Diff
130 lines
6.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Taiyou06 <kaandindar21@gmail.com>
|
|
Date: Thu, 6 Mar 2025 00:26:19 +0100
|
|
Subject: [PATCH] SparklyPaper: Track each world MSPT
|
|
|
|
Original project: https://github.com/SparklyPower/SparklyPaper
|
|
|
|
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
|
index 15b01ff019e48ce9434b1f538d712601c3fe65c8..f7aa2b84c20791fe6b626a7e1393145b2d0bf206 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -1686,7 +1686,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
// Leaf start - SparklyPaper - parallel world ticking mod (move level ticking logic out for branch convergence)
|
|
private void tickLevel(ServerLevel serverLevel, BooleanSupplier hasTimeLeft) {
|
|
try {
|
|
+ long i = Util.getNanos(); // SparklyPaper - track world's MSPT
|
|
serverLevel.tick(hasTimeLeft);
|
|
+ // SparklyPaper start - track world's MSPT
|
|
+ long j = Util.getNanos() - i;
|
|
+
|
|
+ // These are from the "tickServer" function
|
|
+ serverLevel.tickTimes5s.add(this.tickCount, j);
|
|
+ serverLevel.tickTimes10s.add(this.tickCount, j);
|
|
+ serverLevel.tickTimes60s.add(this.tickCount, j);
|
|
+ // SparklyPaper end - track world's MSPT
|
|
} catch (Throwable levelTickingException) {
|
|
CrashReport crashReport = CrashReport.forThrowable(levelTickingException, "Exception ticking world");
|
|
serverLevel.fillReportDetails(crashReport);
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index 397ac1603c742b82e74cfb5d3e579935d74933a2..56e6691f4fc425f13fe5f1fd40de16f4c54a3195 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -570,6 +570,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
}
|
|
// Paper end - chunk tick iteration
|
|
|
|
+ // SparklyPaper start - track world's MSPT
|
|
+ public final MinecraftServer.TickTimes tickTimes5s = new MinecraftServer.TickTimes(100);
|
|
+ public final MinecraftServer.TickTimes tickTimes10s = new MinecraftServer.TickTimes(200);
|
|
+ public final MinecraftServer.TickTimes tickTimes60s = new MinecraftServer.TickTimes(1200);
|
|
+ // SparklyPaper end - track world's MSPT
|
|
+
|
|
public ServerLevel(
|
|
MinecraftServer server,
|
|
Executor dispatcher,
|
|
diff --git a/org/purpurmc/purpur/task/TPSBarTask.java b/org/purpurmc/purpur/task/TPSBarTask.java
|
|
index 8769993e7ca59da309087051a3cd38fc562c15d1..b65c839e45402c618020c77fe63b89bd19cc7d96 100644
|
|
--- a/org/purpurmc/purpur/task/TPSBarTask.java
|
|
+++ b/org/purpurmc/purpur/task/TPSBarTask.java
|
|
@@ -28,6 +28,44 @@ public class TPSBarTask extends BossBarTask {
|
|
|
|
@Override
|
|
void updateBossBar(BossBar bossbar, Player player) {
|
|
+ // SparklyPaper start - track world's MSPT
|
|
+ if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled) {
|
|
+ // Get player's current world
|
|
+ net.minecraft.server.level.ServerLevel serverLevel = ((org.bukkit.craftbukkit.CraftWorld) player.getWorld()).getHandle();
|
|
+
|
|
+ // Calculate world-specific MSPT and TPS
|
|
+ double worldMspt = calculateWorldMSPT(serverLevel);
|
|
+ double worldTps = Math.min(20.0, 1000.0 / Math.max(worldMspt, 0.001)); // Avoid division by zero
|
|
+
|
|
+ // Store original values
|
|
+ double originalTps = this.tps;
|
|
+ double originalMspt = this.mspt;
|
|
+
|
|
+ try {
|
|
+ // Temporarily set to world values
|
|
+ this.tps = worldTps;
|
|
+ this.mspt = worldMspt;
|
|
+
|
|
+ // Create MSPT component with world name
|
|
+ Component msptWithWorld = Component.empty()
|
|
+ .append(getMSPTColor())
|
|
+ .append(Component.text(" [" + player.getWorld().getName() + "]").color(net.kyori.adventure.text.format.NamedTextColor.GRAY));
|
|
+
|
|
+ // Update the boss bar using the methods that depend on the fields
|
|
+ bossbar.progress(getBossBarProgress());
|
|
+ bossbar.color(getBossBarColor());
|
|
+ bossbar.name(MiniMessage.miniMessage().deserialize(PurpurConfig.commandTPSBarTitle,
|
|
+ Placeholder.component("tps", getTPSColor()),
|
|
+ Placeholder.component("mspt", msptWithWorld),
|
|
+ Placeholder.component("ping", getPingColor(player.getPing()))
|
|
+ ));
|
|
+ } finally {
|
|
+ // Restore original values
|
|
+ this.tps = originalTps;
|
|
+ this.mspt = originalMspt;
|
|
+ }
|
|
+ } else {
|
|
+ // Default behavior
|
|
bossbar.progress(getBossBarProgress());
|
|
bossbar.color(getBossBarColor());
|
|
bossbar.name(MiniMessage.miniMessage().deserialize(PurpurConfig.commandTPSBarTitle,
|
|
@@ -35,6 +73,8 @@ public class TPSBarTask extends BossBarTask {
|
|
Placeholder.component("mspt", getMSPTColor()),
|
|
Placeholder.component("ping", getPingColor(player.getPing()))
|
|
));
|
|
+ }
|
|
+ // SparklyPaper end - track world's MSPT
|
|
}
|
|
|
|
@Override
|
|
@@ -136,6 +176,25 @@ public class TPSBarTask extends BossBarTask {
|
|
return MiniMessage.miniMessage().deserialize(color, Placeholder.parsed("text", String.format("%s", ping)));
|
|
}
|
|
|
|
+ // SparklyPaper start - track world's MSPT
|
|
+ private double calculateWorldMSPT(net.minecraft.server.level.ServerLevel serverLevel) {
|
|
+ long[] times = serverLevel.tickTimes5s.getTimes();
|
|
+ long total = 0L;
|
|
+ int count = 0;
|
|
+
|
|
+ for (long value : times) {
|
|
+ if (value > 0L) {
|
|
+ total += value;
|
|
+ count++;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (count == 0) return 0.0;
|
|
+
|
|
+ return (double) total / (double) count * 1.0E-6D;
|
|
+ }
|
|
+ // SparklyPaper end - track world's MSPT
|
|
+
|
|
public enum FillMode {
|
|
TPS, MSPT, PING
|
|
}
|