diff options
author | Linnea Gräf <nea@nea.moe> | 2025-03-11 17:58:47 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-03-11 17:58:47 +0100 |
commit | 03a1a00e57633ff30048d5af09fa10db9dcf423b (patch) | |
tree | 8ff130eb0684fa4839c85f6e1bb2d0bd5271f735 /src/main/kotlin/util/skyblock/Rarity.kt | |
parent | 17a855a4bdfcca00b29f85981d8fb86968d9038c (diff) | |
download | Firmament-03a1a00e57633ff30048d5af09fa10db9dcf423b.tar.gz Firmament-03a1a00e57633ff30048d5af09fa10db9dcf423b.tar.bz2 Firmament-03a1a00e57633ff30048d5af09fa10db9dcf423b.zip |
feat: Add SBRecombobulatedexperiment/itemstacks
Diffstat (limited to 'src/main/kotlin/util/skyblock/Rarity.kt')
-rw-r--r-- | src/main/kotlin/util/skyblock/Rarity.kt | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main/kotlin/util/skyblock/Rarity.kt b/src/main/kotlin/util/skyblock/Rarity.kt index f244ef6..0b26bda 100644 --- a/src/main/kotlin/util/skyblock/Rarity.kt +++ b/src/main/kotlin/util/skyblock/Rarity.kt @@ -13,10 +13,14 @@ import net.minecraft.text.Text import net.minecraft.util.Formatting import moe.nea.firmament.util.StringUtil.words import moe.nea.firmament.util.collections.lastNotNullOfOrNull +import moe.nea.firmament.util.directLiteralStringContent import moe.nea.firmament.util.mc.loreAccordingToNbt import moe.nea.firmament.util.petData +import moe.nea.firmament.util.prepend +import moe.nea.firmament.util.prependHypixelified import moe.nea.firmament.util.removeColorCodes import moe.nea.firmament.util.unformattedString +import moe.nea.firmament.util.withColor typealias RepoRarity = io.github.moulberry.repo.data.Rarity @@ -52,6 +56,10 @@ enum class Rarity(vararg altNames: String) { val text: Text get() = Text.literal(name).setStyle(Style.EMPTY.withColor(colourMap[this])) val neuRepoRarity: RepoRarity? = RepoRarity.entries.find { it.name == name } + fun recombobulate(): Rarity = Rarity.entries.getOrElse(ordinal + 1) { this } + + fun colour() = colourMap[this] ?: Formatting.WHITE + companion object { // TODO: inline those formattings as fields val colourMap = mapOf( @@ -94,11 +102,46 @@ enum class Rarity(vararg altNames: String) { } } + fun findLoreIndex(lore: List<Text>): Int { + return lore.indexOfLast { + it.unformattedString.words().any { fromString(it) != null } + } + } + fun fromLore(lore: List<Text>): Rarity? = lore.lastNotNullOfOrNull { it.unformattedString.words() .firstNotNullOfOrNull(::fromString) } + fun recombobulateLore(lore: List<Text>): List<Text> { + val before = fromLore(lore) ?: return lore + val rarityIndex = findLoreIndex(lore) + if (rarityIndex < 0) return lore + val after = before.recombobulate() + val col = after.colour() + val loreMut = lore.toMutableList() + val obfuscatedTag = Text.literal("a") + .withColor(col) + .styled { it.withObfuscated(true) } + val rarityLine = loreMut[rarityIndex].copy() + .prependHypixelified(Text.literal(" ")) + .prepend(obfuscatedTag) + .append(Text.literal(" ")) + .append(obfuscatedTag) + (rarityLine.siblings as MutableList<Text>) + .replaceAll { + var content = it.directLiteralStringContent + before.names.forEach { + content = content?.replace(it, after.name) + } + val editedText = (if (content != it.directLiteralStringContent) + Text.literal(content) else it.copy()) + editedText.withColor(col) + } + loreMut[rarityIndex] = rarityLine + return loreMut + } + } } |