aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/skyblock/Rarity.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-17 16:11:21 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-17 16:11:21 +0100
commitffebb438f8d1582ee65936399b79dd714454f223 (patch)
tree57b884d27026f115410743bfd69da983f442f799 /src/main/kotlin/util/skyblock/Rarity.kt
parent762fb402151809395cf9883354804e49a9b188a8 (diff)
downloadFirmament-ffebb438f8d1582ee65936399b79dd714454f223.tar.gz
Firmament-ffebb438f8d1582ee65936399b79dd714454f223.tar.bz2
Firmament-ffebb438f8d1582ee65936399b79dd714454f223.zip
fix: Pets missing an item rarity
Diffstat (limited to 'src/main/kotlin/util/skyblock/Rarity.kt')
-rw-r--r--src/main/kotlin/util/skyblock/Rarity.kt61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/kotlin/util/skyblock/Rarity.kt b/src/main/kotlin/util/skyblock/Rarity.kt
new file mode 100644
index 0000000..f26cefe
--- /dev/null
+++ b/src/main/kotlin/util/skyblock/Rarity.kt
@@ -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)
+ }
+
+ }
+}