New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialize ItemMeta to SNBT to losslessly save ItemStacks #10609
base: master
Are you sure you want to change the base?
Conversation
+ // Paper start - serialize to SNBT | ||
+ @Override | ||
+ ImmutableMap.Builder<String, Object> modernSerialize(final ImmutableMap.Builder<String, Object> builder) { | ||
+ return builder.put("blockMaterial", this.material.name()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't be it better to use https://jd.papermc.io/paper/1.20/org/bukkit/Registry.html#MATERIAL (or nms registry) to get the namespaced name instead of enum name?
(Including if we believe rumours that with those updates items and blocks are going to be data driven, using the name from registry may be better for long term)
Just noting here for prosperity, we had a bit of an internal discussion regarding this and generally posit that the better idea would be to make the stack itself store the SNBT and get ItemMeta out of the picture, that way we stay closer to what vanilla is doing here and have something we can almost directly just pass into DFU/DataConvertor without worrying how broken ItemMeta is, especially when it comes to the upgrade path (or complete lackthereof) |
Do you mean a format similar to item:
==: org.bukkit.inventory.ItemStack
version: 3839
id: minecraft:shulker_box
count: 1
components:
minecraft:container:
- slot: 0
item:
id: minecraft:oak_log
count: 64
- slot: 1
item:
id: minecraft:oak_log
count: 64
- slot: 2
item:
id: minecraft:oak_log
count: 64
- slot: 3
item:
id: minecraft:oak_log
count: 64
- slot: 4
item:
id: minecraft:oak_log
count: 64
- slot: 5
item:
id: minecraft:oak_log
count: 64
- slot: 6
item:
id: minecraft:oak_log
count: 64
- slot: 7
item:
id: minecraft:netherite_sword
count: 1
components:
minecraft:enchantments:
levels:
minecraft:sharpness: 5
- slot: 8
item:
id: minecraft:white_banner
count: 1
components:
minecraft:banner_patterns:
- pattern: minecraft:skull
color: red
- pattern: minecraft:border
color: red
custom: |-
{
PublicBukkitValues: {
"bukkit:a20d69c7-9eac-468e-8e11-9f527acda26d": [B; 0B, 1B, 3B]
}
} Patch |
No, mojang saves itemstacks using NBT still, we'd just align ItemStack itself with that, rather than trying to keep ItemMeta in the mix (i.e. ItemMeta goes, the patch stays as snbt stored against the ItemStack itself, just like mojang does on disk) |
Changes this
to