aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0910-Remove-CraftItemStack-setAmount-null-assignment.patch
blob: 76965d3ef0a196ca9bf9c20d4afcbea4596abf49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Josh Roy <joshroy126@gmail.com>
Date: Mon, 23 Jan 2023 19:19:01 -0500
Subject: [PATCH] Remove CraftItemStack#setAmount null assignment

This creates a problem with Paper's item serialization
api where deserialized items, which are internally
created as a CraftItemStack, will be completely lost if
#setAmount(0) is invoked (since the underlying handle
is set to null), while a regular Bukkit ItemStack
simply sets the amount field to zero, retaining the
item's data.

Vanilla treats items with zero amounts the same as items
with less than zero amounts, so this code doesn't create
a problem with operations on the vanilla ItemStack.

diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
index 5f8f601f5711f4e7aa3f3a6ca047fd75264d0d04..b758cf51923f9e227c287680287dc18525bed4a0 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
@@ -157,7 +157,7 @@ public final class CraftItemStack extends ItemStack {
         }
 
         this.handle.setCount(amount);
-        if (amount == 0) {
+        if (false && amount == 0) { // Paper - remove CraftItemStack#setAmount null assignment
             this.handle = null;
         }
     }