aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Cole <40234707+DavidArthurCole@users.noreply.github.com>2024-10-21 16:40:26 -0400
committerGitHub <noreply@github.com>2024-10-21 22:40:26 +0200
commit95de7887639e35c0b4974b8c61423a0a2aa9eb8f (patch)
tree3e7a68cfd9147d44671e7bc274dd3a553e659369
parentbbc600c4d0b462928077c4f90ed6a9dc62e3a050 (diff)
downloadSkyHanni-95de7887639e35c0b4974b8c61423a0a2aa9eb8f.tar.gz
SkyHanni-95de7887639e35c0b4974b8c61423a0a2aa9eb8f.tar.bz2
SkyHanni-95de7887639e35c0b4974b8c61423a0a2aa9eb8f.zip
Fix: Estimated Item Value OpenGL Error & Data Dump NBT (#2787)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt73
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt24
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt18
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<List<Any>>()
- private val cache = mutableMapOf<ItemStack, List<List<Any>>>()
+ private var display = emptyList<Renderable>()
+ private val cache = mutableMapOf<ItemStack, List<Renderable>>()
private var lastToolTipTime = 0L
var gemstoneUnlockCosts = HashMap<NEUInternalName, HashMap<String, List<String>>>()
var bookBundleAmount = mapOf<String, Int>()
@@ -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<List<Any>> {
- 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<Renderable> {
+ if (stack.shouldIgnoreDraw()) return listOf()
val list = mutableListOf<String>()
list.add("§aEstimated Item Value:")
@@ -228,9 +239,9 @@ object EstimatedItemValue {
}
list.add("§aTotal: §6§l$numberFormat coins")
- val newDisplay = mutableListOf<List<Any>>()
+ val newDisplay = mutableListOf<Renderable>()
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<String>): 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<String>) {
- 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<String>()
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<String> {
+ this ?: return emptyList()
+ val tagList = mutableListOf<String>()
+ 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")