Minecraft client: query server TPS?

an
- in Worlds
4

How do you do that?

Have read that the server sends a SPacketTimeUpdate packet every tick, and you could derive the TPS from it. But how? How do I see when I received such a package and how can I derive the TPS from it? Or is there another way? Per getTotalWorldTime or something? Who knows how to do it?

Lo

The SPacketTimeUpdate has two fields:

Age of the world in ticks
Time of day in ticks

I think the 1st would be more appropriate. The method to derive the TPS from this is very simple, but I have not tested it.

private long lastTime;
private long lastAge = -1L;

@PacketReceive
public void onTimeUpdate (SPacketTimeUpdate packet) {
long age = packet.worldAge;
long time = System.currentTimeMillis ();

if (lastAge == -1L) {
lastTime = time;
lastAge = age;
return;
}

long diffAge = age - lastAge;
long diffTime = time - lastTime;

lastAge = age;
lastTime = time;

long tps = diffAge / (diffTime / 1000.0);
long tpsRounded = Math.round (tps * 100) / 100.0;

System.out.println ("TPS:" + tpsRounded);
}

I came up with the method and annotations myself, the implementation is entirely up to you. You could do this even more precisely if you include the ping.

Lo

Of course it should

double tps
double tpsRounded

an

The @PacketReceive is painted red. There's no such thing.

SPacketTimeUpdate also not. : /

(1.8, MCP)

Lo

As already written:

I came up with the method and annotations myself, the implementation is entirely up to you.