diff options
Diffstat (limited to 'src/main/kotlin/features/inventory/ItemRarityCosmetics.kt')
-rw-r--r-- | src/main/kotlin/features/inventory/ItemRarityCosmetics.kt | 129 |
1 files changed, 74 insertions, 55 deletions
diff --git a/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt b/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt index 424f13b..cc2c003 100644 --- a/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt +++ b/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt @@ -1,5 +1,3 @@ - - package moe.nea.firmament.features.inventory import java.awt.Color @@ -11,74 +9,95 @@ import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.HotbarItemRenderEvent import moe.nea.firmament.events.SlotRenderEvents import moe.nea.firmament.features.FirmamentFeature +import moe.nea.firmament.features.fixes.CompatibliltyFeatures import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.util.MC -import moe.nea.firmament.util.mc.loreAccordingToNbt +import moe.nea.firmament.util.SBData import moe.nea.firmament.util.collections.lastNotNullOfOrNull import moe.nea.firmament.util.collections.memoizeIdentity +import moe.nea.firmament.util.mc.loreAccordingToNbt import moe.nea.firmament.util.unformattedString object ItemRarityCosmetics : FirmamentFeature { - override val identifier: String - get() = "item-rarity-cosmetics" + override val identifier: String + get() = "item-rarity-cosmetics" + + object TConfig : ManagedConfig(identifier) { + val showItemRarityBackground by toggle("background") { false } + val showItemRarityInHotbar by toggle("background-hotbar") { false } + } + + override val config: ManagedConfig + get() = TConfig - object TConfig : ManagedConfig(identifier) { - val showItemRarityBackground by toggle("background") { false } - val showItemRarityInHotbar by toggle("background-hotbar") { false } - } + private val rarityToColor = mapOf( + "UNCOMMON" to Formatting.GREEN, + "COMMON" to Formatting.WHITE, + "RARE" to Formatting.DARK_BLUE, + "EPIC" to Formatting.DARK_PURPLE, + "LEGENDARY" to Formatting.GOLD, + "LEGENJERRY" to Formatting.GOLD, + "MYTHIC" to Formatting.LIGHT_PURPLE, + "DIVINE" to Formatting.BLUE, + "SPECIAL" to Formatting.DARK_RED, + "SUPREME" to Formatting.DARK_RED, + ).mapValues { + val c = Color(it.value.colorValue!!) + Triple(c.red / 255F, c.green / 255F, c.blue / 255F) + } - override val config: ManagedConfig - get() = TConfig + private val tabCubeRarityToColor = mapOf( + "COMMON" to Color.WHITE, + "RELIC" to Color(255, 23, 130), + "BOSS DROP" to Color.YELLOW, + "MYTHIC" to Color.ORANGE, + "RARE" to Color.BLUE, + "UNCOMMON" to Color.GREEN, + "LEGENDARY" to Color(250, 240, 130), + "EPIC" to Color(180, 30, 180), + "ULTIMATE" to Color(255, 130, 0), + "ᴠᴏᴜᴄʜᴇʀ" to Color(80, 120, 255) + ).mapValues { + val c = it.value + Triple(c.red / 255F, c.green / 255F, c.blue / 255F) + } - private val rarityToColor = mapOf( - "UNCOMMON" to Formatting.GREEN, - "COMMON" to Formatting.WHITE, - "RARE" to Formatting.DARK_BLUE, - "EPIC" to Formatting.DARK_PURPLE, - "LEGENDARY" to Formatting.GOLD, - "LEGENJERRY" to Formatting.GOLD, - "MYTHIC" to Formatting.LIGHT_PURPLE, - "DIVINE" to Formatting.BLUE, - "SPECIAL" to Formatting.DARK_RED, - "SUPREME" to Formatting.DARK_RED, - ).mapValues { - val c = Color(it.value.colorValue!!) - Triple(c.red / 255F, c.green / 255F, c.blue / 255F) - } + val currentRarities get() = if (CompatibliltyFeatures.TConfig.tapCube && SBData.isTabCube) tabCubeRarityToColor else rarityToColor - 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 - } - } + private fun getSkyblockRarity0(itemStack: ItemStack): Triple<Float, Float, Float>? { + return itemStack.loreAccordingToNbt.lastNotNullOfOrNull { + val entry = it.unformattedString + currentRarities.entries.find { (k, v) -> k in entry }?.value + } + } - val getSkyblockRarity = ::getSkyblockRarity0.memoizeIdentity(100) + // TODO: replace with weak cache + val getSkyblockRarity = ::getSkyblockRarity0.memoizeIdentity(100) - fun drawItemStackRarity(drawContext: DrawContext, x: Int, y: Int, item: ItemStack) { - val (r, g, b) = getSkyblockRarity(item) ?: return - drawContext.drawSprite( - x, y, - 0, - 16, 16, - MC.guiAtlasManager.getSprite(Identifier.of("firmament:item_rarity_background")), - r, g, b, 1F - ) - } + fun drawItemStackRarity(drawContext: DrawContext, x: Int, y: Int, item: ItemStack) { + val (r, g, b) = getSkyblockRarity(item) ?: return + drawContext.drawSprite( + x, y, + 0, + 16, 16, + MC.guiAtlasManager.getSprite(Identifier.of("firmament:item_rarity_background")), + r, g, b, 1F + ) + } - @Subscribe - fun onRenderSlot(it: SlotRenderEvents.Before) { - if (!TConfig.showItemRarityBackground) return - val stack = it.slot.stack ?: return - drawItemStackRarity(it.context, it.slot.x, it.slot.y, stack) - } + @Subscribe + fun onRenderSlot(it: SlotRenderEvents.Before) { + if (!TConfig.showItemRarityBackground) return + val stack = it.slot.stack ?: return + drawItemStackRarity(it.context, it.slot.x, it.slot.y, stack) + } - @Subscribe - fun onRenderHotbarItem(it: HotbarItemRenderEvent) { - if (!TConfig.showItemRarityInHotbar) return - val stack = it.item - drawItemStackRarity(it.context, it.x, it.y, stack) - } + @Subscribe + fun onRenderHotbarItem(it: HotbarItemRenderEvent) { + if (!TConfig.showItemRarityInHotbar) return + val stack = it.item + drawItemStackRarity(it.context, it.x, it.y, stack) + } } |