feat: Add npc shop recipes
This commit is contained in:
@@ -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