diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-07 21:18:21 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-07 21:18:21 +0100 |
commit | 6955c99b2e241cf7e4070424e8dbf29f80bb63fd (patch) | |
tree | 5abb4d0474cac2c579902e4bbf0266cdce0efaa0 /src/main/kotlin/moe/nea/ledger/ItemUtil.kt | |
parent | e3ace3c1b781b8d07f8eca60ba90df35da6c9d21 (diff) | |
download | LocalTransactionLedger-6955c99b2e241cf7e4070424e8dbf29f80bb63fd.tar.gz LocalTransactionLedger-6955c99b2e241cf7e4070424e8dbf29f80bb63fd.tar.bz2 LocalTransactionLedger-6955c99b2e241cf7e4070424e8dbf29f80bb63fd.zip |
feat: Add kat upgrade and flower detection
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/ItemUtil.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/ItemUtil.kt | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/ItemUtil.kt b/src/main/kotlin/moe/nea/ledger/ItemUtil.kt index b82c97f..38c2b50 100644 --- a/src/main/kotlin/moe/nea/ledger/ItemUtil.kt +++ b/src/main/kotlin/moe/nea/ledger/ItemUtil.kt @@ -4,25 +4,56 @@ import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound +fun ItemStack.getExtraAttributes(): NBTTagCompound { + val nbt = this.tagCompound ?: return NBTTagCompound() + return nbt.getCompoundTag("ExtraAttributes") +} + fun ItemStack.getInternalId(): ItemId? { - val nbt = this.tagCompound ?: NBTTagCompound() - val extraAttributes = nbt.getCompoundTag("ExtraAttributes") - val id = extraAttributes.getString("id") - return id.takeIf { it.isNotBlank() }?.let(::ItemId) + val extraAttributes = getExtraAttributes() + var id = extraAttributes.getString("id") + id = id.takeIf { it.isNotBlank() } + if (id == "PET") { + id = getPetId() ?: id + } + return id?.let(::ItemId) +} + +class PetInfo { + var type: String? = null + var tier: String? = null } +fun ItemStack.getPetId(): String? { + val petInfoStr = getExtraAttributes().getString("petInfo") + val petInfo = Ledger.gson.fromJson(petInfoStr, PetInfo::class.java) + if (petInfo.type == null || petInfo.tier == null) return null + return petInfo.type + ";" + rarityToIndex(petInfo.tier ?: "") +} + +fun rarityToIndex(rarity: String): Int { + return when (rarity) { + "COMMON" -> 0 + "UNCOMMON" -> 1 + "RARE" -> 2 + "EPIC" -> 3 + "LEGENDARY" -> 4 + "MYTHIC" -> 5 + else -> -1 + } +} fun ItemStack.getLore(): List<String> { - val nbt = this.tagCompound ?: NBTTagCompound() - val extraAttributes = nbt.getCompoundTag("display") - val lore = extraAttributes.getTagList("Lore", 8) - return (0 until lore.tagCount()).map { lore.getStringTagAt(it) } + val nbt = this.tagCompound ?: NBTTagCompound() + val extraAttributes = nbt.getCompoundTag("display") + val lore = extraAttributes.getTagList("Lore", 8) + return (0 until lore.tagCount()).map { lore.getStringTagAt(it) } } fun ItemStack.getDisplayNameU(): String { - val nbt = this.tagCompound ?: NBTTagCompound() - val extraAttributes = nbt.getCompoundTag("display") - return extraAttributes.getString("Name") + val nbt = this.tagCompound ?: NBTTagCompound() + val extraAttributes = nbt.getCompoundTag("display") + return extraAttributes.getString("Name") } |