From de0ed829ebf4574a472d1e722787b9d58567efd2 Mon Sep 17 00:00:00 2001
From: Bjarne Koll <git@lynxplay.dev>
Date: Wed, 23 Oct 2024 12:32:08 +0200
Subject: [PATCH] 242

---
 ...lock-entities-from-a-chunk-without-s.patch |   0
 ...ies-option-to-debug-dupe-uuid-issues.patch |   2 +-
 ...dd-Early-Warning-Feature-to-WatchDog.patch |   0
 .../server/Add-More-Creeper-API.patch         |   4 +-
 .../server/Add-PhantomPreSpawnEvent.patch     |   6 +-
 .../server/Add-TNTPrimeEvent.patch            |  32 +++---
 ...-ray-tracing-methods-to-LivingEntity.patch |   0
 .../Allow-disabling-armor-stand-ticking.patch |   0
 .../server/AnvilDamageEvent.patch             |   0
 ...nd-make-tab-spam-limits-configurable.patch |  34 +++---
 ...le-speed-for-water-flowing-over-lava.patch |   4 +-
 .../server/Expand-ArmorStand-API.patch        |   0
 ...e-attack-cooldown-methods-for-Player.patch |   0
 .../server/Fix-NBT-type-issues.patch          |   0
 .../Improve-BlockPosition-inlining.patch      |   0
 .../server/Improve-death-events.patch         | 106 +++++++++---------
 .../server/Inventory-removeItemAnySlot.patch  |   0
 ...loadChunk-int-int-false-load-unconve.patch |   0
 ...ptimize-BlockPosition-helper-methods.patch |   0
 .../Optimize-CraftBlockData-Creation.patch    |   0
 .../server/Optimize-MappedRegistry.patch      |  10 +-
 ...t-armor-stands-from-doing-entity-loo.patch |   0
 ...Remove-unnecessary-itemmeta-handling.patch |   0
 ...default-mob-spawn-range-and-water-an.patch |   0
 .../server/SkeletonHorse-Additions.patch      |   0
 .../server/Slime-Pathfinder-Events.patch      |   0
 .../Use-ConcurrentHashMap-in-JsonList.patch   |   0
 .../Use-a-Queue-for-Queueing-Commands.patch   |   0
 .../Vanished-players-don-t-have-rights.patch  |   0
 29 files changed, 101 insertions(+), 97 deletions(-)
 rename patches/{unapplied => }/server/Ability-to-get-block-entities-from-a-chunk-without-s.patch (100%)
 rename patches/{unapplied => }/server/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch (98%)
 rename patches/{unapplied => }/server/Add-Early-Warning-Feature-to-WatchDog.patch (100%)
 rename patches/{unapplied => }/server/Add-More-Creeper-API.patch (93%)
 rename patches/{unapplied => }/server/Add-PhantomPreSpawnEvent.patch (96%)
 rename patches/{unapplied => }/server/Add-TNTPrimeEvent.patch (83%)
 rename patches/{unapplied => }/server/Add-ray-tracing-methods-to-LivingEntity.patch (100%)
 rename patches/{unapplied => }/server/Allow-disabling-armor-stand-ticking.patch (100%)
 rename patches/{unapplied => }/server/AnvilDamageEvent.patch (100%)
 rename patches/{unapplied => }/server/Break-up-and-make-tab-spam-limits-configurable.patch (57%)
 rename patches/{unapplied => }/server/Configurable-speed-for-water-flowing-over-lava.patch (89%)
 rename patches/{unapplied => }/server/Expand-ArmorStand-API.patch (100%)
 rename patches/{unapplied => }/server/Expose-attack-cooldown-methods-for-Player.patch (100%)
 rename patches/{unapplied => }/server/Fix-NBT-type-issues.patch (100%)
 rename patches/{unapplied => }/server/Improve-BlockPosition-inlining.patch (100%)
 rename patches/{unapplied => }/server/Improve-death-events.patch (87%)
 rename patches/{unapplied => }/server/Inventory-removeItemAnySlot.patch (100%)
 rename patches/{unapplied => }/server/Make-CraftWorld-loadChunk-int-int-false-load-unconve.patch (100%)
 rename patches/{unapplied => }/server/Optimize-BlockPosition-helper-methods.patch (100%)
 rename patches/{unapplied => }/server/Optimize-CraftBlockData-Creation.patch (100%)
 rename patches/{unapplied => }/server/Optimize-MappedRegistry.patch (85%)
 rename patches/{unapplied => }/server/Option-to-prevent-armor-stands-from-doing-entity-loo.patch (100%)
 rename patches/{unapplied => }/server/Remove-unnecessary-itemmeta-handling.patch (100%)
 rename patches/{unapplied => }/server/Restore-vanilla-default-mob-spawn-range-and-water-an.patch (100%)
 rename patches/{unapplied => }/server/SkeletonHorse-Additions.patch (100%)
 rename patches/{unapplied => }/server/Slime-Pathfinder-Events.patch (100%)
 rename patches/{unapplied => }/server/Use-ConcurrentHashMap-in-JsonList.patch (100%)
 rename patches/{unapplied => }/server/Use-a-Queue-for-Queueing-Commands.patch (100%)
 rename patches/{unapplied => }/server/Vanished-players-don-t-have-rights.patch (100%)

