From 2bfe9eca4d81c5eebedfed909e8cc85beb7bdaec Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Tue, 7 Jun 2022 23:25:32 -0700
Subject: [PATCH] bouquet o' patches

---
 .../server/Add-API-for-quit-reason.patch      |  8 +--
 .../server/Add-Destroy-Speed-API.patch        |  0
 .../Add-LivingEntity-clearActiveItem.patch    |  0
 ...-OBSTRUCTED-reason-to-BedEnterResult.patch |  0
 .../server/Add-PlayerItemCooldownEvent.patch  |  0
 .../server/Add-PlayerShearBlockEvent.patch    |  0
 ...ing-Trader-spawn-rate-config-options.patch |  0
 .../Add-getOfflinePlayerIfCached-String.patch |  0
 .../server/Add-ignore-discounts-API.patch     |  2 +-
 ...d-missing-default-perms-for-commands.patch |  0
 ...ling-up-when-item-stack-is-empty-in-.patch |  0
 .../Beacon-API-custom-effect-ranges.patch     |  0
 ...-should-not-bypass-cramming-gamerule.patch |  0
 .../Expose-LivingEntity-hurt-direction.patch  |  0
 .../server/Expose-world-spawn-angle.patch     |  0
 ...x-CraftSound-backwards-compatibility.patch |  0
 ...r-spawnParticle-x-y-z-precision-loss.patch |  0
 ...ix-client-lag-on-advancement-loading.patch |  0
 ...ing-zombie-villager-discount-exploit.patch |  0
 ...r-large-move-vectors-crashing-server.patch |  0
 ...tem-locations-dropped-from-campfires.patch |  2 +-
 .../Fixed-TileEntityBell-memory-leak.patch    |  0
 ...inig-for-some-hot-IBlockData-methods.patch |  0
 .../server/Item-no-age-no-player-pickup.patch |  0
 .../server/Limit-recipe-packets.patch         |  0
 .../server/More-lightning-API.patch           |  0
 .../server/Optimise-getType-calls.patch       |  0
 .../Optimize-Dynamic-get-Missing-Keys.patch   |  0
 ...der-Remove-Streams-Optimized-collect.patch | 43 ++++++------
 .../Player-Chunk-Load-Unload-Events.patch     |  0
 .../server/Player-elytra-boost-API.patch      |  0
 ...blockpos-allocation-from-pathfinding.patch |  0
 ...ace-order-when-capturing-blockstates.patch |  0
 .../Toggle-for-removing-existing-dragon.patch |  0
 .../server/Villager-resetOffers.patch         |  0
 .../MC-4-Fix-item-position-desync.patch       | 65 -------------------
 ...prove-performance-of-the-end-generat.patch | 63 ------------------
 37 files changed, 30 insertions(+), 153 deletions(-)
 rename patches/{unapplied => }/server/Add-API-for-quit-reason.patch (93%)
 rename patches/{unapplied => }/server/Add-Destroy-Speed-API.patch (100%)
 rename patches/{unapplied => }/server/Add-LivingEntity-clearActiveItem.patch (100%)
 rename patches/{unapplied => }/server/Add-OBSTRUCTED-reason-to-BedEnterResult.patch (100%)
 rename patches/{unapplied => }/server/Add-PlayerItemCooldownEvent.patch (100%)
 rename patches/{unapplied => }/server/Add-PlayerShearBlockEvent.patch (100%)
 rename patches/{unapplied => }/server/Add-Wandering-Trader-spawn-rate-config-options.patch (100%)
 rename patches/{unapplied => }/server/Add-getOfflinePlayerIfCached-String.patch (100%)
 rename patches/{unapplied => }/server/Add-ignore-discounts-API.patch (99%)
 rename patches/{unapplied => }/server/Added-missing-default-perms-for-commands.patch (100%)
 rename patches/{unapplied => }/server/Avoid-error-bubbling-up-when-item-stack-is-empty-in-.patch (100%)
 rename patches/{unapplied => }/server/Beacon-API-custom-effect-ranges.patch (100%)
 rename patches/{unapplied => }/server/Climbing-should-not-bypass-cramming-gamerule.patch (100%)
 rename patches/{unapplied => }/server/Expose-LivingEntity-hurt-direction.patch (100%)
 rename patches/{unapplied => }/server/Expose-world-spawn-angle.patch (100%)
 rename patches/{unapplied => }/server/Fix-CraftSound-backwards-compatibility.patch (100%)
 rename patches/{unapplied => }/server/Fix-Player-spawnParticle-x-y-z-precision-loss.patch (100%)
 rename patches/{unapplied => }/server/Fix-client-lag-on-advancement-loading.patch (100%)
 rename patches/{unapplied => }/server/Fix-curing-zombie-villager-discount-exploit.patch (100%)
 rename patches/{unapplied => }/server/Fix-for-large-move-vectors-crashing-server.patch (100%)
 rename patches/{unapplied => }/server/Fix-item-locations-dropped-from-campfires.patch (94%)
 rename patches/{unapplied => }/server/Fixed-TileEntityBell-memory-leak.patch (100%)
 rename patches/{unapplied => }/server/Improve-inlinig-for-some-hot-IBlockData-methods.patch (100%)
 rename patches/{unapplied => }/server/Item-no-age-no-player-pickup.patch (100%)
 rename patches/{unapplied => }/server/Limit-recipe-packets.patch (100%)
 rename patches/{unapplied => }/server/More-lightning-API.patch (100%)
 rename patches/{unapplied => }/server/Optimise-getType-calls.patch (100%)
 rename patches/{unapplied => }/server/Optimize-Dynamic-get-Missing-Keys.patch (100%)
 rename patches/{unapplied => }/server/Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch (82%)
 rename patches/{unapplied => }/server/Player-Chunk-Load-Unload-Events.patch (100%)
 rename patches/{unapplied => }/server/Player-elytra-boost-API.patch (100%)
 rename patches/{unapplied => }/server/Reduce-blockpos-allocation-from-pathfinding.patch (100%)
 rename patches/{unapplied => }/server/Retain-block-place-order-when-capturing-blockstates.patch (100%)
 rename patches/{unapplied => }/server/Toggle-for-removing-existing-dragon.patch (100%)
 rename patches/{unapplied => }/server/Villager-resetOffers.patch (100%)
 delete mode 100644 patches/unapplied/server/MC-4-Fix-item-position-desync.patch
 delete mode 100644 patches/unapplied/server/Significantly-improve-performance-of-the-end-generat.patch

