Skip to content
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

ItemStack serialization is lossy #3309

Open
ItsDoot opened this issue Mar 3, 2021 · 1 comment
Open

ItemStack serialization is lossy #3309

ItsDoot opened this issue Mar 3, 2021 · 1 comment
Labels

Comments

@ItsDoot
Copy link
Member

ItsDoot commented Mar 3, 2021

In the following snippet, myItemB does not have the unbreakable tag, nor any enchantments.

ItemStack myItemA = ItemStack.builder()
            .itemType(ItemTypes.NETHERITE_HELMET)
            .add(Keys.IS_UNBREAKABLE, true)
            .add(Keys.APPLIED_ENCHANTMENTS, List.of(Enchantment.of(EnchantmentTypes.PROTECTION, 3)))
            .build();
ItemStackSnapshot mySnapshot = myItemA.createSnapshot();
ItemStack myItemB = mySnapshot.createStack();
@limbo-app limbo-app added the status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage label Mar 3, 2021
@ItsDoot ItsDoot changed the title ItemStack -> ItemStackSnapshot -> ItemStack fails to transfer item data ItemStack -> ItemStackSnapshot -> ItemStack is lossy Mar 3, 2021
@ItsDoot
Copy link
Member Author

ItsDoot commented Mar 3, 2021

Tested with:

final ItemStack itemA = ItemStack.builder()
        .itemType(ItemTypes.NETHERITE_HELMET)
        .add(Keys.IS_UNBREAKABLE, true)
        .add(Keys.APPLIED_ENCHANTMENTS, List.of(Enchantment.of(EnchantmentTypes.PROTECTION, 3)))
        .build();
final ItemStackSnapshot itemSnapshot = itemA.createSnapshot();
final ItemStack itemB = itemSnapshot.createStack();

this.logger.info("itemA: " + itemA.getValues());
this.logger.info("itemSnapshot: " + itemSnapshot.getValues());
this.logger.info("itemB: " + itemB.getValues());

Outputting:

[16:55:25] [Server thread/INFO] [kitpvp]: itemA: [ImmutableSpongeValue{key=sponge:is_unbreakable, element=true}, ImmutableSpongeListValue{key=sponge:applied_enchantments, element=[SpongeEnchantment[enchantmentType=EnchantmentType{Name=enchantment.minecraft.protection, Key=minecraft:protection}, level=3]]}]
[16:55:25] [Server thread/INFO] [kitpvp]: itemSnapshot: []
[16:55:25] [Server thread/INFO] [kitpvp]: itemB: [ImmutableSpongeValue{key=sponge:is_unbreakable, element=true}, ImmutableSpongeListValue{key=sponge:applied_enchantments, element=[SpongeEnchantment[enchantmentType=EnchantmentType{Name=enchantment.minecraft.protection, Key=minecraft:protection}, level=3]]}]

So it seems like the conversion itself transfers values fine, but when we call player.equip(EquipmentTypes.HEAD, itemB), the data is not serialized correctly, as the client doesn't see the enchantments on the item, nor that the item is unbreakable.

@ItsDoot ItsDoot changed the title ItemStack -> ItemStackSnapshot -> ItemStack is lossy ItemStack serialization is lossy Mar 3, 2021
@ImMorpheus ImMorpheus added system: data type: bug Something isn't working version: 1.16 (u) API: 8 labels May 1, 2021
@limbo-app limbo-app removed the status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage label May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants