aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorVixid <52578495+VixidDev@users.noreply.github.com>2024-04-29 12:28:37 +0100
committerGitHub <noreply@github.com>2024-04-29 13:28:37 +0200
commit5072672495f079d4748872cb258ac5d417ba223c (patch)
tree71c62481277b7ff1f8fbf284a147ef678112ee3d /src/main/java/at/hannibal2/skyhanni
parenta338da23c43719a20da756151bb8de10c8ad8e79 (diff)
downloadskyhanni-5072672495f079d4748872cb258ac5d417ba223c.tar.gz
skyhanni-5072672495f079d4748872cb258ac5d417ba223c.tar.bz2
skyhanni-5072672495f079d4748872cb258ac5d417ba223c.zip
Improvement: Enchant Parsing support for other mods' chat tooltips (#1589)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt
index ac71ecc6a..c8d24092f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt
@@ -109,6 +109,9 @@ object EnchantParser {
val lore = event.getHoverEvent().value.formattedText.split("\n").toMutableList()
+ // Check for any vanilla gray enchants at the top of the tooltip
+ indexOfLastGrayEnchant = accountForAndRemoveGrayEnchants(lore, null)
+
// Since we don't get given an item stack from /show, we pass an empty enchants map and
// use all enchants from the Enchants class instead
parseEnchants(lore, mapOf(), event.component)
@@ -337,16 +340,24 @@ object EnchantParser {
GuiChatHook.replaceOnlyHoverEvent(hoverEvent)
}
- private fun accountForAndRemoveGrayEnchants(loreList: MutableList<String>, item: ItemStack): Int {
- // If the item has no enchantmentTagList then there will be no gray enchants
- if (!item.isEnchanted() || item.enchantmentTagList.tagCount() == 0) return -1
+ /**
+ * Finds where the gray enchants (vanilla) end and optionally remove them from the tooltip.
+ *
+ * Allow for a null item stack in odd situations like when other mods add them in chat components, i.e,
+ * Skytils party finder feature showing a players inventory in chat
+ */
+ private fun accountForAndRemoveGrayEnchants(loreList: MutableList<String>, item: ItemStack?): Int {
+ if (item != null) {
+ // If the item has no enchantmentTagList then there will be no gray enchants
+ if (!item.isEnchanted() || item.enchantmentTagList.tagCount() == 0) return -1
+ }
var lastGrayEnchant = -1
val removeGrayEnchants = config.hideVanillaEnchants.get()
var i = 1
- for (total in 0 until (1 + item.enchantmentTagList.tagCount())) {
- if (i + 1 == loreList.size) break
+ for (total in 0 until 2) { // Using the fact that there should be at most 2 vanilla enchants
+ if (i + 1 >= loreList.size) break // In case the tooltip is very short (i.e, hovering over a short chat component)
val line = loreList[i]
if (grayEnchantPattern.matcher(line).matches()) {
lastGrayEnchant = i