From ed4ff79ac7e567135549fb60cb885419ef6bf845 Mon Sep 17 00:00:00 2001
From: Nassim Jahnke <nassim@njahnke.dev>
Date: Tue, 5 Dec 2023 20:39:26 +0100
Subject: [PATCH] More more work

---
 .../server/Add-BeaconEffectEvent.patch        |  0
 .../server/Add-PlayerInitialSpawnEvent.patch  |  0
 .../server/Add-TickThread.patch               |  0
 ...-option-to-load-extra-plugin-jars-no.patch |  0
 ...-despawn-distances-for-living-entiti.patch |  0
 ...d-version-history-to-version-command.patch |  0
 .../Allow-for-toggling-of-spawn-chunks.patch  |  0
 .../server/Allow-nerfed-mobs-to-jump.patch    |  0
 .../server/Always-tick-falling-blocks.patch   |  0
 ...e-before-converting-and-renaming-pla.patch |  0
 ...figurable-baby-zombie-movement-speed.patch |  0
 ...actus-bamboo-and-reed-growth-heights.patch |  0
 ...figurable-container-update-tick-rate.patch |  0
 .../server/Configurable-end-credits.patch     |  0
 .../Configurable-fishing-time-ranges.patch    |  0
 .../Configurable-mob-spawner-tick-rate.patch  |  0
 ...nfigurable-top-of-nether-void-damage.patch |  2 +-
 .../server/Disable-explosion-knockback.patch  |  6 ++--
 .../server/Disable-ice-and-snow.patch         |  2 +-
 .../server/Disable-spigot-tick-limiters.patch |  4 +--
 .../server/Disable-thunder.patch              |  0
 ...ck-and-tnt-entities-at-the-specified.patch |  0
 .../server/Entity-Origin-API.patch            | 20 ++++++------
 ...-explosions-processing-dead-entities.patch |  0
 .../Further-improve-server-tick-loop.patch    | 28 +++++++---------
 .../Implement-Paper-VersionChecker.patch      |  0
 .../Implement-PlayerLocaleChangeEvent.patch   |  0
 .../Only-refresh-abilities-if-needed.patch    |  0
 .../server/Optimize-explosions.patch          | 14 ++++----
 .../server/Player-affects-spawning-API.patch  |  0
 ...event-tile-entity-and-entity-crashes.patch |  0
 .../server/Rewrite-chunk-system.patch         | 32 +++++++++----------
 ...ient-crashes-server-lists-and-Mojang.patch |  2 +-
 .../{unapplied => }/server/Starlight.patch    |  0
 .../Use-UserCache-for-player-heads.patch      |  0
 35 files changed, 53 insertions(+), 57 deletions(-)
 rename patches/{unapplied => }/server/Add-BeaconEffectEvent.patch (100%)
 rename patches/{unapplied => }/server/Add-PlayerInitialSpawnEvent.patch (100%)
 rename patches/{unapplied => }/server/Add-TickThread.patch (100%)
 rename patches/{unapplied => }/server/Add-command-line-option-to-load-extra-plugin-jars-no.patch (100%)
 rename patches/{unapplied => }/server/Add-configurable-despawn-distances-for-living-entiti.patch (100%)
 rename patches/{unapplied => }/server/Add-version-history-to-version-command.patch (100%)
 rename patches/{unapplied => }/server/Allow-for-toggling-of-spawn-chunks.patch (100%)
 rename patches/{unapplied => }/server/Allow-nerfed-mobs-to-jump.patch (100%)
 rename patches/{unapplied => }/server/Always-tick-falling-blocks.patch (100%)
 rename patches/{unapplied => }/server/Check-online-mode-before-converting-and-renaming-pla.patch (100%)
 rename patches/{unapplied => }/server/Configurable-baby-zombie-movement-speed.patch (100%)
 rename patches/{unapplied => }/server/Configurable-cactus-bamboo-and-reed-growth-heights.patch (100%)
 rename patches/{unapplied => }/server/Configurable-container-update-tick-rate.patch (100%)
 rename patches/{unapplied => }/server/Configurable-end-credits.patch (100%)
 rename patches/{unapplied => }/server/Configurable-fishing-time-ranges.patch (100%)
 rename patches/{unapplied => }/server/Configurable-mob-spawner-tick-rate.patch (100%)
 rename patches/{unapplied => }/server/Configurable-top-of-nether-void-damage.patch (99%)
 rename patches/{unapplied => }/server/Disable-explosion-knockback.patch (85%)
 rename patches/{unapplied => }/server/Disable-ice-and-snow.patch (92%)
 rename patches/{unapplied => }/server/Disable-spigot-tick-limiters.patch (93%)
 rename patches/{unapplied => }/server/Disable-thunder.patch (100%)
 rename patches/{unapplied => }/server/Drop-falling-block-and-tnt-entities-at-the-specified.patch (100%)
 rename patches/{unapplied => }/server/Entity-Origin-API.patch (92%)
 rename patches/{unapplied => }/server/Fix-lag-from-explosions-processing-dead-entities.patch (100%)
 rename patches/{unapplied => }/server/Further-improve-server-tick-loop.patch (93%)
 rename patches/{unapplied => }/server/Implement-Paper-VersionChecker.patch (100%)
 rename patches/{unapplied => }/server/Implement-PlayerLocaleChangeEvent.patch (100%)
 rename patches/{unapplied => }/server/Only-refresh-abilities-if-needed.patch (100%)
 rename patches/{unapplied => }/server/Optimize-explosions.patch (93%)
 rename patches/{unapplied => }/server/Player-affects-spawning-API.patch (100%)
 rename patches/{unapplied => }/server/Prevent-tile-entity-and-entity-crashes.patch (100%)
 rename patches/{unapplied => }/server/Rewrite-chunk-system.patch (99%)
 rename patches/{unapplied => }/server/Show-Paper-in-client-crashes-server-lists-and-Mojang.patch (99%)
 rename patches/{unapplied => }/server/Starlight.patch (100%)
 rename patches/{unapplied => }/server/Use-UserCache-for-player-heads.patch (100%)

