diff options
Diffstat (limited to 'src/main/kotlin/repo')
-rw-r--r-- | src/main/kotlin/repo/BetterRepoRecipeCache.kt | 5 | ||||
-rw-r--r-- | src/main/kotlin/repo/ItemCache.kt | 3 | ||||
-rw-r--r-- | src/main/kotlin/repo/SBItemStack.kt | 68 |
3 files changed, 65 insertions, 11 deletions
diff --git a/src/main/kotlin/repo/BetterRepoRecipeCache.kt b/src/main/kotlin/repo/BetterRepoRecipeCache.kt index 4b32e57..6d18223 100644 --- a/src/main/kotlin/repo/BetterRepoRecipeCache.kt +++ b/src/main/kotlin/repo/BetterRepoRecipeCache.kt @@ -2,8 +2,10 @@ package moe.nea.firmament.repo import io.github.moulberry.repo.IReloadable import io.github.moulberry.repo.NEURepository +import io.github.moulberry.repo.data.NEUNpcShopRecipe import io.github.moulberry.repo.data.NEURecipe import moe.nea.firmament.util.SkyblockId +import moe.nea.firmament.util.skyblockId class BetterRepoRecipeCache(vararg val extraProviders: ExtraRecipeProvider) : IReloadable { var usages: Map<SkyblockId, Set<NEURecipe>> = mapOf() @@ -17,6 +19,9 @@ class BetterRepoRecipeCache(vararg val extraProviders: ExtraRecipeProvider) : IR .flatMap { it.recipes } (baseRecipes + extraProviders.flatMap { it.provideExtraRecipes() }) .forEach { recipe -> + if (recipe is NEUNpcShopRecipe) { + usages.getOrPut(recipe.isSoldBy.skyblockId, ::mutableSetOf).add(recipe) + } recipe.allInputs.forEach { usages.getOrPut(SkyblockId(it.itemId), ::mutableSetOf).add(recipe) } recipe.allOutputs.forEach { recipes.getOrPut(SkyblockId(it.itemId), ::mutableSetOf).add(recipe) } } diff --git a/src/main/kotlin/repo/ItemCache.kt b/src/main/kotlin/repo/ItemCache.kt index e140dd8..9fa0083 100644 --- a/src/main/kotlin/repo/ItemCache.kt +++ b/src/main/kotlin/repo/ItemCache.kt @@ -24,6 +24,7 @@ import net.minecraft.nbt.NbtCompound import net.minecraft.nbt.NbtElement import net.minecraft.nbt.NbtOps import net.minecraft.nbt.NbtString +import net.minecraft.text.MutableText import net.minecraft.text.Style import net.minecraft.text.Text import moe.nea.firmament.Firmament @@ -100,7 +101,7 @@ object ItemCache : IReloadable { } } - fun un189Lore(lore: String): Text { + fun un189Lore(lore: String): MutableText { val base = Text.literal("") base.setStyle(Style.EMPTY.withItalic(false)) var lastColorCode = Style.EMPTY diff --git a/src/main/kotlin/repo/SBItemStack.kt b/src/main/kotlin/repo/SBItemStack.kt index 4d07801..da34707 100644 --- a/src/main/kotlin/repo/SBItemStack.kt +++ b/src/main/kotlin/repo/SBItemStack.kt @@ -17,8 +17,10 @@ import moe.nea.firmament.repo.ItemCache.asItemStack import moe.nea.firmament.repo.ItemCache.withFallback import moe.nea.firmament.util.FirmFormatters import moe.nea.firmament.util.LegacyFormattingCode +import moe.nea.firmament.util.MC import moe.nea.firmament.util.ReforgeId import moe.nea.firmament.util.SkyblockId +import moe.nea.firmament.util.blue import moe.nea.firmament.util.directLiteralStringContent import moe.nea.firmament.util.extraAttributes import moe.nea.firmament.util.getReforgeId @@ -27,12 +29,16 @@ import moe.nea.firmament.util.grey import moe.nea.firmament.util.mc.appendLore import moe.nea.firmament.util.mc.displayNameAccordingToNbt import moe.nea.firmament.util.mc.loreAccordingToNbt +import moe.nea.firmament.util.mc.modifyLore +import moe.nea.firmament.util.modifyExtraAttributes import moe.nea.firmament.util.petData import moe.nea.firmament.util.prepend +import moe.nea.firmament.util.reconstitute import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyblock.ItemType import moe.nea.firmament.util.skyblock.Rarity import moe.nea.firmament.util.skyblockId +import moe.nea.firmament.util.unformattedString import moe.nea.firmament.util.useMatch import moe.nea.firmament.util.withColor @@ -99,6 +105,13 @@ data class SBItemStack constructor( return SBItemStack(SkyblockId.NULL, null, itemStack.count, null, fallback = itemStack) } + fun parseStatBlock(itemStack: ItemStack): List<StatLine> { + return itemStack.loreAccordingToNbt + .map { parseStatLine(it) } + .takeWhile { it != null } + .filterNotNull() + } + fun appendEnhancedStats( itemStack: ItemStack, reforgeStats: Map<String, Double>, @@ -135,6 +148,7 @@ data class SBItemStack constructor( data class StatFormatting( val postFix: String, val color: Formatting, + val isStarAffected: Boolean = true, ) val formattingOverrides = mapOf( @@ -142,7 +156,7 @@ data class SBItemStack constructor( "Strength" to StatFormatting("", Formatting.RED), "Damage" to StatFormatting("", Formatting.RED), "Bonus Attack Speed" to StatFormatting("%", Formatting.RED), - "Shot Cooldown" to StatFormatting("s", Formatting.RED), + "Shot Cooldown" to StatFormatting("s", Formatting.GREEN, false), "Ability Damage" to StatFormatting("%", Formatting.RED), "Crit Damage" to StatFormatting("%", Formatting.RED), "Crit Chance" to StatFormatting("%", Formatting.RED), @@ -184,9 +198,11 @@ data class SBItemStack constructor( val color: Formatting, val prefix: String, val postFix: String, + val isHidden: Boolean, ) { - REFORGE(Formatting.BLUE, "(", ")"), - + REFORGE(Formatting.BLUE, "(", ")", false), + STAR_BUFF(Formatting.RESET, "", "", true), + CATA_STAR_BUFF(Formatting.DARK_GRAY, "(", ")", false), ; } @@ -194,7 +210,7 @@ data class SBItemStack constructor( val statName: String, val value: Text?, val rest: List<Text> = listOf(), - val valueNum: Double? = value?.directLiteralStringContent?.trim(' ', '%', '+')?.toDoubleOrNull() + val valueNum: Double? = value?.directLiteralStringContent?.trim(' ', 's', '%', '+')?.toDoubleOrNull() ) { fun addStat(amount: Double, buffKind: BuffKind): StatLine { val formattedAmount = FirmFormatters.formatCommas(amount, 1, includeSign = true) @@ -202,7 +218,8 @@ data class SBItemStack constructor( valueNum = (valueNum ?: 0.0) + amount, value = null, rest = rest + - listOf( + if (buffKind.isHidden) emptyList() + else listOf( Text.literal( buffKind.prefix + formattedAmount + statFormatting.postFix + @@ -308,6 +325,22 @@ data class SBItemStack constructor( data.putString("modifier", reforgeId.id) itemStack.extraAttributes = data appendEnhancedStats(itemStack, reforgeStats, BuffKind.REFORGE) + reforge.reforgeAbility?.get(rarity)?.let { reforgeAbility -> + val formattedReforgeAbility = ItemCache.un189Lore(reforgeAbility) + .grey() + itemStack.modifyLore { + val lastBlank = it.indexOfLast { it.unformattedString.isBlank() } + val newList = mutableListOf<Text>() + newList.addAll(it.subList(0, lastBlank)) + newList.add(Text.literal("")) + newList.add(Text.literal("${reforge.reforgeName} Bonus").blue()) + MC.font.textHandler.wrapLines(formattedReforgeAbility, 180, Style.EMPTY).mapTo(newList) { + it.reconstitute() + } + newList.addAll(it.subList(lastBlank, it.size)) + return@modifyLore newList + } + } } // TODO: avoid instantiating the item stack here @@ -325,12 +358,14 @@ data class SBItemStack constructor( return@run ItemStack.EMPTY val replacementData = mutableMapOf<String, String>() injectReplacementDataForPets(replacementData) - return@run neuItem.asItemStack(idHint = skyblockId, replacementData) + val baseItem = neuItem.asItemStack(idHint = skyblockId, replacementData) .withFallback(fallback) .copyWithCount(stackSize) - .also { appendReforgeInfo(it) } - .also { it.appendLore(extraLore) } - .also { enhanceStatsByStars(it, stars) } + val baseStats = parseStatBlock(baseItem) + appendReforgeInfo(baseItem) + baseItem.appendLore(extraLore) + enhanceStatsByStars(baseItem, stars, baseStats) + return@run baseItem } if (itemStack_ == null) itemStack_ = itemStack @@ -340,6 +375,7 @@ data class SBItemStack constructor( private fun starString(stars: Int): Text { if (stars <= 0) return Text.empty() + // TODO: idk master stars val tiers = listOf( LegacyFormattingCode.GOLD, LegacyFormattingCode.LIGHT_PURPLE, @@ -359,11 +395,23 @@ data class SBItemStack constructor( return starString } - private fun enhanceStatsByStars(itemStack: ItemStack, stars: Int) { + private fun enhanceStatsByStars(itemStack: ItemStack, stars: Int, baseStats: List<StatLine>) { if (stars == 0) return // TODO: increase stats and add the star level into the nbt data so star displays work + itemStack.modifyExtraAttributes { + it.putInt("upgrade_level", stars) + } itemStack.displayNameAccordingToNbt = itemStack.displayNameAccordingToNbt.copy() .append(starString(stars)) + val isDungeon = ItemType.fromItemStack(itemStack)?.isDungeon ?: true + val truncatedStarCount = if (isDungeon) minOf(5, stars) else stars + appendEnhancedStats(itemStack, + baseStats + .filter { it.statFormatting.isStarAffected } + .associate { + it.statName to ((it.valueNum ?: 0.0) * (truncatedStarCount * 0.02)) + }, + BuffKind.STAR_BUFF) } fun asImmutableItemStack(): ItemStack { |