diff options
author | nea <nea@nea.moe> | 2023-07-22 03:08:56 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-07-22 03:08:56 +0200 |
commit | cdf3938b778188211ad316d16381e0d8c7beac75 (patch) | |
tree | eb3508942f61bee290b0558c97c3e04946070b0a /src/main/kotlin/moe/nea/firmament/util | |
parent | 538827af3bfccbc4cee1ff2e9cb76922108ace9e (diff) | |
download | Firmament-cdf3938b778188211ad316d16381e0d8c7beac75.tar.gz Firmament-cdf3938b778188211ad316d16381e0d8c7beac75.tar.bz2 Firmament-cdf3938b778188211ad316d16381e0d8c7beac75.zip |
Add image preview
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/util/MC.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/util/textutil.kt | 21 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt index d595b61..e6e53fa 100644 --- a/src/main/kotlin/moe/nea/firmament/util/MC.kt +++ b/src/main/kotlin/moe/nea/firmament/util/MC.kt @@ -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 diff --git a/src/main/kotlin/moe/nea/firmament/util/textutil.kt b/src/main/kotlin/moe/nea/firmament/util/textutil.kt index 3096282..5c443c3 100644 --- a/src/main/kotlin/moe/nea/firmament/util/textutil.kt +++ b/src/main/kotlin/moe/nea/firmament/util/textutil.kt @@ -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)) + } + } +} |