diff --git a/patches/unapplied/server/Add-BeaconEffectEvent.patch b/patches/server/Add-BeaconEffectEvent.patch
similarity index 100%
rename from patches/unapplied/server/Add-BeaconEffectEvent.patch
rename to patches/server/Add-BeaconEffectEvent.patch
diff --git a/patches/unapplied/server/Add-PlayerInitialSpawnEvent.patch b/patches/server/Add-PlayerInitialSpawnEvent.patch
similarity index 100%
rename from patches/unapplied/server/Add-PlayerInitialSpawnEvent.patch
rename to patches/server/Add-PlayerInitialSpawnEvent.patch
diff --git a/patches/unapplied/server/Add-TickThread.patch b/patches/server/Add-TickThread.patch
similarity index 100%
rename from patches/unapplied/server/Add-TickThread.patch
rename to patches/server/Add-TickThread.patch
diff --git a/patches/unapplied/server/Add-command-line-option-to-load-extra-plugin-jars-no.patch b/patches/server/Add-command-line-option-to-load-extra-plugin-jars-no.patch
similarity index 100%
rename from patches/unapplied/server/Add-command-line-option-to-load-extra-plugin-jars-no.patch
rename to patches/server/Add-command-line-option-to-load-extra-plugin-jars-no.patch
diff --git a/patches/unapplied/server/Add-configurable-despawn-distances-for-living-entiti.patch b/patches/server/Add-configurable-despawn-distances-for-living-entiti.patch
similarity index 100%
rename from patches/unapplied/server/Add-configurable-despawn-distances-for-living-entiti.patch
rename to patches/server/Add-configurable-despawn-distances-for-living-entiti.patch
diff --git a/patches/unapplied/server/Add-version-history-to-version-command.patch b/patches/server/Add-version-history-to-version-command.patch
similarity index 100%
rename from patches/unapplied/server/Add-version-history-to-version-command.patch
rename to patches/server/Add-version-history-to-version-command.patch
diff --git a/patches/unapplied/server/Allow-for-toggling-of-spawn-chunks.patch b/patches/server/Allow-for-toggling-of-spawn-chunks.patch
similarity index 100%
rename from patches/unapplied/server/Allow-for-toggling-of-spawn-chunks.patch
rename to patches/server/Allow-for-toggling-of-spawn-chunks.patch
diff --git a/patches/unapplied/server/Allow-nerfed-mobs-to-jump.patch b/patches/server/Allow-nerfed-mobs-to-jump.patch
similarity index 100%
rename from patches/unapplied/server/Allow-nerfed-mobs-to-jump.patch
rename to patches/server/Allow-nerfed-mobs-to-jump.patch
diff --git a/patches/unapplied/server/Always-tick-falling-blocks.patch b/patches/server/Always-tick-falling-blocks.patch
similarity index 100%
rename from patches/unapplied/server/Always-tick-falling-blocks.patch
rename to patches/server/Always-tick-falling-blocks.patch
diff --git a/patches/unapplied/server/Check-online-mode-before-converting-and-renaming-pla.patch b/patches/server/Check-online-mode-before-converting-and-renaming-pla.patch
similarity index 100%
rename from patches/unapplied/server/Check-online-mode-before-converting-and-renaming-pla.patch
rename to patches/server/Check-online-mode-before-converting-and-renaming-pla.patch
diff --git a/patches/unapplied/server/Configurable-baby-zombie-movement-speed.patch b/patches/server/Configurable-baby-zombie-movement-speed.patch
similarity index 100%
rename from patches/unapplied/server/Configurable-baby-zombie-movement-speed.patch
rename to patches/server/Configurable-baby-zombie-movement-speed.patch
diff --git a/patches/unapplied/server/Configurable-cactus-bamboo-and-reed-growth-heights.patch b/patches/server/Configurable-cactus-bamboo-and-reed-growth-heights.patch
similarity index 100%
rename from patches/unapplied/server/Configurable-cactus-bamboo-and-reed-growth-heights.patch
rename to patches/server/Configurable-cactus-bamboo-and-reed-growth-heights.patch
diff --git a/patches/unapplied/server/Configurable-container-update-tick-rate.patch b/patches/server/Configurable-container-update-tick-rate.patch
similarity index 100%
rename from patches/unapplied/server/Configurable-container-update-tick-rate.patch
rename to patches/server/Configurable-container-update-tick-rate.patch
diff --git a/patches/unapplied/server/Configurable-end-credits.patch b/patches/server/Configurable-end-credits.patch
similarity index 100%
rename from patches/unapplied/server/Configurable-end-credits.patch
rename to patches/server/Configurable-end-credits.patch
diff --git a/patches/unapplied/server/Configurable-fishing-time-ranges.patch b/patches/server/Configurable-fishing-time-ranges.patch
similarity index 100%
rename from patches/unapplied/server/Configurable-fishing-time-ranges.patch
rename to patches/server/Configurable-fishing-time-ranges.patch
diff --git a/patches/unapplied/server/Configurable-mob-spawner-tick-rate.patch b/patches/server/Configurable-mob-spawner-tick-rate.patch
similarity index 100%
rename from patches/unapplied/server/Configurable-mob-spawner-tick-rate.patch
rename to patches/server/Configurable-mob-spawner-tick-rate.patch
diff --git a/patches/unapplied/server/Configurable-top-of-nether-void-damage.patch b/patches/server/Configurable-top-of-nether-void-damage.patch
similarity index 99%
rename from patches/unapplied/server/Configurable-top-of-nether-void-damage.patch
rename to patches/server/Configurable-top-of-nether-void-damage.patch
index 879cabf3e5..85eb87f546 100644
--- a/patches/unapplied/server/Configurable-top-of-nether-void-damage.patch
+++ b/patches/server/Configurable-top-of-nether-void-damage.patch
@@ -9,7 +9,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/jav
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/Entity.java
 +++ b/src/main/java/net/minecraft/world/entity/Entity.java
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
      }
  
      public void checkBelowWorld() {
diff --git a/patches/unapplied/server/Disable-explosion-knockback.patch b/patches/server/Disable-explosion-knockback.patch
similarity index 85%
rename from patches/unapplied/server/Disable-explosion-knockback.patch
rename to patches/server/Disable-explosion-knockback.patch
index 8f0ca38cde..b3c9a1db99 100644
--- a/patches/unapplied/server/Disable-explosion-knockback.patch
+++ b/patches/server/Disable-explosion-knockback.patch
@@ -12,10 +12,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
                          if (entity instanceof LivingEntity) {
                              LivingEntity entityliving = (LivingEntity) entity;
  
--                            d14 = ProtectionEnchantment.getExplosionKnockbackAfterDampener(entityliving, d13);
-+                            d14 = entity instanceof Player && level.paperConfig().environment.disableExplosionKnockback ? 0 : ProtectionEnchantment.getExplosionKnockbackAfterDampener(entityliving, d13); // Paper - disable explosion knockback
+-                            d13 = ProtectionEnchantment.getExplosionKnockbackAfterDampener(entityliving, d12);
++                            d13 = entity instanceof Player && level.paperConfig().environment.disableExplosionKnockback ? 0 : ProtectionEnchantment.getExplosionKnockbackAfterDampener(entityliving, d12); // Paper - disable explosion knockback
                          } else {
-                             d14 = d13;
+                             d13 = d12;
                          }
 @@ -0,0 +0,0 @@ public class Explosion {
                          if (entity instanceof Player) {
diff --git a/patches/unapplied/server/Disable-ice-and-snow.patch b/patches/server/Disable-ice-and-snow.patch
similarity index 92%
rename from patches/unapplied/server/Disable-ice-and-snow.patch
rename to patches/server/Disable-ice-and-snow.patch
index 76e729cb55..119c38fb25 100644
--- a/patches/unapplied/server/Disable-ice-and-snow.patch
+++ b/patches/server/Disable-ice-and-snow.patch
@@ -15,7 +15,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        if (!this.paperConfig().environment.disableIceAndSnow) { // Paper
          for (int l = 0; l < randomTickSpeed; ++l) {
              if (this.random.nextInt(48) == 0) {
-                 this.tickIceAndSnow(flag, this.getBlockRandomPos(j, 0, k, 15));
+                 this.tickPrecipitation(this.getBlockRandomPos(j, 0, k, 15));
              }
          }
 +        } // Paper
diff --git a/patches/unapplied/server/Disable-spigot-tick-limiters.patch b/patches/server/Disable-spigot-tick-limiters.patch
similarity index 93%
rename from patches/unapplied/server/Disable-spigot-tick-limiters.patch
rename to patches/server/Disable-spigot-tick-limiters.patch
index bd1a33b06d..2a7549b796 100644
--- a/patches/unapplied/server/Disable-spigot-tick-limiters.patch
+++ b/patches/server/Disable-spigot-tick-limiters.patch
@@ -9,8 +9,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/world/level/Level.java
 +++ b/src/main/java/net/minecraft/world/level/Level.java
 @@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
-         // Spigot start
-         // Iterator iterator = this.blockEntityTickers.iterator();
+         boolean flag = this.tickRateManager().runsNormally();
+ 
          int tilesThisCycle = 0;
 -        for (this.tileLimiter.initTick();
 -                tilesThisCycle < this.blockEntityTickers.size() && (tilesThisCycle % 10 != 0 || this.tileLimiter.shouldContinue());
diff --git a/patches/unapplied/server/Disable-thunder.patch b/patches/server/Disable-thunder.patch
similarity index 100%
rename from patches/unapplied/server/Disable-thunder.patch
rename to patches/server/Disable-thunder.patch
diff --git a/patches/unapplied/server/Drop-falling-block-and-tnt-entities-at-the-specified.patch b/patches/server/Drop-falling-block-and-tnt-entities-at-the-specified.patch
similarity index 100%
rename from patches/unapplied/server/Drop-falling-block-and-tnt-entities-at-the-specified.patch
rename to patches/server/Drop-falling-block-and-tnt-entities-at-the-specified.patch
diff --git a/patches/unapplied/server/Entity-Origin-API.patch b/patches/server/Entity-Origin-API.patch
similarity index 92%
rename from patches/unapplied/server/Entity-Origin-API.patch
rename to patches/server/Entity-Origin-API.patch
index 5796490661..48ee4eac26 100644
--- a/patches/unapplied/server/Entity-Origin-API.patch
+++ b/patches/server/Entity-Origin-API.patch
@@ -28,7 +28,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/jav
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/Entity.java
 +++ b/src/main/java/net/minecraft/world/entity/Entity.java
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
      public long activatedTick = Integer.MIN_VALUE;
      public void inactiveTick() { }
      // Spigot end
@@ -56,23 +56,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      public float getBukkitYaw() {
          return this.yRot;
      }
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
-                 this.bukkitEntity.storeBukkitValues(nbt);
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+                 this.bukkitEntity.storeBukkitValues(nbttagcompound);
              }
              // CraftBukkit end
 +            // Paper start - Save the entity's origin location
 +            if (this.origin != null) {
 +                UUID originWorld = this.originWorld != null ? this.originWorld : this.level != null ? this.level.getWorld().getUID() : null;
 +                if (originWorld != null) {
-+                    nbt.putUUID("Paper.OriginWorld", originWorld);
++                    nbttagcompound.putUUID("Paper.OriginWorld", originWorld);
 +                }
-+                nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
++                nbttagcompound.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
 +            }
 +            // Paper end
-             return nbt;
+             return nbttagcompound;
          } catch (Throwable throwable) {
              CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
              }
              // CraftBukkit end
  
@@ -117,9 +117,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
 +++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
 @@ -0,0 +0,0 @@ public class PrimedTnt extends Entity implements TraceableEntity {
-     @Override
-     protected void readAdditionalSaveData(CompoundTag nbt) {
-         this.setFuse(nbt.getShort("Fuse"));
+             this.setBlockState(NbtUtils.readBlockState(this.level().holderLookup(Registries.BLOCK), nbt.getCompound("block_state")));
+         }
+ 
 +        // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
 +        if (nbt.contains("SourceLoc_x")) {
 +            int srcX = nbt.getInt("SourceLoc_x");
diff --git a/patches/unapplied/server/Fix-lag-from-explosions-processing-dead-entities.patch b/patches/server/Fix-lag-from-explosions-processing-dead-entities.patch
similarity index 100%
rename from patches/unapplied/server/Fix-lag-from-explosions-processing-dead-entities.patch
rename to patches/server/Fix-lag-from-explosions-processing-dead-entities.patch
diff --git a/patches/unapplied/server/Further-improve-server-tick-loop.patch b/patches/server/Further-improve-server-tick-loop.patch
similarity index 93%
rename from patches/unapplied/server/Further-improve-server-tick-loop.patch
rename to patches/server/Further-improve-server-tick-loop.patch
index d5f8bc0988..6092b896e9 100644
--- a/patches/unapplied/server/Further-improve-server-tick-loop.patch
+++ b/patches/server/Further-improve-server-tick-loop.patch
@@ -95,32 +95,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  
              // Spigot start
              Arrays.fill( this.recentTps, 20 );
--            long curTime, tickSection = Util.getMillis(), tickCount = 1;
-+            long start = System.nanoTime(), curTime, tickSection = start; // Paper - Further improve server tick loop
-+            lastTick = start - TICK_TIME; // Paper
+-            long tickSection = Util.getMillis(), tickCount = 1;
++            long tickSection = Util.getNanos(), curTime, tickCount = 1; // Paper
              while (this.running) {
                  // Paper start - rewrite chunk system
                  // guarantee that nothing can stop the server from halting if it can at least still tick
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
-                     throw this.chunkSystemCrash;
                  }
-                 // Paper end - rewrite chunk system
--                long i = (curTime = Util.getMillis()) - this.nextTickTime;
-+                long i = ((curTime = System.nanoTime()) / (1000L * 1000L)) - this.nextTickTime; // Paper
- 
-                 if (i > 5000L && this.nextTickTime - this.lastOverloadWarning >= 30000L) { // CraftBukkit
-                     long j = i / 50L;
-@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
-                 }
- 
+                 // Spigot start
                  ++MinecraftServer.currentTickLong; // Paper
 -                if ( tickCount++ % MinecraftServer.SAMPLE_INTERVAL == 0 )
-+                if ( ++MinecraftServer.currentTick % MinecraftServer.SAMPLE_INTERVAL == 0 )
++                if ( ++MinecraftServer.currentTick % MinecraftServer.SAMPLE_INTERVAL == 0 ) // Paper
                  {
+-                    long curTime = Util.getMillis();
 -                    double currentTps = 1E3 / ( curTime - tickSection ) * MinecraftServer.SAMPLE_INTERVAL;
 -                    this.recentTps[0] = MinecraftServer.calcTps( this.recentTps[0], 0.92, currentTps ); // 1/exp(5sec/1min)
 -                    this.recentTps[1] = MinecraftServer.calcTps( this.recentTps[1], 0.9835, currentTps ); // 1/exp(5sec/5min)
 -                    this.recentTps[2] = MinecraftServer.calcTps( this.recentTps[2], 0.9945, currentTps ); // 1/exp(5sec/15min)
++                    // Paper start
++                    curTime = Util.getNanos();
 +                    final long diff = curTime - tickSection;
 +                    java.math.BigDecimal currentTps = TPS_BASE.divide(new java.math.BigDecimal(diff), 30, java.math.RoundingMode.HALF_UP);
 +                    tps1.add(currentTps, diff);
@@ -132,8 +125,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                    this.recentTps[2] = tps15.getAverage();
 +                    // Paper end
                      tickSection = curTime;
-                 }
+-                }
++                } else curTime = Util.getNanos(); // Paper
                  // Spigot end
+ 
+                 boolean flag = i == 0L;
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
                      this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount);
                  }
