Skip to content

Commit

Permalink
Minor tweaks to the modern tick loop (#269)
Browse files Browse the repository at this point in the history
Readd an accidentally removed line that marks "hasTicket" as true, add missing Override annotation
  • Loading branch information
uRyanxD authored Dec 11, 2024
1 parent 5bad488 commit 6dea663
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 32 deletions.
32 changes: 20 additions & 12 deletions patches/server/0004-Backport-modern-tick-loop.patch
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ index 088beb22b53ddf77dc182dd5ac39e1086d5279aa..6434b8613971a228fb0074390d8223bf
Thread thread = new Thread("Server Infinisleeper") {
{
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 7d19ec833d61c2f75b5eb75d7eb291c7366a1a9a..d7b7b123380791d218b5c6bb113ccaadc0e6ffc5 100644
index 7d19ec833d61c2f75b5eb75d7eb291c7366a1a9a..7631ed0c338e5634bbe7ffa3f8e409e5dd5820eb 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -48,7 +48,7 @@ import org.bukkit.craftbukkit.Main;
Expand Down Expand Up @@ -348,12 +348,11 @@ index 7d19ec833d61c2f75b5eb75d7eb291c7366a1a9a..d7b7b123380791d218b5c6bb113ccaad
if ( ++MinecraftServer.currentTick % SAMPLE_INTERVAL == 0 )
{
final long diff = curTime - tickSection;
@@ -613,8 +628,15 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
@@ -613,7 +628,16 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
}
lastTick = curTime;

- this.A();
- this.Q = true;
+ this.ab += 50L;
+ this.methodProfiler.a("tick");
+ this.A(this::haveTime);
Expand All @@ -363,10 +362,11 @@ index 7d19ec833d61c2f75b5eb75d7eb291c7366a1a9a..d7b7b123380791d218b5c6bb113ccaad
+ this.waitUntilNextTick();
+ this.methodProfiler.b();
+ // PandaSpigot end
+
this.Q = true;
}
// Spigot end
} else {
@@ -665,6 +687,57 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
@@ -665,6 +689,57 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
}

}
Expand Down Expand Up @@ -424,7 +424,7 @@ index 7d19ec833d61c2f75b5eb75d7eb291c7366a1a9a..d7b7b123380791d218b5c6bb113ccaad

private void a(ServerPing serverping) {
File file = this.d("server-icon.png");
@@ -698,9 +771,15 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
@@ -698,9 +773,15 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs

protected void z() {}

Expand All @@ -441,7 +441,7 @@ index 7d19ec833d61c2f75b5eb75d7eb291c7366a1a9a..d7b7b123380791d218b5c6bb113ccaad

++this.ticks;
if (this.T) {
@@ -744,6 +823,11 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
@@ -744,6 +825,11 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
}

Expand All @@ -453,23 +453,23 @@ index 7d19ec833d61c2f75b5eb75d7eb291c7366a1a9a..d7b7b123380791d218b5c6bb113ccaad
this.methodProfiler.a("tallying");
this.h[this.ticks % 100] = System.nanoTime() - i;
this.methodProfiler.b();
@@ -981,6 +1065,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
@@ -981,6 +1067,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
});
*/

+ /* // PandaSpigot start - comment out
DedicatedServer dedicatedserver = new DedicatedServer(options);

if (options.has("port")) {
@@ -1000,6 +1085,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
@@ -1000,6 +1087,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs

dedicatedserver.primaryThread.start();
// CraftBukkit end
+ */ // PandaSpigot end
} catch (Exception exception) {
MinecraftServer.LOGGER.fatal("Failed to start the minecraft server", exception);
}
@@ -1483,7 +1569,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
@@ -1483,7 +1571,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
}

public static long az() {
Expand All @@ -478,15 +478,23 @@ index 7d19ec833d61c2f75b5eb75d7eb291c7366a1a9a..d7b7b123380791d218b5c6bb113ccaad
}

public int getIdleTimeout() {
@@ -1589,6 +1677,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
return this.ab;
}

