From 95de7887639e35c0b4974b8c61423a0a2aa9eb8f Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Mon, 21 Oct 2024 16:40:26 -0400 Subject: Fix: Estimated Item Value OpenGL Error & Data Dump NBT (#2787) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/misc/items/EstimatedItemValue.kt | 73 +++++++++++++--------- .../misc/items/EstimatedItemValueCalculator.kt | 7 +++ .../skyhanni/test/command/CopyItemCommand.kt | 24 ++----- .../java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 18 ++++++ 4 files changed, 71 insertions(+), 51 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt index 9ad44445d..8584d0b49 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt @@ -14,7 +14,6 @@ import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.events.item.ItemHoverEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager -import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.ConditionalUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull @@ -28,7 +27,8 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat -import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables +import at.hannibal2.skyhanni.utils.renderables.Renderable import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer import net.minecraft.client.Minecraft import net.minecraft.init.Items @@ -41,8 +41,8 @@ import kotlin.math.roundToLong object EstimatedItemValue { val config: EstimatedItemValueConfig get() = SkyHanniMod.feature.inventory.estimatedItemValues - private var display = emptyList>() - private val cache = mutableMapOf>>() + private var display = emptyList() + private val cache = mutableMapOf>() private var lastToolTipTime = 0L var gemstoneUnlockCosts = HashMap>>() var bookBundleAmount = mapOf() @@ -101,7 +101,19 @@ object EstimatedItemValue { } } - config.itemPriceDataPos.renderStringsAndItems(display, posLabel = "Estimated Item Value") + try { + config.itemPriceDataPos.renderRenderables(display, posLabel = "Estimated Item Value") + } catch (ex: RuntimeException) { + // "No OpenGL context found in the current thread." - caused indiscriminately by any other mod + // that tries to over-render the tooltip, and is not explicitly something we can solve here? + // TODO start a deep sea activity: read mixin dumps, pinpoint the culprit, write over engineered workaround + if (ex.message?.contains("No OpenGL context found in the current thread.") == true) return + ErrorManager.logErrorWithData( + ex, "Error in Estimated Item Value renderer", + "display" to display, + "posLabel" to "Estimated Item Value" + ) + } } @SubscribeEvent @@ -188,31 +200,30 @@ object EstimatedItemValue { lastToolTipTime = System.currentTimeMillis() } - private fun draw(stack: ItemStack): List> { - val internalName = stack.getInternalNameOrNull() ?: return listOf() - - // Stats Breakdown - val name = stack.name - if (name == "§6☘ Category: Item Ability (Passive)") return listOf() - if (name.contains("Salesperson")) return listOf() - - // Autopet rule > Create Rule - if (!InventoryUtils.isSlotInPlayerInventory(stack)) { - if (InventoryUtils.openInventoryName() == "Choose a wardrobe slot") return listOf() - } + private fun ItemStack.shouldIgnoreDraw(): Boolean { + this.getInternalNameOrNull()?.let { internalName -> + val name = this.name + return ( + this.item == Items.enchanted_book || + name.contains("Salesperson") || + name == "§6☘ Category: Item Ability (Passive)" || + internalName.isRune() || + internalName.startsWith("ULTIMATE_ULTIMATE_") || + internalName.startsWith("CATACOMBS_PASS_") || + internalName.startsWith("MASTER_CATACOMBS_PASS_") || + internalName.startsWith("MAP-") || + internalName.contains("UNIQUE_RUNE") || + internalName.contains("WISP_POTION") || + ( + !InventoryUtils.isSlotInPlayerInventory(this) && + InventoryUtils.openInventoryName() == "Choose a wardrobe slot" + ) + ) + } ?: return true + } - // FIX neu item list - if (internalName.startsWith("ULTIMATE_ULTIMATE_")) return listOf() - // We don't need this feature to work on books at all - if (stack.item == Items.enchanted_book) return listOf() - // Block catacombs items in mort inventory - if (internalName.startsWith("CATACOMBS_PASS_") || internalName.startsWith("MASTER_CATACOMBS_PASS_")) return listOf() - // Blocks the dungeon map - if (internalName.startsWith("MAP-")) return listOf() - // Hides the rune item - if (internalName.isRune()) return listOf() - if (internalName.contains("UNIQUE_RUNE")) return listOf() - if (internalName.contains("WISP_POTION")) return listOf() + private fun draw(stack: ItemStack): List { + if (stack.shouldIgnoreDraw()) return listOf() val list = mutableListOf() list.add("§aEstimated Item Value:") @@ -228,9 +239,9 @@ object EstimatedItemValue { } list.add("§aTotal: §6§l$numberFormat coins") - val newDisplay = mutableListOf>() + val newDisplay = mutableListOf() for (line in list) { - newDisplay.addAsSingletonList(line) + newDisplay.add(Renderable.string(line)) } return newDisplay } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt index 3af9bca26..40d424f85 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt @@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.getReadableNBTDump import at.hannibal2.skyhanni.utils.ItemUtils.isRune import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor @@ -254,6 +255,7 @@ object EstimatedItemValueCalculator { "internal name" to stack.getInternalName(), "itemRarity" to itemRarity, "item name" to stack.name, + "item nbt" to stack.readNbtDump(), ) return null } @@ -270,6 +272,7 @@ object EstimatedItemValueCalculator { "internal name" to stack.getInternalName(), "item name" to stack.name, "reforgeStone" to reforgeStone, + "item nbt" to stack.readNbtDump(), ) null } @@ -846,6 +849,9 @@ object EstimatedItemValueCalculator { return totalPrice } + private fun ItemStack.readNbtDump() = tagCompound?.getReadableNBTDump(includeLore = true)?.joinToString("\n") + ?: "no tag compound" + private fun addGemstoneSlotUnlockCost(stack: ItemStack, list: MutableList): Double { val internalName = stack.getInternalName() @@ -865,6 +871,7 @@ object EstimatedItemValueCalculator { "internal name" to internalName, "gemstoneUnlockCosts" to EstimatedItemValue.gemstoneUnlockCosts, "item name" to stack.name, + "item nbt" to stack.readNbtDump(), ) return 0.0 } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt index 9b23b47a9..15156ca0f 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt @@ -4,10 +4,10 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.getReadableNBTDump import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getMinecraftId import net.minecraft.item.ItemStack -import net.minecraft.nbt.NBTTagCompound object CopyItemCommand { @@ -20,21 +20,6 @@ object CopyItemCommand { copyItemToClipboard(itemStack) } - private fun recurseTag(compound: NBTTagCompound, text: String, list: MutableList) { - for (s in compound.keySet) { - if (s == "Lore") continue - val tag = compound.getTag(s) - - if (tag !is NBTTagCompound) { - list.add("$text$s: $tag") - } else { - val element = compound.getCompoundTag(s) - list.add("$text$s:") - recurseTag(element, "$text ", list) - } - } - } - fun copyItemToClipboard(itemStack: ItemStack) { val resultList = mutableListOf() resultList.add(itemStack.getInternalName().toString()) @@ -46,10 +31,9 @@ object CopyItemCommand { } resultList.add("") resultList.add("getTagCompound") - if (itemStack.hasTagCompound()) { - val tagCompound = itemStack.tagCompound - recurseTag(tagCompound, " ", resultList) - } + itemStack.tagCompound?.let { + resultList.addAll(it.getReadableNBTDump()) + } ?: resultList.add("no tag compound") val string = resultList.joinToString("\n") OSUtils.copyToClipboard(string) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 2fda980ea..b06d84f50 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -61,6 +61,24 @@ object ItemUtils { return list } + fun NBTTagCompound?.getReadableNBTDump(initSeparator: String = " ", includeLore: Boolean = false): List { + this ?: return emptyList() + val tagList = mutableListOf() + for (s in this.keySet) { + if (s == "Lore" && !includeLore) continue + val tag = this.getTag(s) + + if (tag !is NBTTagCompound) { + tagList.add("$initSeparator$s: $tag") + } else { + val element = this.getCompoundTag(s) + tagList.add("$initSeparator$s:") + tagList.addAll(element.getReadableNBTDump("$initSeparator ", includeLore)) + } + } + return tagList + } + fun getDisplayName(compound: NBTTagCompound?): String? { compound ?: return null val name = compound.getCompoundTag("display").getString("Name") -- cgit