feat: support searching and sorting items by enchantment name and level - #17
Conversation
…e 3", "fortune iii", etc) - Update enchantment matching logic to parse search queries word-by-word. - Add Roman numeral conversion to support Minecraft's native level formatting (I, II, III, etc.) - hardcoded for now - Ensure both regular enchanted items and Enchanted Books are correctly filtered by their specific enchantment levels.
- Add `getSortName` utility to append the primary enchantment name to the base item name and and zero-padded level for sorting. - Ensures enchanted books remain grouped together under "Enchanted Book" while sorting logically by their specific enchantment (e.g., "Enchanted Book - Mending" before "Enchanted Book - Sharpness"). - Ensures enchanted books display in ascending order of level (e.g. Efficiency IV appears after Efficiency II) - Applies to both stored enchants (books) and regular enchanted gear.
|
Thanks, i really like and missed this feature but was too lazy to add this in. While looking at this i found that in formatEnchantmentName word.substring(1) is appended twice which could maybe double the tail of every word like "sharpness" → "Ssharpnessharpness". Did you check that? |
|
Made the fix to the formatEnchantmentName function, not sure what I was thinking when I wrote that. I will attempt to add unit tests soon(ish), when I get the chance, I'm rather swamped with other work currently and my initial attempts aren't getting anywhere. |
…ent helpers (#22) Companion follow-up to #17. The substring-duplicate bug fix landed via ags816710's PR; this adds the regression coverage that was prepared alongside it but got lost in the rebasing race. - Package-private matchesEnchantment(String, int, String) and formatEnchantmentName(String) overloads so the helpers can be unit-tested without instantiating Enchantment (whose static initializer requires a live Bukkit server). - Move formatNumber up next to applyCustomModelData so related formatting helpers cluster together (was buried at the end of the file). - New ItemUtilsTest with 24 cases covering formatEnchantmentName, toRoman, and matchesEnchantment across name/level/raw-key/case/whitespace paths. Local mvn test is green: 30/30 (24 new + 6 existing NetworkTest).
|
Hey, just wanted to say sorry for jumping in and doing the tests myself :D I know you said you wanted to do them but i had some time and wanted to get this added. Thanks again for the PRs, youre actually my first ever contributor, which is pretty cool. The changes are merged now and will ship with version 1.5.0 whenever I find the time to release it. |
Adds the ability to search for items in the terminal by their enchantment names and levels (e.g., typing "Fortune 3" or "Sharpness IV"). It also updates the alphabetical sorting logic so that enchanted books and gear are grouped by their base name, but sorted logically by their specific enchantment and level (e.g., Sharpness I appears before Sharpness V).
Roman numerals are currently hardcoded from I -> X, might change this to something better if needed though.