aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt25
1 files changed, 22 insertions, 3 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 baf84aff7..420a1a851 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
@@ -9,6 +9,8 @@ import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.mixins.hooks.GuiChatHook
import at.hannibal2.skyhanni.utils.ConditionalUtils
+import at.hannibal2.skyhanni.utils.ItemCategory
+import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.isEnchanted
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
@@ -37,6 +39,8 @@ object EnchantParser {
"grayenchants", "^(Respiration|Aqua Affinity|Depth Strider|Efficiency).*"
)
+ private var currentItem: ItemStack? = null
+
private var indexOfLastGrayEnchant = -1
private var startEnchant = -1
private var endEnchant = -1
@@ -84,6 +88,8 @@ object EnchantParser {
// If enchants doesn't have any enchant data then we have no data to parse enchants correctly
if (!isEnabled() || !this.enchants.hasEnchantData()) return
+ currentItem = event.itemStack
+
// The enchants we expect to find in the lore, found from the items NBT data
val enchants = event.itemStack.getEnchantments() ?: return
@@ -116,7 +122,11 @@ object EnchantParser {
// Check if the lore is already cached so continuous hover isn't 1 fps
if (loreCache.isCached(loreList)) {
loreList.clear()
- loreList.addAll(loreCache.cachedLoreAfter)
+ if (loreCache.cachedLoreAfter.isNotEmpty()) {
+ loreList.addAll(loreCache.cachedLoreAfter)
+ } else {
+ loreList.addAll(loreCache.cachedLoreBefore)
+ }
// Need to still set replacement component even if its cached
if (chatComponent != null) editChatComponent(chatComponent, loreList)
return
@@ -147,11 +157,16 @@ object EnchantParser {
// If we have color parsing off and hide enchant descriptions on, remove them and return from method
if (!config.colorParsing.get()) {
if (config.hideEnchantDescriptions.get()) {
+ if (itemIsBook()) {
+ loreCache.updateAfter(loreList)
+ return
+ }
loreList.removeAll(loreLines)
loreCache.updateAfter(loreList)
if (chatComponent != null) editChatComponent(chatComponent, loreList)
return
}
+ loreCache.updateAfter(loreList)
return
}
@@ -261,7 +276,7 @@ object EnchantParser {
insertEnchants.add(builder.toString())
// This will only add enchant descriptions if there were any to begin with
- if (!config.hideEnchantDescriptions.get()) insertEnchants.addAll(orderedEnchant.getLore())
+ if (!config.hideEnchantDescriptions.get() || itemIsBook()) insertEnchants.addAll(orderedEnchant.getLore())
builder = StringBuilder()
}
@@ -290,7 +305,7 @@ object EnchantParser {
}
private fun stackedFormatting(insertEnchants: MutableList<String>) {
- if (!config.hideEnchantDescriptions.get()) {
+ if (!config.hideEnchantDescriptions.get() || itemIsBook()) {
for (enchant: FormattedEnchant in orderedEnchants) {
insertEnchants.add(enchant.getFormattedString())
insertEnchants.addAll(enchant.getLore())
@@ -344,6 +359,10 @@ object EnchantParser {
return if (removeGrayEnchants) -1 else lastGrayEnchant
}
+ private fun itemIsBook() : Boolean {
+ return currentItem?.getItemCategoryOrNull() == ItemCategory.ENCHANTED_BOOK
+ }
+
// We don't check if the main toggle here since we still need to go into
// the parseEnchants method to deal with hiding vanilla enchants
// and enchant descriptions