--- a/net/minecraft/network/protocol/game/ServerboundContainerClickPacket.java
+++ b/net/minecraft/network/protocol/game/ServerboundContainerClickPacket.java
@@ -17,7 +_,7 @@
     );
     private static final int MAX_SLOT_COUNT = 128;
     private static final StreamCodec<RegistryFriendlyByteBuf, Int2ObjectMap<ItemStack>> SLOTS_STREAM_CODEC = ByteBufCodecs.map(
-        Int2ObjectOpenHashMap::new, ByteBufCodecs.SHORT.map(Short::intValue, Integer::shortValue), ItemStack.OPTIONAL_STREAM_CODEC, 128
+        Int2ObjectOpenHashMap::new, ByteBufCodecs.SHORT.map(Short::intValue, Integer::shortValue), ItemStack.OPTIONAL_STREAM_CODEC.apply(ByteBufCodecs::trackDepth), 128 // Paper - Track codec depth
     );
     private final int containerId;
     private final int stateId;
@@ -46,7 +_,7 @@
         this.buttonNum = buffer.readByte();
         this.clickType = buffer.readEnum(ClickType.class);
         this.changedSlots = Int2ObjectMaps.unmodifiable(SLOTS_STREAM_CODEC.decode(buffer));
-        this.carriedItem = ItemStack.OPTIONAL_STREAM_CODEC.decode(buffer);
+        this.carriedItem = ItemStack.OPTIONAL_STREAM_CODEC.apply(ByteBufCodecs::trackDepth).decode(buffer); // Paper - Track codec depth
     }
 
     private void write(RegistryFriendlyByteBuf buffer) {
