@@ -3,69 +3,46 @@ package gg.essential.universal.utils
3
3
import net.minecraft.util.IChatComponent
4
4
5
5
// #if MC>=11600
6
- // $$ import net.minecraft.util.ICharacterConsumer
7
6
// $$ import net.minecraft.util.text.Color
8
7
// $$ import net.minecraft.util.text.Style
9
8
// $$ import net.minecraft.util.text.TextFormatting
9
+ // $$ import java.util.Optional
10
10
// #endif
11
11
12
12
// #if MC>=11602
13
- // $$ private class TextBuilder(private val isFormatted: Boolean) : ICharacterConsumer {
14
- // $$ private val builder = StringBuilder()
15
- // $$ private var cachedStyle: Style? = null
13
+ // $$ private val colorToFormatChar = TextFormatting.values().mapNotNull { format ->
14
+ // $$ Color.fromTextFormatting(format)?.let { it to format }
15
+ // $$ }.toMap()
16
16
// $$
17
- // $$ override fun accept(index: Int, style: Style, codePoint: Int): Boolean {
18
- // $$ if (isFormatted && style != cachedStyle) {
19
- // $$ cachedStyle = style
20
- // $$ builder.append(formatString(style))
21
- // $$ }
22
- // $$
23
- // $$ builder.append(codePoint.toChar())
24
- // $$ return true
25
- // $$ }
26
- // $$
27
- // $$ fun getString() = builder.toString()
28
- // $$
29
- // $$ private fun formatString(style: Style): String {
30
- // $$ val builder = StringBuilder("§r")
31
- // $$
32
- // $$ when {
33
- // $$ style.bold -> builder.append("§l")
34
- // $$ style.italic -> builder.append("§o")
35
- // $$ style.underlined -> builder.append("§n")
36
- // $$ style.strikethrough -> builder.append("§m")
37
- // $$ style.obfuscated -> builder.append("§k")
38
- // $$ }
39
- // $$
40
- // $$ style.color?.let(colorToFormatChar::get)?.let {
41
- // $$ builder.append(it)
42
- // $$ }
43
- // $$ return builder.toString()
44
- // $$ }
45
- // $$
46
- // $$ companion object {
47
- // $$ private val colorToFormatChar = TextFormatting.values().mapNotNull { format ->
48
- // $$ Color.fromTextFormatting(format)?.let { it to format }
49
- // $$ }.toMap()
50
- // $$ }
17
+ // $$ private fun formatString(style: Style): String = buildString {
18
+ // $$ style.color?.let(colorToFormatChar::get)?.let(::append)
19
+ // $$ if (style.isBold) append("§l")
20
+ // $$ if (style.isItalic) append("§o")
21
+ // $$ if (style.isUnderlined) append("§n")
22
+ // $$ if (style.isObfuscated) append("§k")
23
+ // $$ if (style.isStrikethrough) append("§m")
51
24
// $$ }
52
25
// #endif
53
26
54
27
fun IChatComponent.toUnformattedString (): String {
55
28
// #if MC>=11600
56
- // $$ val builder = TextBuilder(false)
57
- // $$ func_241878_f().accept(builder)
58
- // $$ return builder.getString()
29
+ // $$ return string
59
30
// #else
60
31
return unformattedText
61
32
// #endif
62
33
}
63
34
64
35
fun IChatComponent.toFormattedString (): String {
65
36
// #if MC>=11600
66
- // $$ val builder = TextBuilder(true)
67
- // $$ func_241878_f().accept(builder)
68
- // $$ return builder.getString()
37
+ // $$ return buildString {
38
+ // $$ append(formatString(style))
39
+
40
+ // $$ append(it)
41
+ // $$ Optional.empty()
42
+ // $$ }
43
+ // $$ append("§r")
44
+ // $$ siblings.forEach { append(it.toFormattedString()) }
45
+ // $$ }
69
46
// #else
70
47
return formattedText
71
48
// #endif
0 commit comments