From 520ab93fbf2d5ae5893e0648300bda15195284b1 Mon Sep 17 00:00:00 2001
From: Nassim Jahnke <nassim@njahnke.dev>
Date: Mon, 16 Dec 2024 11:34:20 +0100
Subject: [PATCH] Fix bad method call in EquipmentDispenseItemBehavior

---
 ...1057-Optimise-getChunkAt-calls-for-loaded-chunks.patch | 4 ++--
 .../dispenser/EquipmentDispenseItemBehavior.java.patch    | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/feature-patches/1057-Optimise-getChunkAt-calls-for-loaded-chunks.patch b/feature-patches/1057-Optimise-getChunkAt-calls-for-loaded-chunks.patch
index 0fcf7dd22f..bb441c5742 100644
--- a/feature-patches/1057-Optimise-getChunkAt-calls-for-loaded-chunks.patch
+++ b/feature-patches/1057-Optimise-getChunkAt-calls-for-loaded-chunks.patch
@@ -15,7 +15,7 @@ index d310e7489fc4ecede8deef59241444769d87b0a1..f268808cb250e374f2d5652b20eece01
              return CompletableFuture.<ChunkAccess>supplyAsync(() -> this.getChunk(x, z, chunkStatus, requireChunk), this.mainThreadProcessor).join();
          } else {
 +            // Paper start - Perf: Optimise getChunkAt calls for loaded chunks
-+            LevelChunk ifLoaded = this.getChunkAtIfLoadedMainThread(x, z);
++            LevelChunk ifLoaded = this.getChunkAtIfCachedImmediately(x, z);
 +            if (ifLoaded != null) {
 +                return ifLoaded;
 +            }
@@ -51,7 +51,7 @@ index d310e7489fc4ecede8deef59241444769d87b0a1..f268808cb250e374f2d5652b20eece01
 -
 -                return null;
 -            }
-+            return this.getChunkAtIfLoadedMainThread(chunkX, chunkZ); // Paper - Perf: Optimise getChunkAt calls for loaded chunks
++            return this.getChunkAtIfCachedImmediately(chunkX, chunkZ); // Paper - Perf: Optimise getChunkAt calls for loaded chunks
          }
      }
  
diff --git a/paper-server/patches/sources/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.java.patch b/paper-server/patches/sources/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.java.patch
index b3e53ec5b6..08275c166f 100644
--- a/paper-server/patches/sources/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.java.patch
+++ b/paper-server/patches/sources/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.java.patch
@@ -1,7 +1,11 @@
 --- a/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.java
 +++ b/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.java
-@@ -17,7 +_,13 @@
-         return dispenseEquipment(blockSource, item) ? item : super.execute(blockSource, item);
+@@ -14,10 +_,16 @@
+ 
+     @Override
+     protected ItemStack execute(BlockSource blockSource, ItemStack item) {
+-        return dispenseEquipment(blockSource, item) ? item : super.execute(blockSource, item);
++        return dispenseEquipment(blockSource, item, this) ? item : super.execute(blockSource, item); // Paper - fix possible StackOverflowError
      }
  
 +    @Deprecated @io.papermc.paper.annotation.DoNotUse // Paper