NBTUtil item hashes changing after being pushed/inserted into containers
Gungadean opened this issue · 1 comments
Minecraft Version
1.19.x
Version
1.100.10
Details
When the items are transferred to a different inventory via pipes, vanilla hoppers or CC's chest.pushItems() function, ordering of the item's NBT data can shifted changing the hash data. It only seems that some items are affected by this and it's not exclusively modded vs vanilla. Currently using All The Mods 8 v0.1.8. I did some testing in All The Mods 7 v0.4.34 and there were no issues with NBT reordering. Although this appears to be an issue with either Forge or Minecraft's code with inserting items, with JSON being an unordered set of data, it may be worthwhile to sort the CompoundTag keys of an item before generating a hash as there is potential for other mods to potentially mess with the order of NBT.
Screenshots:
Above picture shows me using the command /advancedperipherals getItemHash command (which calls the CC function) and minecraft's /data entity @s SelectedItem command twice, before and after transfer. As can be seen in the picture, specifically the builder tag's coordinates get shuffled around when the item is transferred.
I also made a simple program to transfer items between and getting NBT data before and after the transfer. (code: https://pastebin.com/N6zvNRvR)
Thanks for the report! I've pushed a commit to sort keys, as you mentioned.
Worth noting that there's never going to be a perfect one-to-one mapping between "identical" items and NBT hash1, but definitely agreed it shouldn't be changing mid-transfer!
Footnotes
-
For instance, if two items have the same enchantments but in different orders, the hash will be different. ↩