@@ -141,7 +137,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 -                MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
 +                //MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit // Paper - don't overwrite current tick time
 +                lastTick = curTime;
-                 this.nextTickTime += 50L;
+                 this.nextTickTimeNanos += i;
                  this.startMetricsRecordingTick();
                  this.profiler.push("tick");
 diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
diff --git a/patches/unapplied/server/Implement-Paper-VersionChecker.patch b/patches/server/Implement-Paper-VersionChecker.patch
similarity index 100%
rename from patches/unapplied/server/Implement-Paper-VersionChecker.patch
rename to patches/server/Implement-Paper-VersionChecker.patch
diff --git a/patches/unapplied/server/Implement-PlayerLocaleChangeEvent.patch b/patches/server/Implement-PlayerLocaleChangeEvent.patch
similarity index 100%
rename from patches/unapplied/server/Implement-PlayerLocaleChangeEvent.patch
rename to patches/server/Implement-PlayerLocaleChangeEvent.patch
diff --git a/patches/unapplied/server/Only-refresh-abilities-if-needed.patch b/patches/server/Only-refresh-abilities-if-needed.patch
similarity index 100%
rename from patches/unapplied/server/Only-refresh-abilities-if-needed.patch
rename to patches/server/Only-refresh-abilities-if-needed.patch
diff --git a/patches/unapplied/server/Optimize-explosions.patch b/patches/server/Optimize-explosions.patch
similarity index 93%
rename from patches/unapplied/server/Optimize-explosions.patch
rename to patches/server/Optimize-explosions.patch
index 37cdca7919..80c610e1c2 100644
--- a/patches/unapplied/server/Optimize-explosions.patch
+++ b/patches/server/Optimize-explosions.patch
@@ -26,14 +26,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/world/level/Explosion.java
 +++ b/src/main/java/net/minecraft/world/level/Explosion.java
 @@ -0,0 +0,0 @@ public class Explosion {
-                         d8 /= d11;
-                         d9 /= d11;
-                         d10 /= d11;
--                        double d12 = (double) Explosion.getSeenPercent(vec3d, entity);
-+                        double d12 = this.getBlockDensity(vec3d, entity); // Paper - Optimize explosions
-                         double d13 = (1.0D - d7) * d12;
+                             // CraftBukkit end
+                         }
  
