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.
This commit is contained in:
Josh Roy 2023-01-23 19:19:01 -05:00
parent b8ad599ceb
commit 933e2e1efa

View file

@ -198,7 +198,7 @@ public final class CraftItemStack extends ItemStack {
} }
this.handle.setCount(amount); this.handle.setCount(amount);
if (amount == 0) { if (false && amount == 0) { // Paper - remove CraftItemStack#setAmount null assignment
this.handle = null; this.handle = null;
} }
} }