aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-09-30 00:09:40 +0200
committernea <nea@nea.moe>2023-09-30 00:10:54 +0200
commit040dbca01439e6fd6afbb911beb09d73d2ee0d1e (patch)
tree26775c922c501db08018306d51559faefca8d9d6 /src/main/kotlin/moe/nea/firmament/features
parentf89135db7e500571231721ac8d5b0ffff63469df (diff)
downloadFirmament-040dbca01439e6fd6afbb911beb09d73d2ee0d1e.tar.gz
Firmament-040dbca01439e6fd6afbb911beb09d73d2ee0d1e.tar.bz2
Firmament-040dbca01439e6fd6afbb911beb09d73d2ee0d1e.zip
Add item rarity backgrounds
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt2
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt80
2 files changed, 82 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
index 72f1056..b9d343c 100644
--- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
@@ -18,6 +18,7 @@ import moe.nea.firmament.features.debug.PowerUserTools
import moe.nea.firmament.features.fixes.CompatibliltyFeatures
import moe.nea.firmament.features.fixes.Fixes
import moe.nea.firmament.features.inventory.CraftingOverlay
+import moe.nea.firmament.features.inventory.ItemRarityCosmetics
import moe.nea.firmament.features.inventory.PriceData
import moe.nea.firmament.features.inventory.SaveCursorPosition
import moe.nea.firmament.features.inventory.SlotLocking
@@ -59,6 +60,7 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature
loadFeature(CustomSkyBlockTextures)
loadFeature(PriceData)
loadFeature(Fixes)
+ loadFeature(ItemRarityCosmetics)
if (Firmament.DEBUG) {
loadFeature(DeveloperFeatures)
loadFeature(DebugView)
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt
new file mode 100644
index 0000000..2017b40
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt
@@ -0,0 +1,80 @@
+/*
+ * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.features.inventory
+
+import java.awt.Color
+import net.minecraft.client.gui.DrawContext
+import net.minecraft.item.ItemStack
+import net.minecraft.nbt.NbtElement
+import net.minecraft.util.Formatting
+import net.minecraft.util.Identifier
+import moe.nea.firmament.events.HotbarItemRenderEvent
+import moe.nea.firmament.events.SlotRenderEvents
+import moe.nea.firmament.features.FirmamentFeature
+import moe.nea.firmament.gui.config.ManagedConfig
+import moe.nea.firmament.util.MC
+
+object ItemRarityCosmetics : FirmamentFeature {
+ 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
+
+ private val rarityToColor = mapOf(
+ "COMMON" to Formatting.WHITE,
+ "UNCOMMON" to Formatting.GREEN,
+ "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)
+ }
+ private val ItemStack.skyblockLoreRarityColor: Triple<Float, Float, Float>?
+ get() {
+ val lore =
+ getOrCreateSubNbt(ItemStack.DISPLAY_KEY).getList(ItemStack.LORE_KEY, NbtElement.STRING_TYPE.toInt())
+ val entry = lore.getString(lore.size - 1)
+ return rarityToColor.entries.find { (k, v) -> k in entry }?.value
+ }
+
+
+ fun drawItemStackRarity(drawContext: DrawContext, x: Int, y: Int, item: ItemStack) {
+ val (r, g, b) = item.skyblockLoreRarityColor ?: return
+ drawContext.drawSprite(
+ x, y,
+ 0,
+ 16, 16,
+ MC.guiAtlasManager.getSprite(Identifier("firmament:item_rarity_background")),
+ r, g, b, 1F
+ )
+ }
+
+ override fun onLoad() {
+ HotbarItemRenderEvent.subscribe {
+ if (!TConfig.showItemRarityInHotbar) return@subscribe
+ val stack = it.item
+ drawItemStackRarity(it.context, it.x, it.y, stack)
+ }
+ SlotRenderEvents.Before.subscribe {
+ if (!TConfig.showItemRarityBackground) return@subscribe
+ val stack = it.slot.stack ?: return@subscribe
+ drawItemStackRarity(it.context, it.slot.x, it.slot.y, stack)
+ }
+ }
+}