diff --git a/patches/unapplied/server/Ability-to-get-block-entities-from-a-chunk-without-s.patch b/patches/server/Ability-to-get-block-entities-from-a-chunk-without-s.patch
similarity index 100%
rename from patches/unapplied/server/Ability-to-get-block-entities-from-a-chunk-without-s.patch
rename to patches/server/Ability-to-get-block-entities-from-a-chunk-without-s.patch
diff --git a/patches/unapplied/server/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch b/patches/server/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch
similarity index 98%
rename from patches/unapplied/server/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch
rename to patches/server/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch
index 20b6e07f24..eb878d4e3e 100644
--- a/patches/unapplied/server/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch
+++ b/patches/server/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch
@@ -8,7 +8,7 @@ diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/mai
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java
 +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
-@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel {
+@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
      // CraftBukkit start
      private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
          org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
diff --git a/patches/unapplied/server/Add-Early-Warning-Feature-to-WatchDog.patch b/patches/server/Add-Early-Warning-Feature-to-WatchDog.patch
similarity index 100%
rename from patches/unapplied/server/Add-Early-Warning-Feature-to-WatchDog.patch
rename to patches/server/Add-Early-Warning-Feature-to-WatchDog.patch
diff --git a/patches/unapplied/server/Add-More-Creeper-API.patch b/patches/server/Add-More-Creeper-API.patch
similarity index 93%
rename from patches/unapplied/server/Add-More-Creeper-API.patch
rename to patches/server/Add-More-Creeper-API.patch
index 7f6801b7c6..2d8c3c0719 100644
--- a/patches/unapplied/server/Add-More-Creeper-API.patch
+++ b/patches/server/Add-More-Creeper-API.patch
@@ -8,7 +8,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/monster/Creeper.java b/src
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/monster/Creeper.java
 +++ b/src/main/java/net/minecraft/world/entity/monster/Creeper.java
-@@ -0,0 +0,0 @@ public class Creeper extends Monster implements PowerableMob {
+@@ -0,0 +0,0 @@ public class Creeper extends Monster {
          }
  
          if (nbt.getBoolean("ignited")) {
@@ -17,7 +17,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          }
  
      }
-@@ -0,0 +0,0 @@ public class Creeper extends Monster implements PowerableMob {
+@@ -0,0 +0,0 @@ public class Creeper extends Monster {
      }
  
      public void ignite() {
diff --git a/patches/unapplied/server/Add-PhantomPreSpawnEvent.patch b/patches/server/Add-PhantomPreSpawnEvent.patch
similarity index 96%
rename from patches/unapplied/server/Add-PhantomPreSpawnEvent.patch
rename to patches/server/Add-PhantomPreSpawnEvent.patch
index 7fee1d6f33..d5b3f6ff4f 100644
--- a/patches/unapplied/server/Add-PhantomPreSpawnEvent.patch
+++ b/patches/server/Add-PhantomPreSpawnEvent.patch
@@ -33,7 +33,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  
      @Override
 @@ -0,0 +0,0 @@ public class Phantom extends FlyingMob implements Enemy {
-         return entitysize.scale(1.0F + 0.15F * (float) i);
+         return predicate.test(world, this, target);
      }
  
 +    // Paper start
@@ -67,12 +67,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                                                    continue;
 +                                                }
 +                                                // Paper end - PhantomPreSpawnEvent
-                                                 Phantom entityphantom = (Phantom) EntityType.PHANTOM.create(world);
+                                                 Phantom entityphantom = (Phantom) EntityType.PHANTOM.create(world, EntitySpawnReason.NATURAL);
  
                                                  if (entityphantom != null) {
 +                                                    entityphantom.setSpawningEntity(entityplayer.getUUID()); // Paper - PhantomPreSpawnEvent
                                                      entityphantom.moveTo(blockposition1, 0.0F, 0.0F);
-                                                     groupdataentity = entityphantom.finalizeSpawn(world, difficultydamagescaler, MobSpawnType.NATURAL, groupdataentity);
+                                                     groupdataentity = entityphantom.finalizeSpawn(world, difficultydamagescaler, EntitySpawnReason.NATURAL, groupdataentity);
                                                      world.addFreshEntityWithPassengers(entityphantom, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit
 diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
diff --git a/patches/unapplied/server/Add-TNTPrimeEvent.patch b/patches/server/Add-TNTPrimeEvent.patch
similarity index 83%
rename from patches/unapplied/server/Add-TNTPrimeEvent.patch
rename to patches/server/Add-TNTPrimeEvent.patch
index ff71cf714e..a6faf3c5ed 100644
--- a/patches/unapplied/server/Add-TNTPrimeEvent.patch
+++ b/patches/server/Add-TNTPrimeEvent.patch
@@ -17,7 +17,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, explosionSource.getIndirectSourceEntity().getBukkitEntity()).callEvent())
 +                    continue;
 +                // Paper end - TNTPrimeEvent
-                 nmsBlock.wasExploded(this.level(), blockposition, this.explosionSource);
+                 nmsBlock.wasExploded((ServerLevel) this.level(), blockposition, this.explosionSource);
  
                  this.level().removeBlock(blockposition, false);
 diff --git a/src/main/java/net/minecraft/world/level/block/FireBlock.java b/src/main/java/net/minecraft/world/level/block/FireBlock.java
@@ -64,8 +64,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              }
 @@ -0,0 +0,0 @@ public class TntBlock extends Block {
      @Override
-     protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
-         if (world.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(world, pos, PrimeCause.REDSTONE, null, sourcePos)) { // CraftBukkit - TNTPrimeEvent
+     protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, @Nullable Orientation wireOrientation, boolean notify) {
+         if (world.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(world, pos, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent
 +            // Paper start - TNTPrimeEvent
 +            org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
 +            if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.REDSTONE, null).callEvent()) {
@@ -76,27 +76,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              world.removeBlock(pos, false);
          }
 @@ -0,0 +0,0 @@ public class TntBlock extends Block {
+ 
      @Override
-     public void wasExploded(Level world, BlockPos pos, Explosion explosion) {
-         if (!world.isClientSide) {
-+            // Paper start - TNTPrimeEvent
-+            org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
-+            org.bukkit.entity.Entity source = explosion.source != null ? explosion.source.getBukkitEntity() : null;
-+            if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, source).callEvent()) {
-+                return;
-+            }
-+            // Paper end - TNTPrimeEvent
-             PrimedTnt entitytntprimed = new PrimedTnt(world, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, explosion.getIndirectSourceEntity());
-             int i = entitytntprimed.getFuse();
+     public void wasExploded(ServerLevel world, BlockPos pos, Explosion explosion) {
++        // Paper start - TNTPrimeEvent
++        org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
++        org.bukkit.entity.Entity source = explosion.getDirectSourceEntity() != null ? explosion.getDirectSourceEntity().getBukkitEntity() : null;
++        if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, source).callEvent()) {
++            return;
++        }
++        // Paper end - TNTPrimeEvent
+         PrimedTnt entitytntprimed = new PrimedTnt(world, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, explosion.getIndirectSourceEntity());
+         int i = entitytntprimed.getFuse();
  
 @@ -0,0 +0,0 @@ public class TntBlock extends Block {
-                 return ItemInteractionResult.CONSUME;
+                 return InteractionResult.CONSUME;
              }
              // CraftBukkit end
 +            // Paper start - TNTPrimeEvent
 +            org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
 +            if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.ITEM, player.getBukkitEntity()).callEvent()) {
-+                return ItemInteractionResult.FAIL;
++                return InteractionResult.FAIL;
 +            }
 +            // Paper end - TNTPrimeEvent
              TntBlock.explode(world, pos, player);
diff --git a/patches/unapplied/server/Add-ray-tracing-methods-to-LivingEntity.patch b/patches/server/Add-ray-tracing-methods-to-LivingEntity.patch
similarity index 100%
rename from patches/unapplied/server/Add-ray-tracing-methods-to-LivingEntity.patch
rename to patches/server/Add-ray-tracing-methods-to-LivingEntity.patch
diff --git a/patches/unapplied/server/Allow-disabling-armor-stand-ticking.patch b/patches/server/Allow-disabling-armor-stand-ticking.patch
similarity index 100%
rename from patches/unapplied/server/Allow-disabling-armor-stand-ticking.patch
rename to patches/server/Allow-disabling-armor-stand-ticking.patch
diff --git a/patches/unapplied/server/AnvilDamageEvent.patch b/patches/server/AnvilDamageEvent.patch
similarity index 100%
rename from patches/unapplied/server/AnvilDamageEvent.patch
rename to patches/server/AnvilDamageEvent.patch
diff --git a/patches/unapplied/server/Break-up-and-make-tab-spam-limits-configurable.patch b/patches/server/Break-up-and-make-tab-spam-limits-configurable.patch
similarity index 57%
rename from patches/unapplied/server/Break-up-and-make-tab-spam-limits-configurable.patch
rename to patches/server/Break-up-and-make-tab-spam-limits-configurable.patch
index 271c9e007f..300947eceb 100644
--- a/patches/unapplied/server/Break-up-and-make-tab-spam-limits-configurable.patch
+++ b/patches/server/Break-up-and-make-tab-spam-limits-configurable.patch
@@ -25,28 +25,36 @@ diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListener
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
 +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+@@ -0,0 +0,0 @@ import com.mojang.brigadier.ParseResults;
+ import com.mojang.brigadier.StringReader;
+ import com.mojang.brigadier.suggestion.Suggestions;
+ import com.mojang.logging.LogUtils;
++import io.papermc.paper.configuration.GlobalConfiguration;
+ import it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry;
+ import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
+ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
 @@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
+     private int tickCount;
      private int ackBlockChangesUpTo = -1;
-     // CraftBukkit start - multithreaded fields
-     private final AtomicInteger chatSpamTickCount = new AtomicInteger();
-+    private final java.util.concurrent.atomic.AtomicInteger tabSpamLimiter = new java.util.concurrent.atomic.AtomicInteger(); // Paper - configurable tab spam limits
-     // CraftBukkit end
-     private int dropSpamTickCount;
+     private final TickThrottler chatSpamThrottler = new TickThrottler(20, 200);
++    private final TickThrottler tabSpamThrottler = new TickThrottler(GlobalConfiguration.get().spamLimiter.tabSpamIncrement, GlobalConfiguration.get().spamLimiter.tabSpamLimit); // Paper - configurable tab spam limits
+     private final TickThrottler dropSpamThrottler = new TickThrottler(20, 1480);
      private double firstGoodX;
+     private double firstGoodY;
 @@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
+ 
          this.keepConnectionAlive();
-         // CraftBukkit start
-         for (int spam; (spam = this.chatSpamTickCount.get()) > 0 && !this.chatSpamTickCount.compareAndSet(spam, spam - 1); ) ;
-+        if (tabSpamLimiter.get() > 0) tabSpamLimiter.getAndDecrement(); // Paper - configurable tab spam limits
-         /* Use thread-safe field access instead
-         if (this.chatSpamTickCount > 0) {
-             --this.chatSpamTickCount;
+         this.chatSpamThrottler.tick();
++        this.tabSpamThrottler.tick(); // Paper - configurable tab spam limits
+         this.dropSpamThrottler.tick();
+         if (this.player.getLastActionTime() > 0L && this.server.getPlayerIdleTimeout() > 0 && Util.getMillis() - this.player.getLastActionTime() > (long) this.server.getPlayerIdleTimeout() * 1000L * 60L) {
+             this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854
 @@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
      public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) {
          // PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // Paper - AsyncTabCompleteEvent; run this async
          // CraftBukkit start
--        if (this.chatSpamTickCount.addAndGet(1) > 500 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) {
-+        if (this.chatSpamTickCount.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamLimit && !this.server.getPlayerList().isOp(this.player.getGameProfile())) { // Paper - configurable tab spam limits
+-        if (!this.chatSpamThrottler.isIncrementAndUnderThreshold(1, 500) && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
++        if (!this.tabSpamThrottler.isIncrementAndUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) { // Paper - configurable tab spam limits
              this.disconnect(Component.translatable("disconnect.spam"));
              return;
          }
diff --git a/patches/unapplied/server/Configurable-speed-for-water-flowing-over-lava.patch b/patches/server/Configurable-speed-for-water-flowing-over-lava.patch
similarity index 89%
rename from patches/unapplied/server/Configurable-speed-for-water-flowing-over-lava.patch
rename to patches/server/Configurable-speed-for-water-flowing-over-lava.patch
index f2f211fe28..3f687d8e1d 100644
--- a/patches/unapplied/server/Configurable-speed-for-water-flowing-over-lava.patch
+++ b/patches/server/Configurable-speed-for-water-flowing-over-lava.patch
@@ -39,11 +39,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    // Paper end - Configurable speed for water flowing over lava
 +
      @Override
-     protected BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
+     protected BlockState updateShape(BlockState state, LevelReader world, ScheduledTickAccess tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random) {
          if (state.getFluidState().isSource() || neighborState.getFluidState().isSource()) {
 @@ -0,0 +0,0 @@ public class LiquidBlock extends Block implements BucketPickup {
      @Override
-     protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
+     protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, @Nullable Orientation wireOrientation, boolean notify) {
          if (this.shouldSpreadLiquid(world, pos, state)) {
 -            world.scheduleTick(pos, state.getFluidState().getType(), this.fluid.getTickDelay(world));
 +            world.scheduleTick(pos, state.getFluidState().getType(), this.getFlowSpeed(world, pos)); // Paper - Configurable speed for water flowing over lava
diff --git a/patches/unapplied/server/Expand-ArmorStand-API.patch b/patches/server/Expand-ArmorStand-API.patch
similarity index 100%
rename from patches/unapplied/server/Expand-ArmorStand-API.patch
rename to patches/server/Expand-ArmorStand-API.patch
diff --git a/patches/unapplied/server/Expose-attack-cooldown-methods-for-Player.patch b/patches/server/Expose-attack-cooldown-methods-for-Player.patch
similarity index 100%
rename from patches/unapplied/server/Expose-attack-cooldown-methods-for-Player.patch
rename to patches/server/Expose-attack-cooldown-methods-for-Player.patch
diff --git a/patches/unapplied/server/Fix-NBT-type-issues.patch b/patches/server/Fix-NBT-type-issues.patch
similarity index 100%
rename from patches/unapplied/server/Fix-NBT-type-issues.patch
rename to patches/server/Fix-NBT-type-issues.patch
diff --git a/patches/unapplied/server/Improve-BlockPosition-inlining.patch b/patches/server/Improve-BlockPosition-inlining.patch
similarity index 100%
rename from patches/unapplied/server/Improve-BlockPosition-inlining.patch
rename to patches/server/Improve-BlockPosition-inlining.patch
diff --git a/patches/unapplied/server/Improve-death-events.patch b/patches/server/Improve-death-events.patch
similarity index 87%
rename from patches/unapplied/server/Improve-death-events.patch
rename to patches/server/Improve-death-events.patch
index 9d5df0a96e..1a78fc7a3e 100644
--- a/patches/unapplied/server/Improve-death-events.patch
+++ b/patches/server/Improve-death-events.patch
@@ -39,7 +39,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      public void die(DamageSource damageSource) {
 -        this.gameEvent(GameEvent.ENTITY_DIE);
 +        // this.gameEvent(GameEvent.ENTITY_DIE); // Paper - move below event cancellation check
-         boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
+         boolean flag = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
          // CraftBukkit start - fire PlayerDeathEvent
          if (this.isRemoved()) {
 @@ -0,0 +0,0 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
@@ -60,15 +60,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          // SPIGOT-943 - only call if they have an inventory open
          if (this.containerMenu != this.inventoryMenu) {
 @@ -0,0 +0,0 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
-                         }
                      }
                  }
--
--                return super.hurt(source, amount);
+ 
+-                return super.hurtServer(world, source, amount);
 +                // Paper start - cancellable death events
 +                //return super.hurt(source, amount);
 +                this.queueHealthUpdatePacket = true;
-+                boolean damaged = super.hurt(source, amount);
++                boolean damaged = super.hurtServer(world, source, amount);
 +                this.queueHealthUpdatePacket = false;
 +                if (this.queuedHealthUpdatePacket != null) {
 +                    this.connection.send(this.queuedHealthUpdatePacket);
@@ -180,12 +179,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      }
  
 @@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable {
-         if (!this.level().isClientSide) {
+         if (world instanceof ServerLevel worldserver) {
              boolean flag = false;
  
 -            if (adversary instanceof WitherBoss) {
 +            if (this.dead && adversary instanceof WitherBoss) { // Paper
-                 if (this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
+                 if (worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
                      BlockPos blockposition = this.blockPosition();
                      BlockState iblockdata = Blocks.WITHER_ROSE.defaultBlockState();
 @@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -200,9 +199,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        // Paper end
          boolean flag = this.lastHurtByPlayerTime > 0;
  
-         this.dropEquipment(); // CraftBukkit - from below
+         this.dropEquipment(world); // CraftBukkit - from below
          if (this.shouldDropLoot() && world.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
-             this.dropFromLootTable(damageSource, flag);
+             this.dropFromLootTable(world, damageSource, flag);
 +            // Paper start
 +            final boolean prev = this.clearEquipmentSlots;
 +            this.clearEquipmentSlots = false;
@@ -218,16 +217,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          this.drops = new ArrayList<>();
          // CraftBukkit end
  
-         // this.dropEquipment();// CraftBukkit - moved up
-         this.dropExperience(damageSource.getEntity());
+         // this.dropEquipment(worldserver);// CraftBukkit - moved up
+         this.dropExperience(world, damageSource.getEntity());
 +        return deathEvent; // Paper
      }
  
-     protected void dropEquipment() {}
+     protected void dropEquipment(ServerLevel world) {}
 +    protected void postDeathDropItems(org.bukkit.event.entity.EntityDeathEvent event) {} // Paper - method for post death logic that cannot be ran before the event is potentially cancelled
  
-     public int getExpReward(@Nullable Entity entity) { // CraftBukkit
-         Level world = this.level();
+     public int getExpReward(ServerLevel worldserver, @Nullable Entity entity) { // CraftBukkit
+         if (!this.wasExperienceConsumed() && (this.isAlwaysExperienceDropper() || this.lastHurtByPlayerTime > 0 && this.shouldDropExperience() && worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))) {
 diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/Mob.java
@@ -247,8 +246,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          super.dropCustomDeathLoot(world, source, causedByPlayer);
 @@ -0,0 +0,0 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
  
-         for (int j = 0; j < i; ++j) {
-             EquipmentSlot enumitemslot = aenumitemslot[j];
+         while (iterator.hasNext()) {
+             EquipmentSlot enumitemslot = (EquipmentSlot) iterator.next();
 +            if (this.shouldSkipLoot(enumitemslot)) continue; // Paper
              ItemStack itemstack = this.getItemBySlot(enumitemslot);
              float f = this.getEquipmentDropChance(enumitemslot);
@@ -256,7 +255,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
                      }
  
-                     this.spawnAtLocation(itemstack);
+                     this.spawnAtLocation(world, itemstack);
 +                    if (this.clearEquipmentSlots) { // Paper
                      this.setItemSlot(enumitemslot, ItemStack.EMPTY);
 +                    // Paper start
@@ -271,7 +270,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/animal/Fox.java b/src/main
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/animal/Fox.java
 +++ b/src/main/java/net/minecraft/world/entity/animal/Fox.java
-@@ -0,0 +0,0 @@ public class Fox extends Animal implements VariantHolder<Fox.Type> {
+@@ -0,0 +0,0 @@ public class Fox extends Animal implements VariantHolder<Fox.Variant> {
          return this.getTrustedUUIDs().contains(uuid);
      }
  
@@ -290,8 +289,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  
 -        if (!itemstack.isEmpty()) {
 +        boolean releaseMouth = false;
-+        if (!itemstack.isEmpty() && this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { // Fix MC-153010
-             this.spawnAtLocation(itemstack);
++        if (!itemstack.isEmpty() && world.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { // Fix MC-153010
+             this.spawnAtLocation(world, itemstack);
 +            releaseMouth = true;
 +        }
 +
@@ -318,13 +317,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/world/entity/animal/horse/AbstractChestedHorse.java
 +++ b/src/main/java/net/minecraft/world/entity/animal/horse/AbstractChestedHorse.java
 @@ -0,0 +0,0 @@ public abstract class AbstractChestedHorse extends AbstractHorse {
-                 this.spawnAtLocation(Blocks.CHEST);
-             }
- 
+         super.dropEquipment(world);
+         if (this.hasChest()) {
+             this.spawnAtLocation(world, Blocks.CHEST);
 +            //this.setChest(false); // Paper - moved to post death logic
 +        }
 +    }
-+
 +    // Paper start
 +    protected void postDeathDropItems(org.bukkit.event.entity.EntityDeathEvent event) {
 +        if (this.hasChest() && (event == null || !event.isCancelled())) {
@@ -340,36 +338,35 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
 +++ b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
 @@ -0,0 +0,0 @@ public class ArmorStand extends LivingEntity {
-                     }
-                     // CraftBukkit end
-                     if (source.is(DamageTypeTags.IS_EXPLOSION)) {
--                        this.brokenByAnything(worldserver, source);
--                        this.kill(source); // CraftBukkit
-+                        // Paper start - avoid duplicate event call
-+                        org.bukkit.event.entity.EntityDeathEvent event = this.brokenByAnything(worldserver, source);
-+                        if (!event.isCancelled()) this.kill(source, false); // CraftBukkit
-+                        // Paper end
-                         return false;
-                     } else if (source.is(DamageTypeTags.IGNITES_ARMOR_STANDS)) {
-                         if (this.isOnFire()) {
+             }
+             // CraftBukkit end
+             if (source.is(DamageTypeTags.IS_EXPLOSION)) {
+-                this.brokenByAnything(world, source);
+-                this.kill(world, source); // CraftBukkit
++                // Paper start - avoid duplicate event call
++                org.bukkit.event.entity.EntityDeathEvent event = this.brokenByAnything(world, source);
++                if (!event.isCancelled()) this.kill(source, false); // CraftBukkit
++                // Paper end
+                 return false;
+             } else if (source.is(DamageTypeTags.IGNITES_ARMOR_STANDS)) {
+                 if (this.isOnFire()) {
 @@ -0,0 +0,0 @@ public class ArmorStand extends LivingEntity {
-                                     this.gameEvent(GameEvent.ENTITY_DAMAGE, source.getEntity());
-                                     this.lastHit = i;
-                                 } else {
--                                    this.brokenByPlayer(worldserver, source);
-+                                    org.bukkit.event.entity.EntityDeathEvent event = this.brokenByPlayer(worldserver, source); // Paper
-                                     this.showBreakingParticles();
--                                    this.discard(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - SPIGOT-4890: remain as this.discard() since above damagesource method will call death event
-+                                    if (!event.isCancelled()) this.kill(source, false); // Paper - we still need to kill to follow vanilla logic (emit the game event etc...)
-                                 }
+                             this.gameEvent(GameEvent.ENTITY_DAMAGE, source.getEntity());
+                             this.lastHit = i;
+                         } else {
+-                            this.brokenByPlayer(world, source);
++                            org.bukkit.event.entity.EntityDeathEvent event = this.brokenByPlayer(world, source); // Paper
+                             this.showBreakingParticles();
+-                            this.discard(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - SPIGOT-4890: remain as this.discard() since above damagesource method will call death event
++                            if (!event.isCancelled()) this.kill(source, false); // Paper - we still need to kill to follow vanilla logic (emit the game event etc...)
+                         }
  
-                                 return true;
+                         return true;
 @@ -0,0 +0,0 @@ public class ArmorStand extends LivingEntity {
- 
          f1 -= amount;
          if (f1 <= 0.5F) {
--            this.brokenByAnything(world, damageSource);
--            this.kill(damageSource); // CraftBukkit
+             this.brokenByAnything(world, damageSource);
+-            this.kill(world, damageSource); // CraftBukkit
 +            // Paper start - avoid duplicate event call
 +            org.bukkit.event.entity.EntityDeathEvent event = this.brokenByAnything(world, damageSource);
 +            if (!event.isCancelled()) this.kill(damageSource, false); // CraftBukkit
@@ -408,7 +405,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public class ArmorStand extends LivingEntity {
      }
  
-     public void kill(DamageSource damageSource) {
+     public void kill(ServerLevel worldserver, DamageSource damageSource) {
 -        org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, (damageSource == null ? this.damageSources().genericKill() : damageSource), this.drops); // CraftBukkit - call event
 +        // Paper start - make cancellable
 +        this.kill(damageSource, true);
@@ -447,11 +444,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
 +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
 @@ -0,0 +0,0 @@ public class CraftEventFactory {
-         CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
          CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource);
-         EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(damageSource.getEntity()));
-+        populateFields(victim, event); // Paper - make cancellable
          CraftWorld world = (CraftWorld) entity.getWorld();
+         EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(world.getHandle(), damageSource.getEntity()));
++        populateFields(victim, event); // Paper - make cancellable
          Bukkit.getServer().getPluginManager().callEvent(event);
  
 +        // Paper start - make cancellable
@@ -464,10 +460,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  
          for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
 @@ -0,0 +0,0 @@ public class CraftEventFactory {
-         PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(damageSource.getEntity()), 0, deathMessage);
+         PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(victim.serverLevel(), damageSource.getEntity()), 0, deathMessage);
          event.setKeepInventory(keepInventory);
          event.setKeepLevel(victim.keepLevel); // SPIGOT-2222: pre-set keepLevel
-+        populateFields(victim, event); // Paper - make cancellable
++populateFields(victim, event); // Paper - make cancellable
          Bukkit.getServer().getPluginManager().callEvent(event);
 +        // Paper start - make cancellable
 +        if (event.isCancelled()) {
diff --git a/patches/unapplied/server/Inventory-removeItemAnySlot.patch b/patches/server/Inventory-removeItemAnySlot.patch
similarity index 100%
rename from patches/unapplied/server/Inventory-removeItemAnySlot.patch
rename to patches/server/Inventory-removeItemAnySlot.patch
diff --git a/patches/unapplied/server/Make-CraftWorld-loadChunk-int-int-false-load-unconve.patch b/patches/server/Make-CraftWorld-loadChunk-int-int-false-load-unconve.patch
similarity index 100%
rename from patches/unapplied/server/Make-CraftWorld-loadChunk-int-int-false-load-unconve.patch
rename to patches/server/Make-CraftWorld-loadChunk-int-int-false-load-unconve.patch
diff --git a/patches/unapplied/server/Optimize-BlockPosition-helper-methods.patch b/patches/server/Optimize-BlockPosition-helper-methods.patch
similarity index 100%
rename from patches/unapplied/server/Optimize-BlockPosition-helper-methods.patch
rename to patches/server/Optimize-BlockPosition-helper-methods.patch
diff --git a/patches/unapplied/server/Optimize-CraftBlockData-Creation.patch b/patches/server/Optimize-CraftBlockData-Creation.patch
similarity index 100%
rename from patches/unapplied/server/Optimize-CraftBlockData-Creation.patch
rename to patches/server/Optimize-CraftBlockData-Creation.patch
diff --git a/patches/unapplied/server/Optimize-MappedRegistry.patch b/patches/server/Optimize-MappedRegistry.patch
similarity index 85%
rename from patches/unapplied/server/Optimize-MappedRegistry.patch
rename to patches/server/Optimize-MappedRegistry.patch
index 0d9d037d06..2593cf9839 100644
--- a/patches/unapplied/server/Optimize-MappedRegistry.patch
+++ b/patches/server/Optimize-MappedRegistry.patch
@@ -11,9 +11,9 @@ diff --git a/src/main/java/net/minecraft/core/MappedRegistry.java b/src/main/jav
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/core/MappedRegistry.java
 +++ b/src/main/java/net/minecraft/core/MappedRegistry.java
-@@ -0,0 +0,0 @@ public class MappedRegistry<T> implements WritableRegistry<T> {
-     private static final Logger LOGGER = LogUtils.getLogger();
-     final ResourceKey<? extends Registry<T>> key;
+@@ -0,0 +0,0 @@ import net.minecraft.util.RandomSource;
+ public class MappedRegistry<T> implements WritableRegistry<T> {
+     private final ResourceKey<? extends Registry<T>> key;
      private final ObjectList<Holder.Reference<T>> byId = new ObjectArrayList<>(256);
 -    private final Reference2IntMap<T> toId = Util.make(new Reference2IntOpenHashMap<>(), map -> map.defaultReturnValue(-1));
 -    private final Map<ResourceLocation, Holder.Reference<T>> byLocation = new HashMap<>();
@@ -26,5 +26,5 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    private final Map<T, Holder.Reference<T>> byValue = new IdentityHashMap<>(2048); // Paper - Perf: Use bigger expected size to reduce collisions
 +    private final Map<ResourceKey<T>, RegistrationInfo> registrationInfos = new IdentityHashMap<>(2048); // Paper - Perf: Use bigger expected size to reduce collisions
      private Lifecycle registryLifecycle;
-     private volatile Map<TagKey<T>, HolderSet.Named<T>> tags = new IdentityHashMap<>();
-     private boolean frozen;
+     private final Map<TagKey<T>, HolderSet.Named<T>> frozenTags = new IdentityHashMap<>();
+     MappedRegistry.TagSet<T> allTags = MappedRegistry.TagSet.unbound();
diff --git a/patches/unapplied/server/Option-to-prevent-armor-stands-from-doing-entity-loo.patch b/patches/server/Option-to-prevent-armor-stands-from-doing-entity-loo.patch
similarity index 100%
rename from patches/unapplied/server/Option-to-prevent-armor-stands-from-doing-entity-loo.patch
rename to patches/server/Option-to-prevent-armor-stands-from-doing-entity-loo.patch
diff --git a/patches/unapplied/server/Remove-unnecessary-itemmeta-handling.patch b/patches/server/Remove-unnecessary-itemmeta-handling.patch
similarity index 100%
rename from patches/unapplied/server/Remove-unnecessary-itemmeta-handling.patch
rename to patches/server/Remove-unnecessary-itemmeta-handling.patch
diff --git a/patches/unapplied/server/Restore-vanilla-default-mob-spawn-range-and-water-an.patch b/patches/server/Restore-vanilla-default-mob-spawn-range-and-water-an.patch
similarity index 100%
rename from patches/unapplied/server/Restore-vanilla-default-mob-spawn-range-and-water-an.patch
rename to patches/server/Restore-vanilla-default-mob-spawn-range-and-water-an.patch
diff --git a/patches/unapplied/server/SkeletonHorse-Additions.patch b/patches/server/SkeletonHorse-Additions.patch
similarity index 100%
rename from patches/unapplied/server/SkeletonHorse-Additions.patch
rename to patches/server/SkeletonHorse-Additions.patch
diff --git a/patches/unapplied/server/Slime-Pathfinder-Events.patch b/patches/server/Slime-Pathfinder-Events.patch
similarity index 100%
rename from patches/unapplied/server/Slime-Pathfinder-Events.patch
rename to patches/server/Slime-Pathfinder-Events.patch
diff --git a/patches/unapplied/server/Use-ConcurrentHashMap-in-JsonList.patch b/patches/server/Use-ConcurrentHashMap-in-JsonList.patch
similarity index 100%
rename from patches/unapplied/server/Use-ConcurrentHashMap-in-JsonList.patch
rename to patches/server/Use-ConcurrentHashMap-in-JsonList.patch
diff --git a/patches/unapplied/server/Use-a-Queue-for-Queueing-Commands.patch b/patches/server/Use-a-Queue-for-Queueing-Commands.patch
similarity index 100%
rename from patches/unapplied/server/Use-a-Queue-for-Queueing-Commands.patch
rename to patches/server/Use-a-Queue-for-Queueing-Commands.patch
diff --git a/patches/unapplied/server/Vanished-players-don-t-have-rights.patch b/patches/server/Vanished-players-don-t-have-rights.patch
similarity index 100%
rename from patches/unapplied/server/Vanished-players-don-t-have-rights.patch
rename to patches/server/Vanished-players-don-t-have-rights.patch