fix: Pets missing an item rarity
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
package moe.nea.firmament.features.inventory
|
package moe.nea.firmament.features.inventory
|
||||||
|
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
@@ -13,74 +11,64 @@ import moe.nea.firmament.events.HotbarItemRenderEvent
|
|||||||
import moe.nea.firmament.events.SlotRenderEvents
|
import moe.nea.firmament.events.SlotRenderEvents
|
||||||
import moe.nea.firmament.features.FirmamentFeature
|
import moe.nea.firmament.features.FirmamentFeature
|
||||||
import moe.nea.firmament.gui.config.ManagedConfig
|
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.collections.lastNotNullOfOrNull
|
import moe.nea.firmament.util.collections.lastNotNullOfOrNull
|
||||||
import moe.nea.firmament.util.collections.memoizeIdentity
|
import moe.nea.firmament.util.collections.memoizeIdentity
|
||||||
import moe.nea.firmament.util.render.drawGuiTexture
|
import moe.nea.firmament.util.mc.loreAccordingToNbt
|
||||||
|
import moe.nea.firmament.util.skyblock.Rarity
|
||||||
import moe.nea.firmament.util.unformattedString
|
import moe.nea.firmament.util.unformattedString
|
||||||
|
|
||||||
object ItemRarityCosmetics : FirmamentFeature {
|
object ItemRarityCosmetics : FirmamentFeature {
|
||||||
override val identifier: String
|
override val identifier: String
|
||||||
get() = "item-rarity-cosmetics"
|
get() = "item-rarity-cosmetics"
|
||||||
|
|
||||||
object TConfig : ManagedConfig(identifier, Category.INVENTORY) {
|
object TConfig : ManagedConfig(identifier, Category.INVENTORY) {
|
||||||
val showItemRarityBackground by toggle("background") { false }
|
val showItemRarityBackground by toggle("background") { false }
|
||||||
val showItemRarityInHotbar by toggle("background-hotbar") { false }
|
val showItemRarityInHotbar by toggle("background-hotbar") { false }
|
||||||
}
|
}
|
||||||
|
|
||||||
override val config: ManagedConfig
|
override val config: ManagedConfig
|
||||||
get() = TConfig
|
get() = TConfig
|
||||||
|
|
||||||
private val rarityToColor = mapOf(
|
private val rarityToColor = mapOf(
|
||||||
"UNCOMMON" to Formatting.GREEN,
|
Rarity.UNCOMMON to Formatting.GREEN,
|
||||||
"COMMON" to Formatting.WHITE,
|
Rarity.COMMON to Formatting.WHITE,
|
||||||
"RARE" to Formatting.DARK_BLUE,
|
Rarity.RARE to Formatting.DARK_BLUE,
|
||||||
"EPIC" to Formatting.DARK_PURPLE,
|
Rarity.EPIC to Formatting.DARK_PURPLE,
|
||||||
"LEGENDARY" to Formatting.GOLD,
|
Rarity.LEGENDARY to Formatting.GOLD,
|
||||||
"LEGENJERRY" to Formatting.GOLD,
|
Rarity.MYTHIC to Formatting.LIGHT_PURPLE,
|
||||||
"MYTHIC" to Formatting.LIGHT_PURPLE,
|
Rarity.DIVINE to Formatting.BLUE,
|
||||||
"DIVINE" to Formatting.BLUE,
|
Rarity.SPECIAL to Formatting.DARK_RED,
|
||||||
"SPECIAL" to Formatting.DARK_RED,
|
Rarity.VERY_SPECIAL to Formatting.DARK_RED,
|
||||||
"SUPREME" to Formatting.DARK_RED,
|
Rarity.SUPREME to Formatting.DARK_RED,
|
||||||
).mapValues {
|
).mapValues {
|
||||||
val c = Color(it.value.colorValue!!)
|
val c = Color(it.value.colorValue!!)
|
||||||
c.rgb
|
c.rgb
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSkyblockRarity0(itemStack: ItemStack): Int? {
|
fun drawItemStackRarity(drawContext: DrawContext, x: Int, y: Int, item: ItemStack) {
|
||||||
return itemStack.loreAccordingToNbt.lastNotNullOfOrNull {
|
val rarity = Rarity.fromItem(item) ?: return
|
||||||
val entry = it.unformattedString
|
val rgb = rarityToColor[rarity] ?: 0xFF00FF80.toInt()
|
||||||
rarityToColor.entries.find { (k, v) -> k in entry }?.value
|
drawContext.drawGuiTexture(
|
||||||
}
|
RenderLayer::getGuiTextured,
|
||||||
}
|
Identifier.of("firmament:item_rarity_background"),
|
||||||
|
x, y,
|
||||||
val getSkyblockRarity = ::getSkyblockRarity0.memoizeIdentity(100)
|
16, 16,
|
||||||
|
rgb
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun drawItemStackRarity(drawContext: DrawContext, x: Int, y: Int, item: ItemStack) {
|
@Subscribe
|
||||||
val rgb = getSkyblockRarity(item) ?: return
|
fun onRenderSlot(it: SlotRenderEvents.Before) {
|
||||||
drawContext.drawGuiTexture(
|
if (!TConfig.showItemRarityBackground) return
|
||||||
RenderLayer::getGuiTextured,
|
val stack = it.slot.stack ?: return
|
||||||
Identifier.of("firmament:item_rarity_background"),
|
drawItemStackRarity(it.context, it.slot.x, it.slot.y, stack)
|
||||||
x, y,
|
}
|
||||||
16, 16,
|
|
||||||
rgb
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
@Subscribe
|
fun onRenderHotbarItem(it: HotbarItemRenderEvent) {
|
||||||
fun onRenderSlot(it: SlotRenderEvents.Before) {
|
if (!TConfig.showItemRarityInHotbar) return
|
||||||
if (!TConfig.showItemRarityBackground) return
|
val stack = it.item
|
||||||
val stack = it.slot.stack ?: return
|
drawItemStackRarity(it.context, it.x, it.y, stack)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import moe.nea.firmament.gui.config.ManagedConfig
|
|||||||
import moe.nea.firmament.util.MC
|
import moe.nea.firmament.util.MC
|
||||||
import moe.nea.firmament.util.ScreenUtil
|
import moe.nea.firmament.util.ScreenUtil
|
||||||
import moe.nea.firmament.util.data.DataHolder
|
import moe.nea.firmament.util.data.DataHolder
|
||||||
import moe.nea.firmament.util.getRectangle
|
import moe.nea.firmament.util.accessors.getRectangle
|
||||||
|
|
||||||
object InventoryButtons : FirmamentFeature {
|
object InventoryButtons : FirmamentFeature {
|
||||||
override val identifier: String
|
override val identifier: String
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ data class HypixelPetInfo(
|
|||||||
val uuid: UUID? = null,
|
val uuid: UUID? = null,
|
||||||
val active: Boolean = false,
|
val active: Boolean = false,
|
||||||
) {
|
) {
|
||||||
val skyblockId get() = SkyblockId("${type.uppercase()};${tier.ordinal}")
|
val skyblockId get() = SkyblockId("${type.uppercase()};${tier.ordinal}") // TODO: is this ordinal set up correctly?
|
||||||
}
|
}
|
||||||
|
|
||||||
private val jsonparser = Json { ignoreUnknownKeys = true }
|
private val jsonparser = Json { ignoreUnknownKeys = true }
|
||||||
@@ -125,8 +125,8 @@ val ItemStack.skyblockUUID: UUID?
|
|||||||
private val petDataCache = WeakCache.memoize<ItemStack, Optional<HypixelPetInfo>>("PetInfo") {
|
private val petDataCache = WeakCache.memoize<ItemStack, Optional<HypixelPetInfo>>("PetInfo") {
|
||||||
val jsonString = it.extraAttributes.getString("petInfo")
|
val jsonString = it.extraAttributes.getString("petInfo")
|
||||||
if (jsonString.isNullOrBlank()) return@memoize Optional.empty()
|
if (jsonString.isNullOrBlank()) return@memoize Optional.empty()
|
||||||
runCatching { jsonparser.decodeFromString<HypixelPetInfo>(jsonString) }
|
ErrorUtil.catch<HypixelPetInfo?>("Could not decode hypixel pet info") { jsonparser.decodeFromString<HypixelPetInfo>(jsonString) }
|
||||||
.getOrElse { null }.intoOptional()
|
.or { null }.intoOptional()
|
||||||
}
|
}
|
||||||
|
|
||||||
val ItemStack.petData: HypixelPetInfo?
|
val ItemStack.petData: HypixelPetInfo?
|
||||||
|
|||||||
9
src/main/kotlin/util/StringUtil.kt
Normal file
9
src/main/kotlin/util/StringUtil.kt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package moe.nea.firmament.util
|
||||||
|
|
||||||
|
object StringUtil {
|
||||||
|
fun String.words(): Sequence<String> {
|
||||||
|
return splitToSequence(" ") // TODO: better boundaries
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Iterable<String>.unwords() = joinToString(" ")
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
package moe.nea.firmament.util
|
package moe.nea.firmament.util.accessors
|
||||||
|
|
||||||
import me.shedaniel.math.Rectangle
|
import me.shedaniel.math.Rectangle
|
||||||
import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
|
import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
|
||||||
21
src/main/kotlin/util/skyblock/ItemType.kt
Normal file
21
src/main/kotlin/util/skyblock/ItemType.kt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package moe.nea.firmament.util.skyblock
|
||||||
|
|
||||||
|
import kotlin.properties.ReadOnlyProperty
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
|
||||||
|
class ItemType(val name: String) {
|
||||||
|
companion object {
|
||||||
|
private val generated = object : ReadOnlyProperty<Any?, ItemType> {
|
||||||
|
override fun getValue(thisRef: Any?, property: KProperty<*>): ItemType {
|
||||||
|
return ItemType.ofName(property.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ofName(name: String): ItemType {
|
||||||
|
return ItemType(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
val SWORD by generated
|
||||||
|
}
|
||||||
|
}
|
||||||
61
src/main/kotlin/util/skyblock/Rarity.kt
Normal file
61
src/main/kotlin/util/skyblock/Rarity.kt
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package moe.nea.firmament.util.skyblock
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
import net.minecraft.text.Text
|
||||||
|
import moe.nea.firmament.util.StringUtil.words
|
||||||
|
import moe.nea.firmament.util.collections.lastNotNullOfOrNull
|
||||||
|
import moe.nea.firmament.util.mc.loreAccordingToNbt
|
||||||
|
import moe.nea.firmament.util.petData
|
||||||
|
import moe.nea.firmament.util.unformattedString
|
||||||
|
|
||||||
|
typealias RepoRarity = io.github.moulberry.repo.data.Rarity
|
||||||
|
|
||||||
|
enum class Rarity(vararg altNames: String) {
|
||||||
|
COMMON,
|
||||||
|
UNCOMMON,
|
||||||
|
RARE,
|
||||||
|
EPIC,
|
||||||
|
LEGENDARY("LEGENJERRY"),
|
||||||
|
MYTHIC,
|
||||||
|
DIVINE,
|
||||||
|
SUPREME,
|
||||||
|
SPECIAL,
|
||||||
|
VERY_SPECIAL,
|
||||||
|
UNKNOWN
|
||||||
|
;
|
||||||
|
|
||||||
|
val names = setOf(name) + altNames
|
||||||
|
|
||||||
|
val neuRepoRarity: RepoRarity? = RepoRarity.entries.find { it.name == name }
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val byName = entries.flatMap { en -> en.names.map { it to en } }.toMap()
|
||||||
|
val fromNeuRepo = entries.associateBy { it.neuRepoRarity }
|
||||||
|
|
||||||
|
fun fromNeuRepo(repo: RepoRarity): Rarity? {
|
||||||
|
return fromNeuRepo[repo]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromString(name: String): Rarity? {
|
||||||
|
return byName[name]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromTier(tier: Int): Rarity? {
|
||||||
|
return entries.getOrNull(tier)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromItem(itemStack: ItemStack): Rarity? {
|
||||||
|
return fromLore(itemStack.loreAccordingToNbt) ?: fromPetItem(itemStack)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromPetItem(itemStack: ItemStack): Rarity? =
|
||||||
|
itemStack.petData?.tier?.let(::fromNeuRepo)
|
||||||
|
|
||||||
|
fun fromLore(lore: List<Text>): Rarity? =
|
||||||
|
lore.lastNotNullOfOrNull {
|
||||||
|
it.unformattedString.words()
|
||||||
|
.firstNotNullOfOrNull(::fromString)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user