diff --git a/patches/unapplied/server/Add-API-for-quit-reason.patch b/patches/server/Add-API-for-quit-reason.patch
similarity index 93%
rename from patches/unapplied/server/Add-API-for-quit-reason.patch
rename to patches/server/Add-API-for-quit-reason.patch
index 0909695520..e41cca9860 100644
--- a/patches/unapplied/server/Add-API-for-quit-reason.patch
+++ b/patches/server/Add-API-for-quit-reason.patch
@@ -16,9 +16,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
                  if (throwable instanceof TimeoutException) {
                      Connection.LOGGER.debug("Timeout", throwable);
 +                    if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.TIMED_OUT; // Paper
-                     this.disconnect(new TranslatableComponent("disconnect.timeout"));
+                     this.disconnect(Component.translatable("disconnect.timeout"));
                  } else {
-                     TranslatableComponent chatmessage = new TranslatableComponent("disconnect.genericReason", new Object[]{"Internal Exception: " + throwable});
+                     MutableComponent ichatmutablecomponent = Component.translatable("disconnect.genericReason", "Internal Exception: " + throwable);
  
 +                    if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.ERRONEOUS_STATE; // Paper
                      if (flag) {
@@ -34,8 +34,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper
 +    public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - there are a lot of changes to do if we change all methods leading to the event
  
-     public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile) {
-         super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
+     public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, @Nullable ProfilePublicKey publicKey) {
+         super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile, publicKey);
 diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
diff --git a/patches/unapplied/server/Add-Destroy-Speed-API.patch b/patches/server/Add-Destroy-Speed-API.patch
similarity index 100%
rename from patches/unapplied/server/Add-Destroy-Speed-API.patch
rename to patches/server/Add-Destroy-Speed-API.patch
diff --git a/patches/unapplied/server/Add-LivingEntity-clearActiveItem.patch b/patches/server/Add-LivingEntity-clearActiveItem.patch
similarity index 100%
rename from patches/unapplied/server/Add-LivingEntity-clearActiveItem.patch
rename to patches/server/Add-LivingEntity-clearActiveItem.patch
diff --git a/patches/unapplied/server/Add-OBSTRUCTED-reason-to-BedEnterResult.patch b/patches/server/Add-OBSTRUCTED-reason-to-BedEnterResult.patch
similarity index 100%
rename from patches/unapplied/server/Add-OBSTRUCTED-reason-to-BedEnterResult.patch
rename to patches/server/Add-OBSTRUCTED-reason-to-BedEnterResult.patch
diff --git a/patches/unapplied/server/Add-PlayerItemCooldownEvent.patch b/patches/server/Add-PlayerItemCooldownEvent.patch
similarity index 100%
rename from patches/unapplied/server/Add-PlayerItemCooldownEvent.patch
rename to patches/server/Add-PlayerItemCooldownEvent.patch
diff --git a/patches/unapplied/server/Add-PlayerShearBlockEvent.patch b/patches/server/Add-PlayerShearBlockEvent.patch
similarity index 100%
rename from patches/unapplied/server/Add-PlayerShearBlockEvent.patch
rename to patches/server/Add-PlayerShearBlockEvent.patch
diff --git a/patches/unapplied/server/Add-Wandering-Trader-spawn-rate-config-options.patch b/patches/server/Add-Wandering-Trader-spawn-rate-config-options.patch
similarity index 100%
rename from patches/unapplied/server/Add-Wandering-Trader-spawn-rate-config-options.patch
rename to patches/server/Add-Wandering-Trader-spawn-rate-config-options.patch
diff --git a/patches/unapplied/server/Add-getOfflinePlayerIfCached-String.patch b/patches/server/Add-getOfflinePlayerIfCached-String.patch
similarity index 100%
rename from patches/unapplied/server/Add-getOfflinePlayerIfCached-String.patch
rename to patches/server/Add-getOfflinePlayerIfCached-String.patch
diff --git a/patches/unapplied/server/Add-ignore-discounts-API.patch b/patches/server/Add-ignore-discounts-API.patch
similarity index 99%
rename from patches/unapplied/server/Add-ignore-discounts-API.patch
rename to patches/server/Add-ignore-discounts-API.patch
index b85bf560c9..9d6cd5ae0f 100644
--- a/patches/unapplied/server/Add-ignore-discounts-API.patch
+++ b/patches/server/Add-ignore-discounts-API.patch
@@ -29,7 +29,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java
 +++ b/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java
 @@ -0,0 +0,0 @@ public class MerchantOffer {
-     public int demand; // PAIL private -> public
+     public int demand;
      public float priceMultiplier;
      public int xp;
 +    public boolean ignoreDiscounts; // Paper
diff --git a/patches/unapplied/server/Added-missing-default-perms-for-commands.patch b/patches/server/Added-missing-default-perms-for-commands.patch
similarity index 100%
rename from patches/unapplied/server/Added-missing-default-perms-for-commands.patch
rename to patches/server/Added-missing-default-perms-for-commands.patch
diff --git a/patches/unapplied/server/Avoid-error-bubbling-up-when-item-stack-is-empty-in-.patch b/patches/server/Avoid-error-bubbling-up-when-item-stack-is-empty-in-.patch
similarity index 100%
rename from patches/unapplied/server/Avoid-error-bubbling-up-when-item-stack-is-empty-in-.patch
rename to patches/server/Avoid-error-bubbling-up-when-item-stack-is-empty-in-.patch
diff --git a/patches/unapplied/server/Beacon-API-custom-effect-ranges.patch b/patches/server/Beacon-API-custom-effect-ranges.patch
similarity index 100%
rename from patches/unapplied/server/Beacon-API-custom-effect-ranges.patch
rename to patches/server/Beacon-API-custom-effect-ranges.patch
diff --git a/patches/unapplied/server/Climbing-should-not-bypass-cramming-gamerule.patch b/patches/server/Climbing-should-not-bypass-cramming-gamerule.patch
similarity index 100%
rename from patches/unapplied/server/Climbing-should-not-bypass-cramming-gamerule.patch
rename to patches/server/Climbing-should-not-bypass-cramming-gamerule.patch
diff --git a/patches/unapplied/server/Expose-LivingEntity-hurt-direction.patch b/patches/server/Expose-LivingEntity-hurt-direction.patch
similarity index 100%
rename from patches/unapplied/server/Expose-LivingEntity-hurt-direction.patch
rename to patches/server/Expose-LivingEntity-hurt-direction.patch
diff --git a/patches/unapplied/server/Expose-world-spawn-angle.patch b/patches/server/Expose-world-spawn-angle.patch
similarity index 100%
rename from patches/unapplied/server/Expose-world-spawn-angle.patch
rename to patches/server/Expose-world-spawn-angle.patch
diff --git a/patches/unapplied/server/Fix-CraftSound-backwards-compatibility.patch b/patches/server/Fix-CraftSound-backwards-compatibility.patch
similarity index 100%
rename from patches/unapplied/server/Fix-CraftSound-backwards-compatibility.patch
rename to patches/server/Fix-CraftSound-backwards-compatibility.patch
diff --git a/patches/unapplied/server/Fix-Player-spawnParticle-x-y-z-precision-loss.patch b/patches/server/Fix-Player-spawnParticle-x-y-z-precision-loss.patch
similarity index 100%
rename from patches/unapplied/server/Fix-Player-spawnParticle-x-y-z-precision-loss.patch
rename to patches/server/Fix-Player-spawnParticle-x-y-z-precision-loss.patch
diff --git a/patches/unapplied/server/Fix-client-lag-on-advancement-loading.patch b/patches/server/Fix-client-lag-on-advancement-loading.patch
similarity index 100%
rename from patches/unapplied/server/Fix-client-lag-on-advancement-loading.patch
rename to patches/server/Fix-client-lag-on-advancement-loading.patch
diff --git a/patches/unapplied/server/Fix-curing-zombie-villager-discount-exploit.patch b/patches/server/Fix-curing-zombie-villager-discount-exploit.patch
similarity index 100%
rename from patches/unapplied/server/Fix-curing-zombie-villager-discount-exploit.patch
rename to patches/server/Fix-curing-zombie-villager-discount-exploit.patch
diff --git a/patches/unapplied/server/Fix-for-large-move-vectors-crashing-server.patch b/patches/server/Fix-for-large-move-vectors-crashing-server.patch
similarity index 100%
rename from patches/unapplied/server/Fix-for-large-move-vectors-crashing-server.patch
rename to patches/server/Fix-for-large-move-vectors-crashing-server.patch
diff --git a/patches/unapplied/server/Fix-item-locations-dropped-from-campfires.patch b/patches/server/Fix-item-locations-dropped-from-campfires.patch
similarity index 94%
rename from patches/unapplied/server/Fix-item-locations-dropped-from-campfires.patch
rename to patches/server/Fix-item-locations-dropped-from-campfires.patch
index 52ce91bafa..16c09fd48e 100644
--- a/patches/unapplied/server/Fix-item-locations-dropped-from-campfires.patch
+++ b/patches/server/Fix-item-locations-dropped-from-campfires.patch
@@ -21,4 +21,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                    // Paper end
                      campfire.items.set(i, ItemStack.EMPTY);
                      world.sendBlockUpdated(pos, state, state, 3);
-                 }
+                     world.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(state));
diff --git a/patches/unapplied/server/Fixed-TileEntityBell-memory-leak.patch b/patches/server/Fixed-TileEntityBell-memory-leak.patch
similarity index 100%
rename from patches/unapplied/server/Fixed-TileEntityBell-memory-leak.patch
rename to patches/server/Fixed-TileEntityBell-memory-leak.patch
diff --git a/patches/unapplied/server/Improve-inlinig-for-some-hot-IBlockData-methods.patch b/patches/server/Improve-inlinig-for-some-hot-IBlockData-methods.patch
similarity index 100%
rename from patches/unapplied/server/Improve-inlinig-for-some-hot-IBlockData-methods.patch
rename to patches/server/Improve-inlinig-for-some-hot-IBlockData-methods.patch
diff --git a/patches/unapplied/server/Item-no-age-no-player-pickup.patch b/patches/server/Item-no-age-no-player-pickup.patch
similarity index 100%
rename from patches/unapplied/server/Item-no-age-no-player-pickup.patch
rename to patches/server/Item-no-age-no-player-pickup.patch
diff --git a/patches/unapplied/server/Limit-recipe-packets.patch b/patches/server/Limit-recipe-packets.patch
similarity index 100%
rename from patches/unapplied/server/Limit-recipe-packets.patch
rename to patches/server/Limit-recipe-packets.patch
diff --git a/patches/unapplied/server/More-lightning-API.patch b/patches/server/More-lightning-API.patch
similarity index 100%
rename from patches/unapplied/server/More-lightning-API.patch
rename to patches/server/More-lightning-API.patch
diff --git a/patches/unapplied/server/Optimise-getType-calls.patch b/patches/server/Optimise-getType-calls.patch
similarity index 100%
rename from patches/unapplied/server/Optimise-getType-calls.patch
rename to patches/server/Optimise-getType-calls.patch
diff --git a/patches/unapplied/server/Optimize-Dynamic-get-Missing-Keys.patch b/patches/server/Optimize-Dynamic-get-Missing-Keys.patch
similarity index 100%
rename from patches/unapplied/server/Optimize-Dynamic-get-Missing-Keys.patch
rename to patches/server/Optimize-Dynamic-get-Missing-Keys.patch
diff --git a/patches/unapplied/server/Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch b/patches/server/Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch
similarity index 82%
rename from patches/unapplied/server/Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch
rename to patches/server/Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch
index 7c2c7137b7..2cfd1213a6 100644
--- a/patches/unapplied/server/Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch
+++ b/patches/server/Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch
@@ -21,21 +21,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
 +++ b/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
 @@ -0,0 +0,0 @@ public class PathFinder {
-         this.openSet.clear();
-         this.nodeEvaluator.prepare(world, mob);
-         Node node = this.nodeEvaluator.getStart();
--        Map<Target, BlockPos> map = positions.stream().collect(Collectors.toMap((pos) -> {
--            return this.nodeEvaluator.getGoal((double)pos.getX(), (double)pos.getY(), (double)pos.getZ());
--        }, Function.identity()));
-+        // Paper start - remove streams - and optimize collection
-+        List<Map.Entry<Target, BlockPos>> map = Lists.newArrayList();
-+        for (BlockPos blockPos : positions) {
-+            map.add(new java.util.AbstractMap.SimpleEntry<>(this.nodeEvaluator.getGoal(blockPos.getX(), blockPos.getY(), blockPos.getZ()), blockPos));
-+        }
-+        // Paper end
-         Path path = this.findPath(world.getProfiler(), node, map, followRange, distance, rangeMultiplier);
-         this.nodeEvaluator.done();
-         return path;
+         if (node == null) {
+             return null;
+         } else {
+-            Map<Target, BlockPos> map = positions.stream().collect(Collectors.toMap((pos) -> {
+-                return this.nodeEvaluator.getGoal((double)pos.getX(), (double)pos.getY(), (double)pos.getZ());
+-            }, Function.identity()));
++            // Paper start - remove streams - and optimize collection
++            List<Map.Entry<Target, BlockPos>> map = Lists.newArrayList();
++            for (BlockPos pos : positions) {
++                map.add(new java.util.AbstractMap.SimpleEntry<>(this.nodeEvaluator.getGoal(pos.getX(), pos.getY(), pos.getZ()), pos));
++            }
++            // Paper end
+             Path path = this.findPath(world.getProfiler(), node, map, followRange, distance, rangeMultiplier);
+             this.nodeEvaluator.done();
+             return path;
+@@ -0,0 +0,0 @@ public class PathFinder {
      }
  
      @Nullable
@@ -45,7 +46,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          profiler.push("find_path");
          profiler.markForCharting(MetricCategory.PATH_FINDING);
 -        Set<Target> set = positions.keySet();
-+        //Set<Target> set = positions.keySet();
++        // Set<Target> set = positions.keySet();
          startNode.g = 0.0F;
 -        startNode.h = this.getBestH(startNode, set);
 +        startNode.h = this.getBestH(startNode, positions); // Paper - optimize collection
@@ -53,7 +54,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          this.openSet.clear();
          this.openSet.insert(startNode);
 -        Set<Node> set2 = ImmutableSet.of();
-+        //Set<Node> set2 = ImmutableSet.of(); // Paper - unused - diff on change
++        // Set<Node> set2 = ImmutableSet.of(); // Paper - unused - diff on change
          int i = 0;
 -        Set<Target> set3 = Sets.newHashSetWithExpectedSize(set.size());
 +        List<Map.Entry<Target, BlockPos>> entryList = Lists.newArrayListWithExpectedSize(positions.size()); // Paper - optimize collection
@@ -95,8 +96,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              }
          }
  
