2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Fri, 2 Nov 2018 23:11:51 -0400
Subject: [PATCH] Optimize World Time Updates
Splits time updates into incremental updates as well as does
the updates per world, so that we can re-use the same packet
object for every player unless they have per-player time enabled.
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2024-05-16 02:06:59 +02:00
index 41ffbf38f8bc4423f7670edf86702330f02e488d..c543a7e7ef3b26ab610811448b8091894a0a36d5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2024-05-16 02:06:59 +02:00
@@ -1535,12 +1535,24 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
MinecraftTimings.timeUpdateTimer.startTiming(); // Spigot // Paper
// Send time updates to everyone, it will get the right time from the world the player is in.
- if (this.tickCount % 20 == 0) {
- for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
- ServerPlayer entityplayer = (ServerPlayer) this.getPlayerList().players.get(i);
2023-06-07 22:41:26 +02:00
- entityplayer.connection.send(new ClientboundSetTimePacket(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.level().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time
2024-01-21 13:56:22 +01:00
+ // Paper start - Perf: Optimize time updates
2023-06-07 22:41:26 +02:00
+ for (final ServerLevel level : this.getAllLevels()) {
+ final boolean doDaylight = level.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT);
+ final long dayTime = level.getDayTime();
+ long worldTime = level.getGameTime();
2021-06-11 14:02:28 +02:00
+ final ClientboundSetTimePacket worldPacket = new ClientboundSetTimePacket(worldTime, dayTime, doDaylight);
2023-06-07 22:41:26 +02:00
+ for (Player entityhuman : level.players()) {
2021-06-11 14:02:28 +02:00
+ if (!(entityhuman instanceof ServerPlayer) || (tickCount + entityhuman.getId()) % 20 != 0) {
+ continue;
+ }
+ ServerPlayer entityplayer = (ServerPlayer) entityhuman;
+ long playerTime = entityplayer.getPlayerTime();
+ ClientboundSetTimePacket packet = (playerTime == dayTime) ? worldPacket :
+ new ClientboundSetTimePacket(worldTime, playerTime, doDaylight);
+ entityplayer.connection.send(packet); // Add support for per player time
}
}
2024-01-21 13:56:22 +01:00
+ // Paper end - Perf: Optimize time updates
2021-06-11 14:02:28 +02:00
MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot // Paper
while (iterator.hasNext()) {