mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 13:40:24 -07:00
Add passthrough for air serialization
This commit is contained in:
parent
93b6829e83
commit
f517267c0c
@ -507,11 +507,17 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||||||
private ItemStack deserializeItem(CompoundTag compound) {
|
private ItemStack deserializeItem(CompoundTag compound) {
|
||||||
final int dataVersion = compound.getIntOr("DataVersion", 0);
|
final int dataVersion = compound.getIntOr("DataVersion", 0);
|
||||||
compound = PlatformHooks.get().convertNBT(References.ITEM_STACK, DataFixers.getDataFixer(), compound, dataVersion, this.getDataVersion()); // Paper - possibly use dataconverter
|
compound = PlatformHooks.get().convertNBT(References.ITEM_STACK, DataFixers.getDataFixer(), compound, dataVersion, this.getDataVersion()); // Paper - possibly use dataconverter
|
||||||
|
if (compound.getStringOr("id", "minecraft:air").equals("minecraft:air")) {
|
||||||
|
return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.EMPTY);
|
||||||
|
}
|
||||||
return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.parse(CraftRegistry.getMinecraftRegistry(), compound).orElseThrow());
|
return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.parse(CraftRegistry.getMinecraftRegistry(), compound).orElseThrow());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @org.jetbrains.annotations.NotNull Map<String, Object> serializeStack(final ItemStack itemStack) {
|
public @org.jetbrains.annotations.NotNull Map<String, Object> serializeStack(final ItemStack itemStack) {
|
||||||
|
if (itemStack.isEmpty()) {
|
||||||
|
return Map.of("id", "minecraft:air", SharedConstants.DATA_VERSION_TAG, this.getDataVersion(), "schema_version", 1);
|
||||||
|
}
|
||||||
final CompoundTag tag = CraftItemStack.asNMSCopy(itemStack).save(CraftRegistry.getMinecraftRegistry()).asCompound().orElseThrow();
|
final CompoundTag tag = CraftItemStack.asNMSCopy(itemStack).save(CraftRegistry.getMinecraftRegistry()).asCompound().orElseThrow();
|
||||||
NbtUtils.addCurrentDataVersion(tag);
|
NbtUtils.addCurrentDataVersion(tag);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user