Support sort on NBT data if everything else is equal
Opened this issue ยท 4 comments
This will allow to sort i.e. a chest of enchanted books, or a chest full of enchanted swords.
There should also be a config option to disable it.
See #8, support for general NBT data is not possible because it is a freeform data structure and can hold arbitrary data. Support has to be done for specific uses of it [eg. Enchantments] separately.
I know you closed this issue, but wouldn't it be possible for the user to define the sort key in the config file? That way, you could implement a general NBT comparer that takes a key to sort on, such as:
"tag/ench/id"
You could then make another rule that sorts on:
"tag/ench/lvl"
when the previous is equal.
As far as I can tell there is no such thing as a 'default sort key'. Things just end up in whatever order the tree file dictates, with unknown things getting tacked on the end of that list. Granted I still don't completely understand exactly how the sorting works, but I haven't been able to find anything that looks like a 'I don't know an order, use this' yet.
There wouldn't have to be a default sort key, or any ordering at all to the keys in the file. NBT keys are looked up like hash keys. A generic NBT comparer would take a "key specification" string (in some format, for instance, "tag/ench/id"). When comparing two objects, it would then look up that key in each object's NBT blob and compare those values. Since NBT values are well-defined data types (ints, strings, etc.), comparing those values once they're retrieved is straightforward.
So, a method NBTComparer.compare(item1, item2, "tag/ench/id")
would return the comparison of those two integers by looking up the "tag/ench/id" key in each item's NBT blob and comparing those values.