diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-25 16:55:33 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-25 16:55:33 +0100 |
commit | c4997e21053c8671ed4c5474fb70df6ae58dae06 (patch) | |
tree | 9b17d0fa1a46dc7571fbca8a2d09dc9aaec98dd0 | |
parent | ddebaf47900dfab41590c97c202984142ae5b9f6 (diff) | |
download | Firmament-c4997e21053c8671ed4c5474fb70df6ae58dae06.tar.gz Firmament-c4997e21053c8671ed4c5474fb70df6ae58dae06.tar.bz2 Firmament-c4997e21053c8671ed4c5474fb70df6ae58dae06.zip |
feat: Add reforge recipes
-rw-r--r-- | build.gradle.kts | 1 | ||||
-rw-r--r-- | src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBReforgeRecipe.kt | 47 | ||||
-rw-r--r-- | src/main/kotlin/repo/Reforge.kt | 10 | ||||
-rw-r--r-- | src/main/kotlin/repo/SBItemStack.kt | 26 | ||||
-rw-r--r-- | translations/en_us.json | 2 |
5 files changed, 65 insertions, 21 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index 1d5478f..15b7d71 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -182,6 +182,7 @@ fun createIsolatedSourceSet(name: String, path: String = "compat/$name", isEnabl classpath.from(configurations.getByName(ss.compileClasspathConfigurationName)) } collectTranslations { + // TODO: this does not work, somehow this.classes.from(sourceSets.main.get().kotlin.classesDirectory) } return ss diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBReforgeRecipe.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBReforgeRecipe.kt index 232f04f..9c8d8f4 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBReforgeRecipe.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBReforgeRecipe.kt @@ -6,6 +6,7 @@ import me.shedaniel.math.FloatingDimension import me.shedaniel.math.Point import me.shedaniel.math.Rectangle import me.shedaniel.rei.api.client.gui.Renderer +import me.shedaniel.rei.api.client.gui.widgets.Label import me.shedaniel.rei.api.client.gui.widgets.Widget import me.shedaniel.rei.api.client.gui.widgets.Widgets import me.shedaniel.rei.api.client.registry.display.DisplayCategory @@ -34,6 +35,7 @@ import moe.nea.firmament.util.AprilFoolsUtil import moe.nea.firmament.util.FirmFormatters import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.gold +import moe.nea.firmament.util.grey import moe.nea.firmament.util.skyblock.ItemType import moe.nea.firmament.util.skyblock.Rarity import moe.nea.firmament.util.skyblock.SkyBlockItems @@ -64,15 +66,15 @@ class SBReforgeRecipe( override fun setupDisplay(display: SBReforgeRecipe, bounds: Rectangle): MutableList<Widget> { val list = mutableListOf<Widget>() list.add(Widgets.createRecipeBase(bounds)) - // TODO: actual layout after christmas, probably - list.add(Widgets.createSlot(Point(bounds.minX + 10, bounds.centerY - 9)) - .markInput().entries(display.inputItems)) + val inputSlot = Widgets.createSlot(Point(bounds.minX + 10, bounds.centerY - 9)) + .markInput().entries(display.inputItems) + list.add(inputSlot) if (display.reforgeStone != null) { list.add(Widgets.createSlot(Point(bounds.minX + 10 + 24, bounds.centerY - 9 - 10)) .markInput().entry(display.reforgeStone)) list.add(Widgets.withTooltip( Widgets.withTranslate(Widgets.wrapRenderer( - Rectangle(Point(bounds.minX + 10 + 24, bounds.centerY - 9 + 10), Dimension(18, 18)), + Rectangle(Point(bounds.minX + 10 + 24, bounds.centerY - 9 + 10), Dimension(16, 16)), SBItemEntryDefinition.getEntry(SkyBlockItems.REFORGE_ANVIL)), 0.0, 0.0, 150.0), Rarity.entries.mapNotNull { rarity -> display.reforge.reforgeCosts?.get(rarity)?.let { rarity to it } @@ -87,16 +89,41 @@ class SBReforgeRecipe( val size = if (AprilFoolsUtil.isAprilFoolsDay) 1.2 else 0.6 val dimension = FloatingDimension(EntityWidget.defaultSize.width * size, EntityWidget.defaultSize.height * size) - list.add(EntityWidget( - EntityType.VILLAGER.create(EntityRenderer.fakeWorld, SpawnReason.COMMAND) - ?.also { it.villagerData = it.villagerData.withProfession(VillagerProfession.WEAPONSMITH) }, - Point(bounds.minX + 10 + 24 + 8 - dimension.width / 2, bounds.centerY - dimension.height / 2), - dimension + list.add(Widgets.withTooltip( + EntityWidget( + EntityType.VILLAGER.create(EntityRenderer.fakeWorld, SpawnReason.COMMAND) + ?.also { it.villagerData = it.villagerData.withProfession(VillagerProfession.WEAPONSMITH) }, + Point(bounds.minX + 10 + 24 + 8 - dimension.width / 2, bounds.centerY - dimension.height / 2), + dimension + ), + tr("firmament.recipecategory.reforge.basic", + "This is a basic reforge, available at the Blacksmith.").grey() )) -// TODO: render a blacksmith entity or smth } list.add(Widgets.createSlot(Point(bounds.minX + 10 + 24 + 24, bounds.centerY - 9)) .markInput().entries(display.outputItems)) + val statToLineMappings = mutableListOf<Pair<String, Label>>() + for ((i, statId) in display.reforge.statUniverse.withIndex()) { + val label = Widgets.createLabel( + Point(bounds.minX + 10 + 24 + 24 + 20, bounds.minY + 8 + i * 11), + SBItemStack.Companion.StatLine(SBItemStack.statIdToName(statId), null).reconstitute(7)) + .horizontalAlignment(Label.LEFT_ALIGNED) + statToLineMappings.add(statId to label) + list.add(label) + } + fun updateStatLines() { + val entry = inputSlot.currentEntry?.castValue<SBItemStack>() ?: return + val stats = display.reforge.reforgeStats?.get(entry.rarity) ?: mapOf() + for ((stat, label) in statToLineMappings) { + label.message = + SBItemStack.Companion.StatLine( + SBItemStack.statIdToName(stat), null, + valueNum = stats[stat] + ).reconstitute(7) + } + } + updateStatLines() + inputSlot.withEntriesListener { updateStatLines() } return list } } diff --git a/src/main/kotlin/repo/Reforge.kt b/src/main/kotlin/repo/Reforge.kt index b52adc6..dc0d93d 100644 --- a/src/main/kotlin/repo/Reforge.kt +++ b/src/main/kotlin/repo/Reforge.kt @@ -36,6 +36,10 @@ data class Reforge( ) { val eligibleItems get() = allowOn ?: itemTypes ?: listOf() + val statUniverse: Set<String> = Rarity.entries.flatMapTo(mutableSetOf()) { + reforgeStats?.get(it)?.keys ?: emptySet() + } + @Serializable(with = ReforgeEligibilityFilter.Serializer::class) sealed interface ReforgeEligibilityFilter { object ItemTypesSerializer : KSerializer<List<ReforgeEligibilityFilter>> { @@ -108,7 +112,7 @@ data class Reforge( @Serializable(with = RarityMapped.Serializer::class) sealed interface RarityMapped<T> { - fun get(rarity: Rarity): T? + fun get(rarity: Rarity?): T? class Serializer<T>( val values: KSerializer<T> @@ -140,14 +144,14 @@ data class Reforge( @Serializable data class Direct<T>(val value: T) : RarityMapped<T> { - override fun get(rarity: Rarity): T { + override fun get(rarity: Rarity?): T { return value } } @Serializable data class PerRarity<T>(val values: Map<Rarity, T>) : RarityMapped<T> { - override fun get(rarity: Rarity): T? { + override fun get(rarity: Rarity?): T? { return values[rarity] } } diff --git a/src/main/kotlin/repo/SBItemStack.kt b/src/main/kotlin/repo/SBItemStack.kt index a5f54ae..3c59543 100644 --- a/src/main/kotlin/repo/SBItemStack.kt +++ b/src/main/kotlin/repo/SBItemStack.kt @@ -18,7 +18,6 @@ import moe.nea.firmament.util.FirmFormatters import moe.nea.firmament.util.LegacyFormattingCode 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 @@ -179,21 +178,30 @@ data class SBItemStack constructor( } fun formatValue() = - Text.literal(FirmFormatters.formatCommas(valueNum ?: 0.0, 1, includeSign = true) + statFormatting.postFix + " ") + Text.literal(FirmFormatters.formatCommas(valueNum ?: 0.0, + 1, + includeSign = true) + statFormatting.postFix + " ") .setStyle(Style.EMPTY.withColor(statFormatting.color)) val statFormatting = formattingOverrides[statName] ?: StatFormatting("", Formatting.GREEN) - fun reconstitute(): Text = + private fun abbreviate(abbreviateTo: Int): String { + if (abbreviateTo >= statName.length) return statName + val segments = statName.split(" ") + return segments.joinToString(" ") { + it.substring(0, maxOf(1, abbreviateTo / segments.size)) + } + } + + fun reconstitute(abbreviateTo: Int = Int.MAX_VALUE): Text = Text.literal("").setStyle(Style.EMPTY.withItalic(false)) - .append(Text.literal("$statName: ").grey()) + .append(Text.literal("${abbreviate(abbreviateTo)}: ").grey()) .append(value ?: formatValue()) .also { rest.forEach(it::append) } } - private fun statIdToName(statId: String): String { - return statId.split("_").joinToString(" ") { - it.replaceFirstChar { it.uppercaseChar() } - } + fun statIdToName(statId: String): String { + val segments = statId.split("_") + return segments.joinToString(" ") { it.replaceFirstChar { it.uppercaseChar() } } } private fun parseStatLine(line: Text): StatLine? { @@ -271,6 +279,8 @@ data class SBItemStack constructor( // TODO: avoid instantiating the item stack here val itemType: ItemType? get() = ItemType.fromItemStack(asImmutableItemStack()) + val rarity: Rarity? get() = Rarity.fromItem(asImmutableItemStack()) + private var itemStack_: ItemStack? = null private val itemStack: ItemStack diff --git a/translations/en_us.json b/translations/en_us.json index 3d8de96..82dcd45 100644 --- a/translations/en_us.json +++ b/translations/en_us.json @@ -331,6 +331,8 @@ "firmament.recipe.mobs.name": "§8[§7Lv %d§8] §c%s", "firmament.recipe.mobs.name.nolevel": "§c%s", "firmament.recipe.novanilla": "Hypixel cannot super craft vanilla recipes", + "firmament.recipecategory.reforge": "Reforge", + "firmament.recipecategory.reforge.basic": "This is a basic reforge, available at the Blacksmith.", "firmament.reiwarning": "Firmament needs RoughlyEnoughItems to display its item list!", "firmament.reiwarning.disable": "Click here to disable this warning", "firmament.reiwarning.disabled": "Disabled the RoughlyEnoughItems warning. Keep in mind that you will not have an item list without REI.", |