feat: Add npc shop recipes
This commit is contained in:
@@ -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) }
|
||||
}
|
||||
|
||||
@@ -9,11 +9,39 @@ import kotlin.io.path.isReadable
|
||||
import kotlin.io.path.isRegularFile
|
||||
import kotlin.io.path.listDirectoryEntries
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
import net.minecraft.text.Text
|
||||
|
||||
object FirmFormatters {
|
||||
|
||||
private inline fun shortIf(
|
||||
value: Double, breakpoint: Double, char: String,
|
||||
return_: (String) -> Nothing
|
||||
) {
|
||||
if (value >= breakpoint) {
|
||||
val broken = (value / breakpoint * 10).roundToInt()
|
||||
if (broken > 99)
|
||||
return_((broken / 10).toString() + char)
|
||||
val decimals = broken.toString()
|
||||
decimals.singleOrNull()?.let {
|
||||
return_("0.$it$char")
|
||||
}
|
||||
return_("${decimals[0]}.${decimals[1]}$char")
|
||||
}
|
||||
}
|
||||
|
||||
fun shortFormat(double: Double): String {
|
||||
if (double < 0) return "-" + shortFormat(-double)
|
||||
shortIf(double, 1_000_000_000_000.0, "t") { return it }
|
||||
shortIf(double, 1_000_000_000.0, "b") { return it }
|
||||
shortIf(double, 1_000_000.0, "m") { return it }
|
||||
shortIf(double, 1_000.0, "k") { return it }
|
||||
shortIf(double, 1.0, "") { return it }
|
||||
return double.toString()
|
||||
}
|
||||
|
||||
fun formatCommas(int: Int, segments: Int = 3): String = formatCommas(int.toLong(), segments)
|
||||
fun formatCommas(long: Long, segments: Int = 3, includeSign: Boolean = false): String {
|
||||
if (long < 0 && long != Long.MIN_VALUE) {
|
||||
|
||||
@@ -122,6 +122,7 @@ fun MutableText.pink() = withColor(Formatting.LIGHT_PURPLE)
|
||||
fun MutableText.yellow() = withColor(Formatting.YELLOW)
|
||||
fun MutableText.gold() = withColor(Formatting.GOLD)
|
||||
fun MutableText.grey() = withColor(Formatting.GRAY)
|
||||
fun MutableText.darkGrey() = withColor(Formatting.DARK_GRAY)
|
||||
fun MutableText.red() = withColor(Formatting.RED)
|
||||
fun MutableText.white() = withColor(Formatting.WHITE)
|
||||
fun MutableText.bold(): MutableText = styled { it.withBold(true) }
|
||||
|
||||
Reference in New Issue
Block a user