[SPIGOT-6333] CraftItemMeta comparing bad Created: 27/Jan/21  Updated: 27/Jan/21

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

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

Attachments: PNG File image-2021-01-27-17-10-33-757.png     PNG File image-2021-01-27-17-10-52-926.png    
Version: 1.16.5
Guidelines Read: Yes

 Description   

Comparing this item:

To this one:

with item.equals(otherItem) returns false, whereas the items are literally the same, the only thing that changes is the order of the tags in its lore NBT representation.

The problem is that when comparing two CraftItemMeta, it compares the lore of the two metas not as NBT compounds, but as Strings, so even if the NBT are the same, the String are different and comparing leads to false value.

Sorry if I'm not really comprehensible :/



 Comments   
Comment by blablubbabc [ 27/Jan/21 ]

> curious if the first ping notified you or I have to add you as a watcher like I normally do

Yeah, I got a notification for both of them.

> So does Minecraft. These two items will not stack with each other, therefore the behaviour seems correct to me. They are not strictly equal.

I agree: As long as Minecraft doesn't consider them equal, we should stick to that.

We could however consider adding a config option to automatically normalize all items to a common representation, as outlined in SPIGOT-6312.
However, I don't know how large the performance impact would be for this (this conversion would run for all ItemStacks whenever they are loaded by the server, and during config deserializations), and it poses the risk to break existing contraptions that rely on ItemStacks with a specific internal representation (though, I consider this a minor issue, especially if this is documented and guarded behind a by default disabled option in the Spigot config). Implementing this in a plugin is slightly more tricky compared to implementing it in the server itself (since the server can more easily hook into all ItemStack loading), and a plugin-based implementation would impose an additional performance impact (due to the additional back and forth conversions through the API).
This would probably also resolve SPIGOT-5964.

Comment by md_5 [ 27/Jan/21 ]

blablubbabc curious if the first ping notified you or I have to add you as a watcher like I normally do

Comment by md_5 [ 27/Jan/21 ]

So does Minecraft.
These two items will not stack with each other, therefore the behaviour seems correct to me. They are not strictly equal.

blablubbabc

Generated at Sat Apr 05 09:53:41 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.