Bulk commit
This commit is contained in:
@@ -2,6 +2,7 @@ package moe.nea.firmament.util
|
||||
|
||||
import com.google.common.math.IntMath.pow
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.time.Duration
|
||||
|
||||
object FirmFormatters {
|
||||
fun toString(float: Float, fractionalDigits: Int): String = toString(float.toDouble(), fractionalDigits)
|
||||
@@ -13,4 +14,8 @@ object FirmFormatters {
|
||||
return long.toString() + (if (digits.isEmpty()) "" else ".$digits")
|
||||
}
|
||||
|
||||
fun formatTimespan(duration: Duration): String {
|
||||
return duration.toString()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||
import net.minecraft.util.math.BlockPos
|
||||
|
||||
object MC {
|
||||
fun sendCommand(command: String) {
|
||||
player?.networkHandler?.sendCommand(command)
|
||||
}
|
||||
|
||||
inline val font get() = MinecraftClient.getInstance().textRenderer
|
||||
inline val soundManager get() = MinecraftClient.getInstance().soundManager
|
||||
inline val player get() = MinecraftClient.getInstance().player
|
||||
|
||||
38
src/main/kotlin/moe/nea/firmament/util/ScoreboardUtil.kt
Normal file
38
src/main/kotlin/moe/nea/firmament/util/ScoreboardUtil.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
package moe.nea.firmament.util
|
||||
|
||||
import java.util.Optional
|
||||
import net.minecraft.scoreboard.Scoreboard
|
||||
import net.minecraft.scoreboard.Team
|
||||
import net.minecraft.text.StringVisitable
|
||||
import net.minecraft.text.Style
|
||||
import net.minecraft.text.Text
|
||||
import net.minecraft.util.Formatting
|
||||
|
||||
fun getScoreboardLines(): List<Text> {
|
||||
val scoreboard = MC.player?.scoreboard ?: return listOf()
|
||||
val activeObjective = scoreboard.getObjectiveForSlot(Scoreboard.SIDEBAR_DISPLAY_SLOT_ID) ?: return listOf()
|
||||
return scoreboard.getAllPlayerScores(activeObjective).reversed().take(15).map {
|
||||
val team = scoreboard.getPlayerTeam(it.playerName)
|
||||
Team.decorateName(team, Text.literal(it.playerName))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Text.formattedString(): String {
|
||||
val sb = StringBuilder()
|
||||
visit(StringVisitable.StyledVisitor<Unit> { style, string ->
|
||||
val c = Formatting.byName(style.color?.name)
|
||||
if (c != null) {
|
||||
sb.append("§${c.code}")
|
||||
}
|
||||
if (style.isUnderlined) {
|
||||
sb.append("§n")
|
||||
}
|
||||
if (style.isBold) {
|
||||
sb.append("§l")
|
||||
}
|
||||
sb.append(string)
|
||||
Optional.empty()
|
||||
}, Style.EMPTY)
|
||||
return sb.toString().replace("§[^a-f0-9]".toRegex(), "")
|
||||
}
|
||||
18
src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt
Normal file
18
src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
package moe.nea.firmament.util.item
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NbtElement
|
||||
import net.minecraft.nbt.NbtString
|
||||
import net.minecraft.text.Text
|
||||
|
||||
val ItemStack.loreAccordingToNbt
|
||||
get() = getOrCreateSubNbt(ItemStack.DISPLAY_KEY).getList(ItemStack.LORE_KEY, NbtElement.STRING_TYPE.toInt())
|
||||
.map { Text.Serializer.fromJson((it as NbtString).asString()) }
|
||||
|
||||
val ItemStack.displayNameAccordingToNbt
|
||||
get() = getOrCreateSubNbt(ItemStack.DISPLAY_KEY).let {
|
||||
if (it.contains(ItemStack.NAME_KEY, NbtElement.STRING_TYPE.toInt()))
|
||||
Text.Serializer.fromJson(it.getString(ItemStack.NAME_KEY))
|
||||
else
|
||||
null
|
||||
}
|
||||
4
src/main/kotlin/moe/nea/firmament/util/regex.kt
Normal file
4
src/main/kotlin/moe/nea/firmament/util/regex.kt
Normal file
@@ -0,0 +1,4 @@
|
||||
package moe.nea.firmament.util
|
||||
|
||||
inline fun <T> String.ifMatches(regex: Regex, block: (MatchResult) -> T): T? =
|
||||
regex.matchEntire(this)?.let(block)
|
||||
@@ -76,6 +76,10 @@ class RenderInWorldContext private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun waypoint(position: BlockPos, label: Text) {
|
||||
text(position.toCenterPos(), label, Text.literal("§e${MC.player?.pos?.distanceTo(position.toCenterPos())}m"))
|
||||
}
|
||||
|
||||
fun text(position: Vec3d, vararg texts: Text, verticalAlign: VerticalAlign = VerticalAlign.CENTER) {
|
||||
assertTrueOr(texts.isNotEmpty()) { return@text }
|
||||
matrixStack.push()
|
||||
|
||||
Reference in New Issue
Block a user