+ @Override // PandaSpigot - Modern tick loop
public Thread aM() {
return this.serverThread;
}
diff --git a/src/main/java/net/minecraft/server/SystemUtils.java b/src/main/java/net/minecraft/server/SystemUtils.java
index e65ffc1566784f8a35a4a620514375b9077ce247..0c23e540a300590f967a681a3a8cf65bfc4f1377 100644
index e65ffc1566784f8a35a4a620514375b9077ce247..f25a8c7e4e11dd9fb257b09f762585c998f8204d 100644
--- a/src/main/java/net/minecraft/server/SystemUtils.java
+++ b/src/main/java/net/minecraft/server/SystemUtils.java
@@ -6,6 +6,16 @@ import org.apache.logging.log4j.Logger;

public class SystemUtils {

+ // PandaSpigot start - Modern Tick Loop
+ // PandaSpigot start - Modern tick Loop
+ public static long getMonotonicMillis() {
+ return getMonotonicNanos() / 1000000L;
+ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Subject: [PATCH] Consolidate flush calls for entity tracker packets
Most server packets seem to be sent from here, so try to avoid expensive flush calls from them.

diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 2d3e52542cfec01ad7c3ca246ed087ef56bbcb35..568c8a28cdb44b2b0a1fb64596b96fbfe87e14cd 100644
index 0ad70c9ef1d5ab91a56852f171934a41e0c0a11d..9ae7d40f9d558d501fc754996f2122d7b9edcdae 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -944,7 +944,26 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -946,7 +946,26 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
this.methodProfiler.b();
this.methodProfiler.a("tracker");
worldserver.timings.tracker.startTiming(); // Spigot
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0017-Optimize-World-Time-Updates.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ 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
index 568c8a28cdb44b2b0a1fb64596b96fbfe87e14cd..ea2a883dc4552163b4fed10ff75ff7330cfafd71 100644
index 9ae7d40f9d558d501fc754996f2122d7b9edcdae..864f078f7242bf7b0571c61f0e023c8de02ff771 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -880,12 +880,24 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -882,12 +882,24 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree

SpigotTimings.timeUpdateTimer.startTiming(); // Spigot
// Send time updates to everyone, it will get the right time from the world the player is in.
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0018-Configurable-time-update-frequency.patch
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ index 3dd3d0702c17541083d0d365ca46e93602105bce..b5f16e8cab9e43ad7597b2ea5bc92139
public KnockbackConfig knockback;

diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index ea2a883dc4552163b4fed10ff75ff7330cfafd71..d27e39fb8b80b4745c13655ae6b671ae75a17a1f 100644
index 864f078f7242bf7b0571c61f0e023c8de02ff771..f2ba1733dcd66ef43bf6262f5fcf241c71d2d26f 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -887,7 +887,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -889,7 +889,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
long worldTime = world.getTime();
final PacketPlayOutUpdateTime worldPacket = new PacketPlayOutUpdateTime(worldTime, dayTime, doDaylight);
for (EntityHuman entityhuman : world.players) {
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0023-EntityMoveEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ index 72c7e6fc8bb0a71877d6759af44d39030bcf51f5..1353a791235ae3b820072fa80ef60c3c

protected void doTick() {}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index d27e39fb8b80b4745c13655ae6b671ae75a17a1f..5048ee0fd59b15a49ebd221fbbab44a4dea9a9d3 100644
index f2ba1733dcd66ef43bf6262f5fcf241c71d2d26f..9b3028ddc71ea072a53d44d49fc66865fdcd4d36 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -907,6 +907,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -909,6 +909,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree

// if (i == 0 || this.getAllowNether()) {
WorldServer worldserver = this.worlds.get(i);
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0030-Cleanup-allocated-favicon-ByteBuf.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ Cleanups a bytebuffer which was allocated during the encoding of the
favicon to be sent to the client.

diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 5048ee0fd59b15a49ebd221fbbab44a4dea9a9d3..f141208ad11a5594aa1b7aee5b09ad0cb9e9dd9d 100644
index 9b3028ddc71ea072a53d44d49fc66865fdcd4d36..ff1cd9953300e3306c42b0875ab003d014e7ba44 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -744,6 +744,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -746,6 +746,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree

if (file.isFile()) {
ByteBuf bytebuf = Unpooled.buffer();
+ ByteBuf bytebuf1 = null; // PandaSpigot - cleanup favicon bytebuf

try {
BufferedImage bufferedimage = ImageIO.read(file);
@@ -751,13 +752,14 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -753,13 +754,14 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
ImageIO.write(bufferedimage, "PNG", new ByteBufOutputStream(bytebuf));
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0036-Backport-PlayerProfile-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ index 9034e1ad7a013c7288e68322a65798e40d8b851d..86ab9994079c6e18e3aed885db4171d0
public EntityFishingHook hookedFish;
public boolean affectsSpawning = true; // PaperSpigot
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 705d7a2a43570e022b54698ba4311c1ab284b090..76cd10c8b8ffd7a7db8c9e95fcf59033c8d6d88e 100644
index 86abea9555bdd23eed4a2a92cc5b1907f5a081c7..a82b1d140f3e3abbce55e9d96cc340fb6a8b8642 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1622,6 +1622,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -1624,6 +1624,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ index 09085582a95fc4c61034db70dd543c5e7da8ede7..cd22366c7b066494192e0602da174701
System.setOut(new PrintStream(new LoggerOutputStream(logger, Level.INFO), true));
System.setErr(new PrintStream(new LoggerOutputStream(logger, Level.WARN), true));
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 76cd10c8b8ffd7a7db8c9e95fcf59033c8d6d88e..c5ef30ac9aeb1c10ec9c01fca854f38bea1fc895 100644
index a82b1d140f3e3abbce55e9d96cc340fb6a8b8642..7b1bb09da5f87de37df6c01252996bf32d43259a 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -41,7 +41,7 @@ import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -279,7 +279,7 @@ index 76cd10c8b8ffd7a7db8c9e95fcf59033c8d6d88e..c5ef30ac9aeb1c10ec9c01fca854f38b
Runtime.getRuntime().addShutdownHook(new org.bukkit.craftbukkit.util.ServerShutdownThread(this));

//this.serverThread = primaryThread = new Thread(this, "Server thread"); // Moved from main // PandaSpigot - comment out; we assign above
@@ -677,7 +679,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -679,7 +681,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
} finally {
// CraftBukkit start - Restore terminal to original settings
try {
Expand All @@ -288,7 +288,7 @@ index 76cd10c8b8ffd7a7db8c9e95fcf59033c8d6d88e..c5ef30ac9aeb1c10ec9c01fca854f38b
} catch (Exception ignored) {
}
// CraftBukkit end
@@ -1290,7 +1292,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -1292,7 +1294,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
}

public void sendMessage(IChatBaseComponent ichatbasecomponent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ index c1110242136e8fd98661886920b765bb5367c37d..81fc97dc295677f5c2914e8c9b97a3f4
org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
BlockPhysicsEvent event = new BlockPhysicsEvent(block, block.getTypeId());
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index c5ef30ac9aeb1c10ec9c01fca854f38bea1fc895..70fe4816c041cad14eb8a875d5128602670cd338 100644
index 7b1bb09da5f87de37df6c01252996bf32d43259a..abdcaf571f36eff832bf639d0486c988e76116f9 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -912,6 +912,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -914,6 +914,7 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
// if (i == 0 || this.getAllowNether()) {
WorldServer worldserver = this.worlds.get(i);
worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // PandaSpigot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Skip updating entity tracker if server is empty


diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 70fe4816c041cad14eb8a875d5128602670cd338..db8f456952677d75e22034e4d32250ed5eccdf0d 100644
index abdcaf571f36eff832bf639d0486c988e76116f9..476a11ac8befd4d4953b7308fe4bac28322c9121 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -974,7 +974,9 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
@@ -976,7 +976,9 @@ public abstract class MinecraftServer extends com.hpfxd.pandaspigot.tickloop.Ree
}
try {
// PandaSpigot end
Expand Down

0 comments on commit 6dea663

Please sign in to comment.