2020-05-06 11:48:49 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-11-03 04:14:53 +01:00
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
2020-11-07 01:19:04 +01:00
index 354109e5f7a8e1b0895e12002951a4bd3bf7dd0c..95f16188a94ba31e4b6a8ea7681eaad70b86ff90 100644
2018-11-03 04:14:53 +01:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2020-11-07 01:19:04 +01:00
@@ -1195,12 +1195,24 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2018-11-03 04:14:53 +01:00
2019-05-05 13:12:32 +02:00
MinecraftTimings.timeUpdateTimer.startTiming(); // Spigot // Paper
2018-11-03 04:14:53 +01:00
// Send time updates to everyone, it will get the right time from the world the player is in.
- if (this.ticks % 20 == 0) {
- for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
- EntityPlayer entityplayer = (EntityPlayer) this.getPlayerList().players.get(i);
2019-06-25 03:47:58 +02:00
- entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(entityplayer.world.getTime(), entityplayer.getPlayerTime(), entityplayer.world.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE))); // Add support for per player time
2018-11-03 04:14:53 +01:00
+ // Paper start - optimize time updates
+ for (final WorldServer world : this.getWorlds()) {
2019-06-25 03:47:58 +02:00
+ final boolean doDaylight = world.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE);
2018-11-03 04:14:53 +01:00
+ final long dayTime = world.getDayTime();
+ long worldTime = world.getTime();
+ final PacketPlayOutUpdateTime worldPacket = new PacketPlayOutUpdateTime(worldTime, dayTime, doDaylight);
2019-05-05 13:12:32 +02:00
+ for (EntityHuman entityhuman : world.getPlayers()) {
2018-11-03 04:14:53 +01:00
+ if (!(entityhuman instanceof EntityPlayer) || (ticks + entityhuman.getId()) % 20 != 0) {
+ continue;
+ }
+ EntityPlayer entityplayer = (EntityPlayer) entityhuman;
+ long playerTime = entityplayer.getPlayerTime();
+ PacketPlayOutUpdateTime packet = (playerTime == dayTime) ? worldPacket :
+ new PacketPlayOutUpdateTime(worldTime, playerTime, doDaylight);
+ entityplayer.playerConnection.sendPacket(packet); // Add support for per player time
}
}
+ // Paper end
2019-05-05 13:12:32 +02:00
MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot // Paper
2018-11-03 04:14:53 +01:00
2019-06-25 03:47:58 +02:00
while (iterator.hasNext()) {