Add passthrough for air serialization

This commit is contained in:
Shane Freeder 2025-04-12 18:44:32 +01:00
parent 93b6829e83
commit f517267c0c
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C

View File

@ -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);