diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-23 10:13:46 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-23 10:13:46 +0200 |
commit | 03a953fdd85d1465e422b6ef11ca222d30ac5eaf (patch) | |
tree | 9e1d92e5f98e982923f2513d60cce85026710b0c /src/main/java/at/hannibal2 | |
parent | 18382c67a2c13342a64ea7838f96f0592f5e673c (diff) | |
download | skyhanni-03a953fdd85d1465e422b6ef11ca222d30ac5eaf.tar.gz skyhanni-03a953fdd85d1465e422b6ef11ca222d30ac5eaf.tar.bz2 skyhanni-03a953fdd85d1465e422b6ef11ca222d30ac5eaf.zip |
Fixed item rarity problems
Diffstat (limited to 'src/main/java/at/hannibal2')
4 files changed, 44 insertions, 27 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt index b0da49b33..077945455 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorColorNames import at.hannibal2.skyhanni.utils.* 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.name import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -272,6 +273,9 @@ class SkyHanniDebugsAndTests { val internalName = itemStack.getInternalName() if ((internalName == NEUInternalName.NONE) && !config.showEmptyNames) return event.toolTip.add("Internal Name: '${internalName.asString()}'") + + val rarity = itemStack.getItemRarityOrNull(logError = false) ?: return + event.toolTip.add("rarity: $rarity") } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CachedItemData.kt b/src/main/java/at/hannibal2/skyhanni/utils/CachedItemData.kt index b9beea397..8f05d64ec 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CachedItemData.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CachedItemData.kt @@ -6,4 +6,6 @@ data class CachedItemData( /** -1 = not loaded */ var sackInASack: Int? = -1, /** null = not loaded */ var riftTransferable: Boolean? = null, /** null = not loaded */ var riftExportable: Boolean? = null, + /** null = not loaded */ var itemRarityLastCheck: Long = 0L, // Cant use SimpleTimeMark here + /** null = not loaded */ var itemRarity: LorenzRarity? = null, )
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index fd2ca66e1..10fd389d9 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.test.command.CopyErrorCommand import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark +import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.cachedData import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated import at.hannibal2.skyhanni.utils.StringUtils.matchRegex import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -13,6 +15,7 @@ import net.minecraft.init.Items import net.minecraft.item.ItemStack import net.minecraftforge.common.util.Constants import java.util.* +import kotlin.time.Duration.Companion.seconds object ItemUtils { @@ -155,38 +158,27 @@ object ItemUtils { fun ItemStack.getItemRarityOrCommon() = getItemRarityOrNull() ?: LorenzRarity.COMMON - fun ItemStack.getItemRarityOrNull(): LorenzRarity? { + fun ItemStack.getItemRarityOrNull(logError: Boolean = true): LorenzRarity? { + val data = cachedData + if (data.itemRarityLastCheck.asTimeMark().passedSince() < 1.seconds) { + return data.itemRarity + } + data.itemRarityLastCheck = SimpleTimeMark.now().toMillis() + + if (isPet(cleanName())) { return getPetRarity(this) } - val lore = getLore() - var lastLine = lore.lastOrNull() ?: return null - if (lastLine == "§eClick to inspect!") { - // Assuming inside ah browser - val index = lore.indexOfFirst { it.startsWith("§7Seller: ") } - 2 - if (index > 0) { - lastLine = lore[index] - } - } - return when (lastLine.take(4)) { - "§f§l" -> LorenzRarity.COMMON - "§a§l" -> LorenzRarity.UNCOMMON - "§9§l" -> LorenzRarity.RARE - "§5§l" -> LorenzRarity.EPIC - "§6§l" -> LorenzRarity.LEGENDARY - "§d§l" -> LorenzRarity.MYTHIC - "§b§l" -> LorenzRarity.DIVINE - "§4§l" -> LorenzRarity.SUPREME - "§c§l" -> LorenzRarity.SPECIAL - else -> { - CopyErrorCommand.logErrorState( - "Could not read rarity for item $name", - "getItemRarityOrNull not found for: ${getInternalName()}, name:'$name', lastLine:'$lastLine'" - ) - return null - } + val rarity = LorenzRarity.readItemRarity(this) + data.itemRarity = rarity + if (rarity == null && logError) { + CopyErrorCommand.logErrorState( + "Could not read rarity for item $name", + "getItemRarityOrNull not found for: ${getInternalName()}, name:'$name''" + ) } + return rarity } //extra method for shorter name and kotlin nullability logic diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt index 4af8f7e2f..4889bdd04 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt @@ -1,6 +1,8 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.test.command.CopyErrorCommand
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import net.minecraft.item.ItemStack
// TODO: replace id with ordinal
@@ -17,6 +19,12 @@ enum class LorenzRarity(val color: LorenzColor, val id: Int) { VERY_SPECIAL(LorenzColor.RED, 9),
;
+ private val chatColorCode by lazy { color.getChatColor() }
+ private val normalName by lazy { "$chatColorCode§l$name" }
+ private val recombName by lazy { "$chatColorCode§l§ka§r $chatColorCode§l$chatColorCode§l$name" }
+
+ //§d§l§ka§r §d§l§d§lMYTHIC
+
fun oneBelow(logError: Boolean = true): LorenzRarity? {
val rarityBelow = getById(ordinal - 1)
if (rarityBelow == null && logError) {
@@ -41,6 +49,17 @@ enum class LorenzRarity(val color: LorenzColor, val id: Int) { companion object {
fun getById(id: Int) = entries.firstOrNull { it.ordinal == id }
+
+ fun readItemRarity(itemStack: ItemStack): LorenzRarity? {
+ for (line in itemStack.getLore()) {
+ for (rarity in LorenzRarity.entries) {
+ if (line.startsWith(rarity.normalName) || line.startsWith(rarity.recombName)) {
+ return rarity
+ }
+ }
+ }
+ return null
+ }
}
}
\ No newline at end of file |