--        Optional<Path> optional = !set3.isEmpty() ? set3.stream().map((target) -> {
--            return this.reconstructPath(target.getBestNode(), positions.get(target), true);
+-        Optional<Path> optional = !set3.isEmpty() ? set3.stream().map((node) -> {
+-            return this.reconstructPath(node.getBestNode(), positions.get(node), true);
 -        }).min(Comparator.comparingInt(Path::getNodeCount)) : set.stream().map((target) -> {
 -            return this.reconstructPath(target.getBestNode(), positions.get(target), false);
 -        }).min(Comparator.comparingDouble(Path::getDistToTarget).thenComparingInt(Path::getNodeCount));
@@ -116,6 +117,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        // Paper end
      }
  
+     protected float distance(Node a, Node b) {
+         return a.distanceTo(b);
+     }
+ 
 -    private float getBestH(Node node, Set<Target> targets) {
 +    private float getBestH(Node node, List<Map.Entry<Target, BlockPos>> targets) { // Paper - optimize collection - Set<Target> -> List<Map.Entry<Target, BlockPos>>
          float f = Float.MAX_VALUE;
diff --git a/patches/unapplied/server/Player-Chunk-Load-Unload-Events.patch b/patches/server/Player-Chunk-Load-Unload-Events.patch
similarity index 100%
rename from patches/unapplied/server/Player-Chunk-Load-Unload-Events.patch
rename to patches/server/Player-Chunk-Load-Unload-Events.patch
diff --git a/patches/unapplied/server/Player-elytra-boost-API.patch b/patches/server/Player-elytra-boost-API.patch
similarity index 100%
rename from patches/unapplied/server/Player-elytra-boost-API.patch
rename to patches/server/Player-elytra-boost-API.patch
diff --git a/patches/unapplied/server/Reduce-blockpos-allocation-from-pathfinding.patch b/patches/server/Reduce-blockpos-allocation-from-pathfinding.patch
similarity index 100%
rename from patches/unapplied/server/Reduce-blockpos-allocation-from-pathfinding.patch
rename to patches/server/Reduce-blockpos-allocation-from-pathfinding.patch
diff --git a/patches/unapplied/server/Retain-block-place-order-when-capturing-blockstates.patch b/patches/server/Retain-block-place-order-when-capturing-blockstates.patch
similarity index 100%
rename from patches/unapplied/server/Retain-block-place-order-when-capturing-blockstates.patch
rename to patches/server/Retain-block-place-order-when-capturing-blockstates.patch
diff --git a/patches/unapplied/server/Toggle-for-removing-existing-dragon.patch b/patches/server/Toggle-for-removing-existing-dragon.patch
similarity index 100%
rename from patches/unapplied/server/Toggle-for-removing-existing-dragon.patch
rename to patches/server/Toggle-for-removing-existing-dragon.patch
diff --git a/patches/unapplied/server/Villager-resetOffers.patch b/patches/server/Villager-resetOffers.patch
similarity index 100%
rename from patches/unapplied/server/Villager-resetOffers.patch
rename to patches/server/Villager-resetOffers.patch
diff --git a/patches/unapplied/server/MC-4-Fix-item-position-desync.patch b/patches/unapplied/server/MC-4-Fix-item-position-desync.patch
deleted file mode 100644
index ea7bc8ec62..0000000000
--- a/patches/unapplied/server/MC-4-Fix-item-position-desync.patch
+++ /dev/null
@@ -1,65 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: BillyGalbreath <blake.galbreath@gmail.com>
-Date: Tue, 8 Dec 2020 20:24:52 -0600
-Subject: [PATCH] MC-4: Fix item position desync
-
-This fixes item position desync (MC-4) by running the item coordinates
-through the encode/decode methods of the packet that causes the precision
-loss, which forces the server to lose the same precision as the client
-keeping them in sync.
-
-diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
-+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
-@@ -0,0 +0,0 @@ public class PaperConfig {
-         trackPluginScoreboards = getBoolean("settings.track-plugin-scoreboards", false);
-     }
- 
-+    public static boolean fixEntityPositionDesync = true;
-+    private static void fixEntityPositionDesync() {
-+        fixEntityPositionDesync = getBoolean("settings.fix-entity-position-desync", fixEntityPositionDesync);
-+    }
-+
-     public static void registerCommands() {
-         for (Map.Entry<String, Command> entry : commands.entrySet()) {
-             MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Paper", entry.getValue());
-diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundMoveEntityPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundMoveEntityPacket.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/net/minecraft/network/protocol/game/ClientboundMoveEntityPacket.java
-+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundMoveEntityPacket.java
-@@ -0,0 +0,0 @@ public abstract class ClientboundMoveEntityPacket implements Packet<ClientGamePa
-     protected final boolean hasPos;
- 
-     public static long entityToPacket(double coord) {
--        return Mth.lfloor(coord * 4096.0D);
-+        return Mth.lfloor(coord * 4096.0D); // Paper - check ItemEntity#setPosRaw on update
-     }
- 
-     public static double packetToEntity(long coord) {
--        return (double)coord / 4096.0D;
-+        return (double)coord / 4096.0D; // Paper - check ItemEntity#setPosRaw on update
-     }
- 
-     public Vec3 updateEntityPosition(Vec3 orig) {
-diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
-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 {
-     }
-     public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
-         // Paper end
-+        // Paper start - fix MC-4
-+        if (this instanceof ItemEntity) {
-+            if (com.destroystokyo.paper.PaperConfig.fixEntityPositionDesync) {
-+                // encode/decode from PacketPlayOutEntity
-+                x = Mth.lfloor(x * 4096.0D) * (1 / 4096.0D);
-+                y = Mth.lfloor(y * 4096.0D) * (1 / 4096.0D);
-+                z = Mth.lfloor(z * 4096.0D) * (1 / 4096.0D);
-+            }
-+        }
-+        // Paper end - fix MC-4
-         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);
diff --git a/patches/unapplied/server/Significantly-improve-performance-of-the-end-generat.patch b/patches/unapplied/server/Significantly-improve-performance-of-the-end-generat.patch
deleted file mode 100644
index c12a353daf..0000000000
--- a/patches/unapplied/server/Significantly-improve-performance-of-the-end-generat.patch
+++ /dev/null
@@ -1,63 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: SuperCoder7979 <25208576+SuperCoder7979@users.noreply.github.com>
-Date: Tue, 3 Nov 2020 23:48:05 -0600
-Subject: [PATCH] Significantly improve performance of the end generation
-
-This patch implements a noise cache for the end which significantly reduces the computation time of generation. This results in about a 3x improvement.
-
-Original code by SuperCoder7979 and Gegy in Lithium, licensed under LGPL-3.0 (Source: https://github.com/jellysquid3/lithium-fabric)
-
-Co-authored-by: Gegy <gegy1000@gmail.com>
-Co-authored-by: Dylan Xaldin <Puremin0rez515@gmail.com>
-Co-authored-by: pop4959 <pop4959@gmail.com>
-
-diff --git a/src/main/java/net/minecraft/world/level/biome/TheEndBiomeSource.java b/src/main/java/net/minecraft/world/level/biome/TheEndBiomeSource.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/net/minecraft/world/level/biome/TheEndBiomeSource.java
-+++ b/src/main/java/net/minecraft/world/level/biome/TheEndBiomeSource.java
-@@ -0,0 +0,0 @@ public class TheEndBiomeSource extends BiomeSource {
-     private final Holder<Biome> midlands;
-     private final Holder<Biome> islands;
-     private final Holder<Biome> barrens;
-+    // Paper start
-+    private static final class NoiseCache {
-+        public long[] keys = new long[8192];
-+        public float[] values = new float[8192];
-+        public NoiseCache() {
-+            java.util.Arrays.fill(keys, Long.MIN_VALUE);
-+        }
-+    }
-+    private static final ThreadLocal<java.util.Map<SimplexNoise, NoiseCache>> noiseCache = ThreadLocal.withInitial(java.util.WeakHashMap::new);
-+    // Paper end
- 
-     public TheEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
-         this(seed, biomeRegistry.getOrCreateHolder(Biomes.THE_END), biomeRegistry.getOrCreateHolder(Biomes.END_HIGHLANDS), biomeRegistry.getOrCreateHolder(Biomes.END_MIDLANDS), biomeRegistry.getOrCreateHolder(Biomes.SMALL_END_ISLANDS), biomeRegistry.getOrCreateHolder(Biomes.END_BARRENS));
-@@ -0,0 +0,0 @@ public class TheEndBiomeSource extends BiomeSource {
-         float f = 100.0F - Mth.sqrt((long) i * (long) i + (long) j * (long) j) * 8.0F; // Paper - cast ints to long to avoid integer overflow
-         f = Mth.clamp(f, -100.0F, 80.0F);
- 
-+        NoiseCache cache = noiseCache.get().computeIfAbsent(simplexNoise, noiseKey -> new NoiseCache()); // Paper
-         for(int o = -12; o <= 12; ++o) {
-             for(int p = -12; p <= 12; ++p) {
-                 long q = (long)(k + o);
-                 long r = (long)(l + p);
--                if (q * q + r * r > 4096L && simplexNoise.getValue((double)q, (double)r) < (double)-0.9F) {
--                    float g = (Mth.abs((float)q) * 3439.0F + Mth.abs((float)r) * 147.0F) % 13.0F + 9.0F;
-+                // Paper start - Significantly improve end generation performance by using a noise cache
-+                long key = net.minecraft.world.level.ChunkPos.asLong((int) q, (int) r);
-+                int index = (int) it.unimi.dsi.fastutil.HashCommon.mix(key) & 8191;
-+                float g = Float.MIN_VALUE;
-+                if (cache.keys[index] == key) {
-+                    g = cache.values[index];
-+                } else {
-+                    if (q * q + r * r > 4096L && simplexNoise.getValue((double)q, (double)r) < (double)-0.9F) {
-+                        g = (Mth.abs((float) q) * 3439.0F + Mth.abs((float) r) * 147.0F) % 13.0F + 9.0F;
-+                    }
-+                    cache.keys[index] = key;
-+                    cache.values[index] = g;
-+                }
-+                if (g != Float.MIN_VALUE) {
-+                    // Paper end
-                     float h = (float)(m - o * 2);
-                     float s = (float)(n - p * 2);
-                     float t = 100.0F - Mth.sqrt(h * h + s * s) * g;