From b6593fcd09be501ededdd795fbdf5a78c1967c8e Mon Sep 17 00:00:00 2001 From: Vixid <52578495+VixidDev@users.noreply.github.com> Date: Sat, 7 Sep 2024 17:53:42 +0100 Subject: Fix: Merged enchant books tooltip being overwritten (+ backend) (#2454) --- .../features/misc/items/enchants/Enchant.kt | 9 ++++++--- .../features/misc/items/enchants/EnchantParser.kt | 23 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt index 8058fc223..286560c73 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt @@ -3,13 +3,15 @@ package at.hannibal2.skyhanni.features.misc.items.enchants import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.features.chroma.ChromaManager import at.hannibal2.skyhanni.utils.ItemCategory +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull -import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import com.google.gson.annotations.Expose import io.github.notenoughupdates.moulconfig.observer.Property -import net.minecraft.item.ItemStack import java.util.TreeSet +import net.minecraft.item.ItemStack open class Enchant : Comparable { @Expose @@ -64,7 +66,8 @@ open class Enchant : Comparable { val config = SkyHanniMod.feature.inventory.enchantParsing val itemCategory = itemStack?.getItemCategoryOrNull() - val itemName = itemStack?.itemNameWithoutColor + val internalName = itemStack?.getInternalNameOrNull() + val itemName = internalName?.itemName?.removeColor() if (this.nbtName == "efficiency") { // If the item is a Stonk, or a non-mining tool with Efficiency 5 (whilst not being a Promising Shovel), 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 f3d7e8017..66c4c0407 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 @@ -19,8 +19,10 @@ import at.hannibal2.skyhanni.utils.ItemUtils.isEnchanted import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments +import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getExtraAttributes import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import java.lang.ArithmeticException import net.minecraft.event.HoverEvent import net.minecraft.item.ItemStack import net.minecraft.util.ChatComponentText @@ -202,7 +204,26 @@ object EnchantParser { val insertEnchants: MutableList = mutableListOf() // Format enchants based on format config option - formatEnchants(insertEnchants) + try { + formatEnchants(insertEnchants) + } catch (e: ArithmeticException) { + ErrorManager.logErrorWithData( + e, + "Item has enchants in nbt but none were found?", + "item" to currentItem, + "loreList" to loreList, + "nbt" to currentItem?.getExtraAttributes() + ) + return + } catch (e: ConcurrentModificationException) { + ErrorManager.logErrorWithData( + e, + "ConcurrentModificationException whilst formatting enchants", + "loreList" to loreList, + "format" to config.format.get(), + "orderedEnchants" to orderedEnchants + ) + } // Add our parsed enchants back into the lore loreList.addAll(startEnchant, insertEnchants) -- cgit