-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
More DataFixers for Item serialization #318
Comments
They are deprecated because the entire NBTItem class is now considered internal implementation, the NBT class provides these methods correctly. The autorun when there is a "tag" or "Count" tag is a failsafe for people forgetting to update their nbt from pre 1.20.3 in 1.20.3+. Use https://github.com/tr7zw/Item-NBT-API/blob/master/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/utils/DataFixerUtil.java to update your nbt correctly. The reason this isn't done automatically is because the API doesn't know the source version, only the current version. For the next release, it is planned that like the Paper serializer save the version ID when using the convert methods, then it can also detect when and how to use the datafixer. |
Glad to hear that. Sounds like you were already planning my number 2 option :) |
Option 1 isn't an option since you can't use the DataFixerUpper without knowing the source version 😅. Before 1.21 this hasn't been a huge issue as nbt changed not a lot, but since Mojang now changes item nbt for sport, better keeping track of the source version is needed. |
While I understand
NBTItem#convertItemtoNBT
and#convertNBTtoItem
are deprecated, I've run into a small issue and wanted to make a small suggestion.As it stands right now, DataFixerUpper is only run on items that contain "tag" or "Count" tags.
This was something I requested due to NBT changes in 1.20.5, thank you for that.
Issue no is that Mojang keeps changing DataComponents in versions.
For instance, Mojang changed the custom model data component from an int, to a bunch of lists (strings/floats/booleans) in 1.21.4
If I were to for instance load this nbt, serialized from an item in 1.21.3:
{id:"minecraft:diamond_sword",count:1,components:{"minecraft:custom_model_data":1}}
into 1.21.4, I get the following error:
Tried to load invalid item: 'Not a map: 1 missed input: {"minecraft:custom_model_data":1}'
A couple of suggestions:
When running
NBTItem#convertNBTtoItem
, run all NBTs thru DataFixerUpper(not a great option, probably slow, but it is a working option)
This is something I noticed Paper does with
ItemStack#serializeToByes
:When serializing via
NBTItem#convertItemtoNBT
, you could add the current server's data version (Bukkit.getUnsafe().getDataVersion()
) to the NBT.When deserializing via
NBTItem#convertNBTtoItem
, you could check if the data version doesn't match the current version, and run it thru DataFixerUpperThis option would be much more viable than option 1, as it would only require passing thru DFU if the version has changed.
If this option were added, obviously items serialized from a previous NBT-API version would most likely have to be run thru DFU since they wouldn't have the DataVersion tag yet.
Special Note:
Minecraft 1.21.5 (or whatever version they will officially use) has a whole whack-a-doo of component changes coming.
(all components which have a "show_in_tooltip" flag are being removed, moved to a new component, and some components will be restructured, for instance the enchantments component ill be restructured)
This is just going to break serialized NBT even more, yippee!
The text was updated successfully, but these errors were encountered: