[SPIGOT-8006] ItemMeta content incorrectly deserialized if inside shulker box Created: 08/Feb/25  Updated: 27/Feb/25

Status: Open
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: SkytAsul Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None

Attachments: File serialization-error.tar.gz    
Version: CraftBukkit version 4434-Spigot-d421948-ec571d7 (MC: 1.21.4) (Implementing API version 1.21.4-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

Hello.

When serializing a shulker box in 1.21.1 and deserializing it in 1.21.4, the content is incorrectly deserialized if it had things to be migrated due to data format change.

I will attach a very basic plugin that can reproduce this bug.

For instance, let's take the "custom model data" that changed. Give yourself an item with a custom model data in 1.21.1, e.g. with

/give @a paper[custom_name='["",{"text":"Custom Paper","italic":false}]',custom_model_data=42]

First, save this item (hold it in your main hand and /saveitem paper).

item: 
  ==: org.bukkit.inventory.ItemStack
  v: 3955
  type: PAPER
  meta: 
    ==: ItemMeta
    meta-type: UNSPECIFIC
    display-name: '{"text":"","extra":[{"text":"Custom Paper","italic":false}]}'
    custom-model-data: 42

Then, put it in a shulker box and serialize it (/saveitem shulker).

item: 
  ==: org.bukkit.inventory.ItemStack
  v: 3955
  type: SHULKER_BOX
  meta: 
    ==: ItemMeta
    meta-type: TILE_ENTITY
    internal: H4sIAAAAAAAA/2VPTWvCQBCdNAqag5489VLmKP6C0FPFg7eCvZUSppuJLtmPkJ1ArPjfu1vBFjqX95j35g2vAChg8WK8andOtJzf6JhDNkKciOeEc5juhW0oIs9ymCo/OEk8g8nBeIkJhfK2846dhBwerXasemqkVEMQbyvrazZVTULxbD2D1T+HI8vwfEEepScs3y+ohYxWWDZkAm9QooIlbn/sT6/UcY/Xj/serzCDB13D8je6S6bU4iu1uMl/PofTYFruq08f234DKph/owgBAAA=
    blockMaterial: SHULKER_BOX

Now, go to a 1.21.4 server. Load the paper item (/loaditem paper). You will see that the custom model data has been properly migrated: if you serialize it again you will see

item: 
  ==: org.bukkit.inventory.ItemStack
  v: 4189
  type: PAPER
  meta: 
    ==: ItemMeta
    meta-type: UNSPECIFIC
    display-name: '{"text":"","extra":[{"text":"Custom Paper","italic":false}]}'
    custom-model-data: 
      ==: CustomModelData
      floats: 
      - 42.0
      flags: []
      strings: []
      colors: []

Now, deserialize the shulker (/loaditem shulker). You can already see a warning in console:

[Server thread/ERROR]: Tried to load invalid item: 'Not a map: 42 missed input: {"minecraft:custom_model_data":42}'

Open the shulker box and take the paper out: it has lost its custom model data. You can see that by re-serializing it:

item: 
  ==: org.bukkit.inventory.ItemStack
  v: 4189
  type: PAPER
  meta: 
    ==: ItemMeta
    meta-type: UNSPECIFIC
    display-name: '{"text":"","extra":[{"text":"Custom Paper","italic":false}]}'

In my case, it completely prevents me from upgrading to 1.21.4 because all of my players backpack will contain broken items...

I am afraid I cannot help in fixing this bug because I cannot wrap my head around how CraftItemMeta is working, seems like a can of worms. I just hope you can do something to fix that...



 Comments   
Comment by SkytAsul [ 27/Feb/25 ]

Since I'm using Paper, I used one of their method to obtain the "vanilla" NBT from the item, that can be safely used across versions. Here is the issue for future reference: https://github.com/PaperMC/Paper/issues/12086

Comment by totKing [ 27/Feb/25 ]

Is there any news or a solution to the problem?

Comment by md_5 [ 09/Feb/25 ]

Problem is I don't know how to pass "v" from the item down into the ItemMeta and that's a pretty serious problem.

Generated at Tue Apr 22 07:16:07 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.