*Setup:*
Place down a shulker box and put a diamond sword with sharpness in it.
Then run the following command:
_/data modify block x y z Items[0].components.enchantments.levels."minecraft:sharpness" set value 1_
*What's supposed to happen:*
If the item already has that component, it will overwrite its value, in this case setting the sword's sharpness level to 1.
What happens instead:
The game tries to add a second component with the same name ("minecraft:sharpness"), causing it to glitch out and remove the item entirely.
(Edit: Not quite correct. As elaborated in my comment, it's caused by using the flat name instead of using "minecraft:...". For some reason, it's possible to use it for creating a component entry, but not for checking or modifying)
Linked issues
Attachments
Comments 4
This might be the same issue as MC-269274. I can no longer reproduce the item getting deleted in 24w10a, instead the command is ignored.
Placing a shulker box containing a diamond sword with sharpness V
Running the command:
/data modify block x y z Items[0].components.enchantments.levels."minecraft:sharpness" set value 1
The item is not deleted, but the above command was simply ignored
Running the command:
/data modify block x y z Items[0].components."minecraft:enchantments".levels."minecraft:sharpness" set value 1
The sharpness level is modified to 1 as expected
While the item deletion bug is fixed, there's still an inconsistency between modifying and getting an item's data:
/data modify block x y z Items[0].components.enchantments.levels."minecraft:sharpness" set value 1
=> This will successfully modify the item
/data get block x y z Items[0].components.enchantments.levels."minecraft:sharpness"
=> This command will fail, as it suddenly requires "minecraft:enchantments" instead
Turns out that using the flat name of the component (e.g. sharpness or enchantments) is allowed when creating the component, but not when reading it or modifying it.
So using '/data modify block -4 -60 -12 Items[0].components."minecraft:enchantments".levels."minecraft:sharpness" set value 1' doesn't result in any weird behaviour, even when executed repeatedly.