Enchantement ids were not retrieved correctly during deserialization #3906
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Version
Minecraft: 1.19.4
SpongeAPI: 10.1.0-SNAPSHOT
Sponge: 1.19.4-10.1.0-SNAPSHOT
SpongeVanilla: 1.19.4-10.0.0-RC0
The bug
The deserialization of an enchanted item in a config file produces an item without its enchantments.
Reported by #3904.
Description
During the deserilization of an enchanted item, it will first create a
CompoundTag
fromUnsafeData
and then fix the enchantment data. The problem is that the enchantment ids in theCompoundTag
are String which represent the resource location of an enchantment but they were retrieved as short. As a result, the modifiedCompoundTag
contained enchantment ids with "0s" as value.After that, if the enchantments were retrieved from the itemstack, the Optional was empty because it couldn't retrieved the enchantment type from the incorrect value "0s".
The fix
The fix is to retrieve and set as a string the enchantment id in the nbt and not as a short.