-                         // CraftBukkit start
+-                        double d12 = (1.0D - d7) * (double) Explosion.getSeenPercent(vec3d, entity);
++                        double d12 = (1.0D - d7) * this.getBlockDensity(vec3d, entity); // Paper - Optimize explosions
+                         double d13;
+ 
+                         if (entity instanceof LivingEntity) {
 @@ -0,0 +0,0 @@ public class Explosion {
  
          private BlockInteraction() {}
diff --git a/patches/unapplied/server/Player-affects-spawning-API.patch b/patches/server/Player-affects-spawning-API.patch
similarity index 100%
rename from patches/unapplied/server/Player-affects-spawning-API.patch
rename to patches/server/Player-affects-spawning-API.patch
diff --git a/patches/unapplied/server/Prevent-tile-entity-and-entity-crashes.patch b/patches/server/Prevent-tile-entity-and-entity-crashes.patch
similarity index 100%
rename from patches/unapplied/server/Prevent-tile-entity-and-entity-crashes.patch
rename to patches/server/Prevent-tile-entity-and-entity-crashes.patch
diff --git a/patches/unapplied/server/Rewrite-chunk-system.patch b/patches/server/Rewrite-chunk-system.patch
similarity index 99%
rename from patches/unapplied/server/Rewrite-chunk-system.patch
rename to patches/server/Rewrite-chunk-system.patch
index d2822da84b..7dadbf5c93 100644
--- a/patches/unapplied/server/Rewrite-chunk-system.patch
+++ b/patches/server/Rewrite-chunk-system.patch
@@ -16717,7 +16717,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 -        while (this.levels.values().stream().anyMatch((worldserver1) -> {
 -            return worldserver1.getChunkSource().chunkMap.hasWork();
 -        })) {
--            this.nextTickTime = Util.getMillis() + 1L;
+-            this.nextTickTimeNanos = Util.getNanos() + TimeUtil.NANOSECONDS_PER_MILLISECOND;
 -            iterator = this.getAllLevels().iterator();
 -
 -            while (iterator.hasNext()) {
@@ -16768,7 +16768,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              if (!this.initServer()) {
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
              Arrays.fill( this.recentTps, 20 );
-             long curTime, tickSection = Util.getMillis(), tickCount = 1;
+             long tickSection = Util.getMillis(), tickCount = 1;
              while (this.running) {
 +                // Paper start - rewrite chunk system
 +                // guarantee that nothing can stop the server from halting if it can at least still tick
@@ -16776,9 +16776,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                    throw this.chunkSystemCrash;
 +                }
 +                // Paper end - rewrite chunk system
-                 long i = (curTime = Util.getMillis()) - this.nextTickTime;
+                 long i;
  
-                 if (i > 5000L && this.nextTickTime - this.lastOverloadWarning >= 30000L) { // CraftBukkit
+                 if (!this.isPaused() && this.tickRateManager.isSprinting() && this.tickRateManager.checkShouldSprintThisTick()) {
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
      }
  
@@ -16790,7 +16790,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        // Paper end
          // CraftBukkit start
          if (isOversleep) return canOversleep();// Paper - because of our changes, this logic is broken
-         return this.forceTicks || this.runningTask() || Util.getMillis() < (this.mayHaveDelayedTasks ? this.delayedTasksMaxNextTickTime : this.nextTickTime);
+         return this.forceTicks || this.runningTask() || Util.getNanos() < (this.mayHaveDelayedTasks ? this.delayedTasksMaxNextTickTimeNanos : this.nextTickTimeNanos);
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
      // CraftBukkit start
      @Override
@@ -19497,7 +19497,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +            this.chunkMap.level.playerChunkLoader.tick(); // Paper - replace player chunk loader - this is mostly required to account for view distance changes
              this.tickChunks();
              this.level.timings.chunks.stopTiming(); // Paper - timings
-         }
+             this.chunkMap.tick();
 @@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource {
          ChunkHolder playerchunk = this.getVisibleChunkIfPresent(pos);
  
@@ -20646,7 +20646,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/jav
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/Entity.java
 +++ b/src/main/java/net/minecraft/world/entity/Entity.java
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
      }
      // Paper end
  
@@ -20705,7 +20705,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      public Entity(EntityType<?> type, Level world) {
          this.id = Entity.ENTITY_COUNTER.incrementAndGet();
          this.passengers = ImmutableList.of();
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
          return InteractionResult.PASS;
      }
  
@@ -20719,8 +20719,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          return false;
      }
  
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
-         };
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+         }).count();
      }
  
 +    // Paper start - rewrite chunk system
