mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
1.20.4: fix sign nbt text wrapping
This commit is contained in:
parent
cdaa65dfec
commit
a1573d9ad7
@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.entities.block.sign
|
||||
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
|
||||
import de.bixilon.minosoft.data.language.lang.Language
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.TextComponent
|
||||
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.test.IT
|
||||
@ -68,4 +69,26 @@ class SignBlockEntityTest {
|
||||
assertEquals(entity.back.color, ChatColors.BLUE)
|
||||
assertEquals(entity.back.text, arrayOf(ChatComponent.of("This is the back"), ChatComponent.of("text"), ChatComponent.of("of"), ChatComponent.of("this sign.")))
|
||||
}
|
||||
fun `nbt 1_20_4`() {
|
||||
val nbt = mapOf(
|
||||
"is_waxed" to 1.toByte(),
|
||||
"front_text" to mapOf(
|
||||
"has_glowing_text" to 1.toByte(),
|
||||
"color" to "red",
|
||||
"messages" to listOf(
|
||||
"\"Very long line\"",
|
||||
"\"\"",
|
||||
"\"\"",
|
||||
"\"\"",
|
||||
)
|
||||
),
|
||||
)
|
||||
val entity = create()
|
||||
entity.updateNBT(nbt)
|
||||
|
||||
assertTrue(entity.waxed)
|
||||
assertTrue(entity.front.glowing)
|
||||
assertEquals(entity.front.color, ChatColors.RED)
|
||||
assertEquals(entity.front.text, arrayOf(TextComponent("Very long line"), ChatComponent.of(""), ChatComponent.of(""), ChatComponent.of("")))
|
||||
}
|
||||
}
|
||||
|
@ -60,11 +60,19 @@ class SignBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
|
||||
val text: Array<ChatComponent> = Array(LINES) { EmptyComponent },
|
||||
) {
|
||||
|
||||
private fun parseText(line: Any?, connection: PlayConnection): ChatComponent {
|
||||
if (line is String && line.startsWith("\"")) {
|
||||
// TODO: minecraft 1.20.4 wraps it in "???
|
||||
return ChatComponent.of(line.removeSurrounding("\""))
|
||||
}
|
||||
return ChatComponent.of(line, translator = connection.language)
|
||||
}
|
||||
|
||||
fun update(data: JsonObject, connection: PlayConnection) {
|
||||
update(data["color"], data["has_glowing_text"])
|
||||
data["messages"]?.asJsonList()?.let {
|
||||
for ((index, line) in it.withIndex()) {
|
||||
this.text[index] = ChatComponent.of(line, translator = connection.language)
|
||||
this.text[index] = parseText(line, connection)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user