diff options
author | nea <nea@nea.moe> | 2023-05-04 15:12:56 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-05-04 15:12:56 +0200 |
commit | f2aa75f7c193513215ba4619c66bcc1449b0bc27 (patch) | |
tree | 89a8e309ba84c9966eb9e7a7317255984419f0c0 /src/main/kotlin/moe/nea/notenoughupdates/util | |
parent | bfcb02e52bf9c1fbe9f4d544108ffd547c40eba5 (diff) | |
download | firmament-f2aa75f7c193513215ba4619c66bcc1449b0bc27.tar.gz firmament-f2aa75f7c193513215ba4619c66bcc1449b0bc27.tar.bz2 firmament-f2aa75f7c193513215ba4619c66bcc1449b0bc27.zip |
Make REI aware of SkyBlock item ids
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/util')
-rw-r--r-- | src/main/kotlin/moe/nea/notenoughupdates/util/SkyblockId.kt | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/SkyblockId.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/SkyblockId.kt new file mode 100644 index 0000000..8d7ef91 --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/util/SkyblockId.kt @@ -0,0 +1,42 @@ +package moe.nea.notenoughupdates.util + +import io.github.moulberry.repo.data.Rarity +import kotlinx.serialization.Serializable +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NbtCompound + +@JvmInline +value class SkyblockId(val neuItem: String) + +@Serializable +data class HypixelPetInfo( + val type: String, + val tier: Rarity, +) { + val skyblockId get() = SkyblockId("${type.uppercase()};${tier}") +} + +private val jsonparser = Json { ignoreUnknownKeys = true } + +val ItemStack.extraAttributes: NbtCompound + get() = getOrCreateSubNbt("ExtraAttributes") + +val ItemStack.skyBlockId: SkyblockId? + get() { + when (val id = extraAttributes.getString("id")) { + "PET" -> { + val jsonString = extraAttributes.getString("petInfo") + if (jsonString.isNullOrBlank()) return null + val petInfo = + runCatching { jsonparser.decodeFromString<HypixelPetInfo>(jsonString) } + .getOrElse { return null } + return petInfo.skyblockId + } + // TODO: RUNE, ENCHANTED_BOOK, PARTY_HAT_CRAB{,_ANIMATED}, ABICASE + else -> { + return SkyblockId(id) + } + } + } |