Add image preview

This commit is contained in:
nea
2023-07-22 03:08:56 +02:00
parent 538827af3b
commit cdf3938b77
10 changed files with 231 additions and 14 deletions

View File

@@ -28,6 +28,8 @@ object MC {
player?.networkHandler?.sendCommand(command)
}
inline val textureManager get() = MinecraftClient.getInstance().textureManager
inline val inGameHud get() = MinecraftClient.getInstance().inGameHud
inline val font get() = MinecraftClient.getInstance().textRenderer
inline val soundManager get() = MinecraftClient.getInstance().soundManager
inline val player get() = MinecraftClient.getInstance().player

View File

@@ -21,6 +21,7 @@ package moe.nea.firmament.util
import net.minecraft.text.LiteralTextContent
import net.minecraft.text.Text
import net.minecraft.text.TextContent
import net.minecraft.text.TranslatableTextContent
import moe.nea.firmament.Firmament
@@ -86,3 +87,23 @@ class TextMatcher(text: Text) {
val Text.unformattedString
get() = string.replace("§.".toRegex(), "")
fun Text.transformEachRecursively(function: (Text) -> Text): Text {
val c = this.content
if (c is TranslatableTextContent) {
return Text.translatableWithFallback(c.key, c.fallback, *c.args.map {
(if (it is Text) it else Text.literal(it.toString())).transformEachRecursively(function)
}.toTypedArray()).also { new ->
new.style = this.style
new.siblings.clear()
this.siblings.forEach { child ->
new.siblings.add(child.transformEachRecursively(function))
}
}
}
return function(this.copy().also { it.siblings.clear() }).also { tt ->
this.siblings.forEach {
tt.siblings.add(it.transformEachRecursively(function))
}
}
}