diff options
author | Linnea Gräf <nea@nea.moe> | 2024-05-18 14:57:07 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-05-18 14:57:07 +0200 |
commit | a39f6e9bec3318b2be251570ea7aea29d58b49cb (patch) | |
tree | e7d93e4243c172f80111e18768f5ee7ec19fb3f5 /src/main/kotlin/moe/nea/firmament/features | |
parent | ad09808c25c769be760559e1a597e29e488827bf (diff) | |
download | Firmament-a39f6e9bec3318b2be251570ea7aea29d58b49cb.tar.gz Firmament-a39f6e9bec3318b2be251570ea7aea29d58b49cb.tar.bz2 Firmament-a39f6e9bec3318b2be251570ea7aea29d58b49cb.zip |
Fix item rarity not displaying in npc shops
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt index dde0ddb..de37748 100644 --- a/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt @@ -19,6 +19,9 @@ import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.util.MC import moe.nea.firmament.util.item.loreAccordingToNbt +import moe.nea.firmament.util.lastNotNullOfOrNull +import moe.nea.firmament.util.memoize +import moe.nea.firmament.util.memoizeIdentity import moe.nea.firmament.util.unformattedString object ItemRarityCosmetics : FirmamentFeature { @@ -48,15 +51,19 @@ object ItemRarityCosmetics : FirmamentFeature { val c = Color(it.value.colorValue!!) Triple(c.red / 255F, c.green / 255F, c.blue / 255F) } - private val ItemStack.skyblockLoreRarityColor: Triple<Float, Float, Float>? - get() { - val entry = loreAccordingToNbt.lastOrNull()?.unformattedString ?: "" - return rarityToColor.entries.find { (k, v) -> k in entry }?.value + + private fun getSkyblockRarity0(itemStack: ItemStack): Triple<Float, Float, Float>? { + return itemStack.loreAccordingToNbt.lastNotNullOfOrNull { + val entry = it.unformattedString + rarityToColor.entries.find { (k, v) -> k in entry }?.value } + } + + val getSkyblockRarity = ::getSkyblockRarity0.memoizeIdentity(100) fun drawItemStackRarity(drawContext: DrawContext, x: Int, y: Int, item: ItemStack) { - val (r, g, b) = item.skyblockLoreRarityColor ?: return + val (r, g, b) = getSkyblockRarity(item) ?: return drawContext.drawSprite( x, y, 0, |