CivMC / Civ

Monorepo for development of and running a Civ Server.
MIT License
4 stars 10 forks source link

Named/Lored items don't stack properly #510

Open RedDevel2 opened 1 month ago

RedDevel2 commented 1 month ago

Items that have data since the 1.20 update no longer stack properly. They often have slight differences in the data on them (Why) Could have something to do with the SAH Item meta converter hack no longer working properly?

This mainly affects Essence, Fossils, and compacted items. Some of these items no longer work in the factories related to #495

Protonull commented 1 month ago

Right, just went about investigating this and we have an annoying problem. When this issue was opened (on 1.16.5), setting an item's display name via itemMeta.displayName(Component.text("Hello, World!")) would yield the following NBT:

{
    "Name": '{"text":"Hello, World!"}'
}

Whereas, itemMeta.setDisplayName("Hello, World!") would yield this NBT:

{
    "Name": '{"text":"","extra":[{"text":"Hello, World!"}]}'
}

However, it seems that Minecraft has done some optimisations because components in NBT are now (in 1.20.4) looking a lot like their pre-1.13 selves, where itemMeta.displayName(Component.text("Hello, World!")) will yield the following NBT:

{
    "Name": 'Hello, World!'
}

And itemMeta.setDisplayName("Hello, World!") yields this NBT:

{
    "Name": '{"text":"","extra":["Hello, World!"]}'
}

This seems like an easy fix, right? Just do Component.empty().append(displayName), except that produces this NBT:

{
    "Name": '{"extra":["Hello, World!"],"text":""}'
}

Despite these being identical JSON objects, they are not identical strings... and they are stored on items as serialised strings. I'm not sure it's possible to fix this issue. It may be worth hard-upgrading items to 1.20.4 components instead. However, this is under the assumption that we want a ItemMetaConverterHack-type solution. But given how these NBT structures keep changing for ostensibly the same text, I think it might be worth moving away from stored display names and lore and instead using the approach in https://github.com/CivMC/Civ/pull/398 where these things are added at network-time.