@@ -20734,9 +20734,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    // Paper end - rewrite chunk system
 +
      public boolean hasExactlyOnePlayerPassenger() {
-         return this.getIndirectPassengersStream().filter((entity) -> {
-             return entity instanceof Player;
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
+         return this.countPlayerPassengers() == 1;
+     }
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
      }
  
      public final void setPosRaw(double x, double y, double z) {
@@ -20749,7 +20749,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          if (this.position.x != x || this.position.y != y || this.position.z != z) {
              this.position = new Vec3(x, y, z);
              int i = Mth.floor(x);
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
  
      @Override
      public final void setRemoved(Entity.RemovalReason reason) {
@@ -20763,7 +20763,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          if (this.removalReason == null) {
              this.removalReason = reason;
          }
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
              this.stopRiding();
          }
  
@@ -20772,7 +20772,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          this.levelCallback.onRemove(reason);
      }
  
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
+@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
  
      @Override
      public boolean shouldBeSaved() {
diff --git a/patches/unapplied/server/Show-Paper-in-client-crashes-server-lists-and-Mojang.patch b/patches/server/Show-Paper-in-client-crashes-server-lists-and-Mojang.patch
similarity index 99%
rename from patches/unapplied/server/Show-Paper-in-client-crashes-server-lists-and-Mojang.patch
rename to patches/server/Show-Paper-in-client-crashes-server-lists-and-Mojang.patch
index de8ee7d258..c1093120a8 100644
--- a/patches/unapplied/server/Show-Paper-in-client-crashes-server-lists-and-Mojang.patch
+++ b/patches/server/Show-Paper-in-client-crashes-server-lists-and-Mojang.patch
@@ -36,7 +36,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/org/bukkit/craftbukkit/Main.java
 +++ b/src/main/java/org/bukkit/craftbukkit/Main.java
 @@ -0,0 +0,0 @@ public class Main {
-                     deadline.add(Calendar.DAY_OF_YEAR, -21);
+                     deadline.add(Calendar.DAY_OF_YEAR, -3);
                      if (buildDate.before(deadline.getTime())) {
                          System.err.println("*** Error, this build is outdated ***");
 -                        System.err.println("*** Please download a new build as per instructions from https://www.spigotmc.org/go/outdated-spigot ***");
diff --git a/patches/unapplied/server/Starlight.patch b/patches/server/Starlight.patch
similarity index 100%
rename from patches/unapplied/server/Starlight.patch
rename to patches/server/Starlight.patch
diff --git a/patches/unapplied/server/Use-UserCache-for-player-heads.patch b/patches/server/Use-UserCache-for-player-heads.patch
similarity index 100%
rename from patches/unapplied/server/Use-UserCache-for-player-heads.patch
rename to patches/server/Use-UserCache-for-player-heads.patch