diff options
author | Linnea Gräf <nea@nea.moe> | 2024-07-24 02:22:30 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-07-24 02:22:30 +0200 |
commit | c7143936d7a1bf3ae49362049541b2d23b11ab8c (patch) | |
tree | 4e905377b8abf56d1a9e253543a6d3a251f9da82 /src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt | |
parent | 4585a11434f44fa0900351825eb3ca38ce64f187 (diff) | |
download | Firmament-c7143936d7a1bf3ae49362049541b2d23b11ab8c.tar.gz Firmament-c7143936d7a1bf3ae49362049541b2d23b11ab8c.tar.bz2 Firmament-c7143936d7a1bf3ae49362049541b2d23b11ab8c.zip |
Add essence upgrade recipes
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt b/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt index 3897d01..19b26c5 100644 --- a/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt +++ b/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt @@ -22,6 +22,7 @@ import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes import net.minecraft.item.ItemStack import net.minecraft.registry.tag.TagKey import net.minecraft.text.Text +import net.minecraft.util.Formatting import net.minecraft.util.Identifier import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry import moe.nea.firmament.repo.ExpLadders @@ -30,10 +31,13 @@ import moe.nea.firmament.repo.ItemCache.asItemStack import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.FirmFormatters import moe.nea.firmament.util.HypixelPetInfo +import moe.nea.firmament.util.LegacyFormattingCode import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.appendLore +import moe.nea.firmament.util.item.displayNameAccordingToNbt import moe.nea.firmament.util.petData import moe.nea.firmament.util.skyBlockId +import moe.nea.firmament.util.withColor // TODO: add in extra data like pet info, into this structure data class PetData( @@ -46,6 +50,7 @@ data class PetData( fun fromHypixel(petInfo: HypixelPetInfo) = PetData( petInfo.tier, petInfo.type, petInfo.exp, ) + fun forLevel(petId: String, rarity: Rarity, level: Int) = PetData( rarity, petId, ExpLadders.getExpLadder(petId, rarity).getPetExpForLevel(level).toDouble() ) @@ -60,6 +65,8 @@ data class SBItemStack( private var stackSize: Int, private var petData: PetData?, val extraLore: List<Text> = emptyList(), + // TODO: grab this star data from nbt if possible + val stars: Int = 0, ) { fun getStackSize() = stackSize @@ -67,6 +74,7 @@ data class SBItemStack( this.stackSize = stackSize this.itemStack_ = null } + fun getPetData() = petData fun setPetData(petData: PetData?) { this.petData = petData @@ -132,12 +140,42 @@ data class SBItemStack( injectReplacementDataForPets(replacementData) return@run neuItem.asItemStack(idHint = skyblockId, replacementData).copyWithCount(stackSize) .also { it.appendLore(extraLore) } + .also { enhanceStatsByStars(it, stars) } } if (itemStack_ == null) itemStack_ = itemStack return itemStack } + + private fun starString(stars: Int): Text { + if (stars <= 0) return Text.empty() + val tiers = listOf( + LegacyFormattingCode.GOLD, + LegacyFormattingCode.LIGHT_PURPLE, + LegacyFormattingCode.AQUA, + ) + val maxStars = 5 + if (stars > tiers.size * maxStars) return Text.literal(" ${stars}✪").withColor(Formatting.RED) + val starBaseTier = (stars - 1) / maxStars + val starBaseColor = tiers[starBaseTier] + val starsInCurrentTier = stars - starBaseTier * maxStars + val starString = Text.literal(" " + "✪".repeat(starsInCurrentTier)).withColor(starBaseColor.modern) + if (starBaseTier > 0) { + val starLastTier = tiers[starBaseTier - 1] + val starsInLastTier = 5 - starsInCurrentTier + starString.append(Text.literal("✪".repeat(starsInLastTier)).withColor(starLastTier.modern)) + } + return starString + } + + private fun enhanceStatsByStars(itemStack: ItemStack, stars: Int) { + if (stars == 0) return + // TODO: increase stats and add the star level into the nbt data so star displays work + itemStack.displayNameAccordingToNbt = itemStack.displayNameAccordingToNbt.copy() + .append(starString(stars)) + } + fun asImmutableItemStack(): ItemStack { return itemStack } @@ -179,11 +217,11 @@ object SBItemEntryDefinition : EntryDefinition<SBItemStack> { } override fun wildcard(entry: EntryStack<SBItemStack>?, value: SBItemStack): SBItemStack { - return value.copy(stackSize = 1) + return value.copy(stackSize = 1, petData = null, stars = 0, extraLore = listOf()) } override fun normalize(entry: EntryStack<SBItemStack>?, value: SBItemStack): SBItemStack { - return value.copy(stackSize = 1) + return wildcard(entry, value) } override fun copy(entry: EntryStack<SBItemStack>?, value: SBItemStack): SBItemStack { |