TPS Update
build / build (push) Successful in 4m10s

This commit is contained in:
ciomek committed 2026-08-19 23:18:55 +02:00
1 parent e331902f6f
commit 998d598fa3
3 files changed
+53 -1

No files matched your search

@@ -11,6 +11,11 @@ public class TPSTracker {
return tps;
}
public static double getTPSRounded()
{
return Math.round(tps * 10.0) / 10.0;
}
public static void setTPS(double tps)
{
TPSTracker.tps = tps;
@@ -2,6 +2,7 @@ package ciomek.loon.mixin;
import ciomek.loon.Loon;
import ciomek.loon.TPSTracker;
import ciomek.loon.mqtt.payload.ServerInfoPayload;
import ciomek.loon.mqtt.payload.data.PlayerIdentity;
import ciomek.loon.mqtt.payload.data.PositionData;
import ciomek.loon.mqtt.payload.player.PlayerPositionPayload;
@@ -29,6 +30,9 @@ public class WorldServerMixin {
@Unique
private static final int POSITION_CHECK_INTERVAL_TICKS = 20;
@Unique
private static final int TPS_CHECK_INTERVAL_TICKS = 20;
@Shadow
public MinecraftServer mcServer;
@@ -47,6 +51,12 @@ public class WorldServerMixin {
@Unique
private static int positionCheckTicks;
@Unique
private static int tpsCheckTicks;
@Unique
private static double lastTPS = 0;
@Unique
private static final Map<UUID, PositionData> lastSentPositions = new HashMap<>();
@@ -54,6 +64,7 @@ public class WorldServerMixin {
private void onTick(CallbackInfo ci) {
countTicks();
positionCountdown();
tpsCountdown();
handleRequests();
}
@@ -100,6 +111,42 @@ public class WorldServerMixin {
}
}
@Unique private void tpsCountdown()
{
if (++tpsCheckTicks >= TPS_CHECK_INTERVAL_TICKS) {
tpsCheckTicks = 0;
double currentTPS = TPSTracker.getTPSRounded();
if (Math.round(lastTPS * 10) != currentTPS * 10) {
lastTPS = currentTPS;
WorldServer world = (WorldServer) (Object) this;
MinecraftServer server = world.mcServer;
String domain = System.getenv(Loon.EnvVarPrefix + "DOMAIN");
if (domain == null) {
domain = "";
}
ServerInfoPayload payload = new ServerInfoPayload(
TPSTracker.getTPSRounded(),
server.getMinecraftVersion(),
domain,
server.motd,
server.onlineMode,
server.sleepPercentage,
server.playerList.playerEntities.size(),
server.maxPlayers,
server.difficulty,
server.pvpOn,
server.viewDistance);
payload.send();
}
}
}
@Unique private void handleRequests()
{
IRequest request;
@@ -15,7 +15,7 @@ public record ServerInfoRequest() implements IRequest {
}
ServerInfoPayload payload = new ServerInfoPayload(
TPSTracker.getTPS(),
TPSTracker.getTPSRounded(),
server.getMinecraftVersion(),
domain,
server.motd,