From 744dcd73cd839ed6e80e2ef307d80e818ba4c8c0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 16:24:38 +0000 Subject: [PATCH] Fix TPS calculation: clamp values above 20 instead of discarding them The old code filtered out any instantaneous TPS sample > 20 with `if (tps <= 20 && tps > 0)`. Because time-update packets arrive with OS/network jitter, many measurements on a healthy server land slightly above 20.0 and were silently discarded, leaving only sub-20 samples in the rolling average. This caused the reported TPS to be virtually always lower than the true server TPS. A Minecraft server cannot genuinely run faster than 20 TPS (it sleeps for the remainder of each 50 ms tick budget), so any measurement above 20 is definitionally timing noise. Clamp to Math.Min(tps, 20.0) instead of discarding the sample so a healthy server's rolling average converges to 20.0 as expected. Agent-Logs-Url: https://github.com/MCCTeam/Minecraft-Console-Client/sessions/826926c5-78fa-4059-ab8f-4abd209f120d Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com> --- MinecraftClient/McClient.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index ae5e427b..0eef1c6a 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -3912,11 +3912,15 @@ namespace MinecraftClient { DateTime currentTime = DateTime.Now; long tickDiff = WorldAge - lastAge; - Double tps = tickDiff / (currentTime - lastTime).TotalSeconds; + double tps = tickDiff / (currentTime - lastTime).TotalSeconds; lastAge = WorldAge; lastTime = currentTime; - if (tps <= 20 && tps > 0) + if (tps > 0) { + // A Minecraft server cannot genuinely exceed 20 TPS; values above 20 are + // caused by packet-timing jitter. Clamp instead of discarding so that a + // healthy server averages to 20 rather than being biased downward. + tps = Math.Min(tps, 20.0); // calculate average tps if (tpsSamples.Count >= maxSamples) {