diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-11-17 19:55:02 +0100 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-11-17 19:55:02 +0100 |
| commit | c93a04a001b0f66b2724d46b04b6d1ed49a08d07 (patch) | |
| tree | 5869ca70acc482ef0362f27785c3d3f1cbb9ffae /src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt | |
| parent | af9893b59407c69d31ebd2ed513f0396ab4d2dc9 (diff) | |
| download | Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.gz Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.bz2 Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.zip | |
refactor: port to mojmaps
Diffstat (limited to 'src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt')
| -rw-r--r-- | src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt index a9ac6d9..ed486f5 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt @@ -3,9 +3,9 @@ package moe.nea.firmament.features.texturepack import java.util.regex.Matcher import util.json.CodecSerializer import kotlinx.serialization.Serializable -import net.minecraft.text.Style -import net.minecraft.text.Text -import net.minecraft.text.TextCodecs +import net.minecraft.network.chat.Style +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.ComponentSerialization import moe.nea.firmament.util.directLiteralStringContent import moe.nea.firmament.util.transformEachRecursively @@ -16,16 +16,16 @@ data class TreeishTextReplacer( ) { @Serializable data class SubPartReplacement( - val match: StringMatcher, - val style: @Serializable(StyleSerializer::class) Style? = null, - val replace: @Serializable(TextSerializer::class) Text, + val match: StringMatcher, + val style: @Serializable(StyleSerializer::class) Style? = null, + val replace: @Serializable(TextSerializer::class) Component, ) - object TextSerializer : CodecSerializer<Text>(TextCodecs.CODEC) - object StyleSerializer : CodecSerializer<Style>(Style.Codecs.CODEC) + object TextSerializer : CodecSerializer<Component>(ComponentSerialization.CODEC) + object StyleSerializer : CodecSerializer<Style>(Style.Serializer.CODEC) companion object { val pattern = "[$]\\{(?<name>[^}]+)}".toPattern() - fun injectMatchResults(text: Text, matches: Matcher): Text { + fun injectMatchResults(text: Component, matches: Matcher): Component { return text.transformEachRecursively { it -> val content = it.directLiteralStringContent ?: return@transformEachRecursively it val matcher = pattern.matcher(content) @@ -34,34 +34,34 @@ data class TreeishTextReplacer( matcher.appendReplacement(builder, matches.group(matcher.group("name")).toString()) } matcher.appendTail(builder) - Text.literal(builder.toString()).setStyle(it.style) + Component.literal(builder.toString()).setStyle(it.style) } } } - fun match(text: Text): Boolean { + fun match(text: Component): Boolean { return match.matches(text) } - fun replaceText(text: Text): Text { + fun replaceText(text: Component): Component { return text.transformEachRecursively { part -> - var part: Text = part + var part: Component = part for (replacement in replacements) { val rawPartText = part.string replacement.style?.let { expectedStyle -> val parentStyle = part.style - val parented = expectedStyle.withParent(parentStyle) + val parented = expectedStyle.applyTo(parentStyle) if (parented.isStrikethrough != parentStyle.isStrikethrough || parented.isObfuscated != parentStyle.isObfuscated || parented.isBold != parentStyle.isBold || parented.isUnderlined != parentStyle.isUnderlined || parented.isItalic != parentStyle.isItalic - || parented.color?.rgb != parentStyle.color?.rgb) + || parented.color?.value != parentStyle.color?.value) continue } val matcher = replacement.match.asRegex.matcher(rawPartText) if (!matcher.find()) continue - val p = Text.literal("") + val p = Component.literal("") p.setStyle(part.style) var lastAppendPosition = 0 do { |
