1 parent
859d901d9a
commit
ba9070eddd
1 file changed
+45
-25
@@ -1,5 +1,6 @@
|
|||||||
package ciomek.loon.mixin;
|
package ciomek.loon.mixin;
|
||||||
|
|
||||||
|
import ciomek.loon.Loon;
|
||||||
import ciomek.loon.TPSTracker;
|
import ciomek.loon.TPSTracker;
|
||||||
import ciomek.loon.mqtt.payload.data.PlayerIdentity;
|
import ciomek.loon.mqtt.payload.data.PlayerIdentity;
|
||||||
import ciomek.loon.mqtt.payload.data.PositionData;
|
import ciomek.loon.mqtt.payload.data.PositionData;
|
||||||
@@ -51,31 +52,9 @@ public class WorldServerMixin {
|
|||||||
|
|
||||||
@Inject(method = "tick", at = @At("TAIL"))
|
@Inject(method = "tick", at = @At("TAIL"))
|
||||||
private void onTick(CallbackInfo ci) {
|
private void onTick(CallbackInfo ci) {
|
||||||
WorldServer self = (WorldServer) (Object) this;
|
countTicks();
|
||||||
if (self.dimension == Dimension.OVERWORLD) {
|
positionCountdown();
|
||||||
long now = System.nanoTime();
|
handleRequests();
|
||||||
if (lastTickNanos != 0) {
|
|
||||||
gapSumNanos += now - lastTickNanos;
|
|
||||||
gapTicks++;
|
|
||||||
if (gapSumNanos >= 1_000_000_000L) {
|
|
||||||
TPSTracker.setTPS(Math.min(20.0, gapTicks / (gapSumNanos / 1e9)));
|
|
||||||
gapSumNanos = 0;
|
|
||||||
gapTicks = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lastTickNanos = now;
|
|
||||||
|
|
||||||
if (++positionCheckTicks >= POSITION_CHECK_INTERVAL_TICKS) {
|
|
||||||
positionCheckTicks = 0;
|
|
||||||
broadcastMovedPlayerPositions();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IRequest request;
|
|
||||||
while ((request = RequestManager.pollRequest()) != null) {
|
|
||||||
IRequest current = request;
|
|
||||||
EXECUTOR.submit(() -> current.handle(mcServer));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
@@ -94,4 +73,45 @@ public class WorldServerMixin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Unique private void countTicks()
|
||||||
|
{
|
||||||
|
WorldServer self = (WorldServer) (Object) this;
|
||||||
|
if (self.dimension == Dimension.OVERWORLD) {
|
||||||
|
long now = System.nanoTime();
|
||||||
|
if (lastTickNanos != 0) {
|
||||||
|
gapSumNanos += now - lastTickNanos;
|
||||||
|
gapTicks++;
|
||||||
|
if (gapSumNanos >= 1_000_000_000L) {
|
||||||
|
TPSTracker.setTPS(Math.min(20.0, gapTicks / (gapSumNanos / 1e9)));
|
||||||
|
gapSumNanos = 0;
|
||||||
|
gapTicks = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastTickNanos = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique private void positionCountdown()
|
||||||
|
{
|
||||||
|
if (++positionCheckTicks >= POSITION_CHECK_INTERVAL_TICKS) {
|
||||||
|
positionCheckTicks = 0;
|
||||||
|
broadcastMovedPlayerPositions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique private void handleRequests()
|
||||||
|
{
|
||||||
|
IRequest request;
|
||||||
|
while ((request = RequestManager.pollRequest()) != null) {
|
||||||
|
IRequest current = request;
|
||||||
|
EXECUTOR.submit(() -> {
|
||||||
|
try {
|
||||||
|
current.handle(mcServer);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Loon.LOGGER.error("Failed to handle request: {}, {}", current.getClass().getSimpleName(), e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user