Remove CraftItemStack#setAmount null assignment (#8807)
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:
parent
b1b19b67f2
commit
18fabc08d5
14 changed files with 59 additions and 31 deletions
|
@ -6,10 +6,10 @@ Subject: [PATCH] Add Raw Byte ItemStack Serialization
|
|||
Serializes using NBT which is safer for server data migrations than bukkits format.
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
index 9c189cc0596301c16e84f7df39b983a4392583d2..cb7fd05f498448c87525eeeb012d055f90bac05e 100644
|
||||
index 9c189cc0596301c16e84f7df39b983a4392583d2..7a017d69bec0fb1e17c47d7edcfce4b1c6836693 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -434,6 +434,53 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
@@ -434,6 +434,52 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
public boolean isSupportedApiVersion(String apiVersion) {
|
||||
return apiVersion != null && SUPPORTED_API.contains(apiVersion);
|
||||
}
|
||||
|
@ -29,8 +29,7 @@ index 9c189cc0596301c16e84f7df39b983a4392583d2..cb7fd05f498448c87525eeeb012d055f
|
|||
+
|
||||
+ CompoundTag compound = deserializeNbtFromBytes(data);
|
||||
+ int dataVersion = compound.getInt("DataVersion");
|
||||
+ Dynamic<Tag> converted = DataFixers.getDataFixer().update(References.ITEM_STACK, new Dynamic<Tag>(NbtOps.INSTANCE, compound), dataVersion, getDataVersion());
|
||||
+ return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.of((CompoundTag) converted.getValue()));
|
||||
+ return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.of(ca.spottedleaf.dataconverter.minecraft.MCDataConverter.convertTag(ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.ITEM_STACK, compound, dataVersion, getDataVersion())));
|
||||
+ }
|
||||
+
|
||||
+ private byte[] serializeNbtToBytes(CompoundTag compound) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue