aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/skyblock/Rarity.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-24 03:58:43 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-24 23:35:29 +0100
commite16c60169bf192b79991176b5f9cee66b5b16e7d (patch)
tree8574fc28d83abe646c23dff336185a9d2ae7f637 /src/main/kotlin/util/skyblock/Rarity.kt
parentfbab19b40f72574b7930ddd2981998b2d2845471 (diff)
downloadFirmament-e16c60169bf192b79991176b5f9cee66b5b16e7d.tar.gz
Firmament-e16c60169bf192b79991176b5f9cee66b5b16e7d.tar.bz2
Firmament-e16c60169bf192b79991176b5f9cee66b5b16e7d.zip
WIP: Reforge recipes
Diffstat (limited to 'src/main/kotlin/util/skyblock/Rarity.kt')
-rw-r--r--src/main/kotlin/util/skyblock/Rarity.kt21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main/kotlin/util/skyblock/Rarity.kt b/src/main/kotlin/util/skyblock/Rarity.kt
index f26cefe..0244630 100644
--- a/src/main/kotlin/util/skyblock/Rarity.kt
+++ b/src/main/kotlin/util/skyblock/Rarity.kt
@@ -1,5 +1,12 @@
package moe.nea.firmament.util.skyblock
+import kotlinx.serialization.KSerializer
+import kotlinx.serialization.Serializable
+import kotlinx.serialization.descriptors.PrimitiveKind
+import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
+import kotlinx.serialization.descriptors.SerialDescriptor
+import kotlinx.serialization.encoding.Decoder
+import kotlinx.serialization.encoding.Encoder
import net.minecraft.item.ItemStack
import net.minecraft.text.Text
import moe.nea.firmament.util.StringUtil.words
@@ -10,6 +17,7 @@ import moe.nea.firmament.util.unformattedString
typealias RepoRarity = io.github.moulberry.repo.data.Rarity
+@Serializable(with = Rarity.Serializer::class)
enum class Rarity(vararg altNames: String) {
COMMON,
UNCOMMON,
@@ -24,6 +32,19 @@ enum class Rarity(vararg altNames: String) {
UNKNOWN
;
+ object Serializer : KSerializer<Rarity> {
+ override val descriptor: SerialDescriptor
+ get() = PrimitiveSerialDescriptor(Rarity::class.java.name, PrimitiveKind.STRING)
+
+ override fun deserialize(decoder: Decoder): Rarity {
+ return valueOf(decoder.decodeString().replace(" ", "_"))
+ }
+
+ override fun serialize(encoder: Encoder, value: Rarity) {
+ encoder.encodeString(value.name)
+ }
+ }
+
val names = setOf(name) + altNames
val neuRepoRarity: RepoRarity? = RepoRarity.entries.find { it.name == name }