1.20.4: fix sign nbt text wrapping

This commit is contained in:
Moritz Zwerger 2023-12-10 02:26:35 +01:00
parent cdaa65dfec
commit a1573d9ad7
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 32 additions and 1 deletions

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.entities.block.sign
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.minosoft.data.language.lang.Language import de.bixilon.minosoft.data.language.lang.Language
import de.bixilon.minosoft.data.text.ChatComponent 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.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.test.IT import de.bixilon.minosoft.test.IT
@ -68,4 +69,26 @@ class SignBlockEntityTest {
assertEquals(entity.back.color, ChatColors.BLUE) 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."))) 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("")))
}
} }

View File

@ -60,11 +60,19 @@ class SignBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
val text: Array<ChatComponent> = Array(LINES) { EmptyComponent }, 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) { fun update(data: JsonObject, connection: PlayConnection) {
update(data["color"], data["has_glowing_text"]) update(data["color"], data["has_glowing_text"])
data["messages"]?.asJsonList()?.let { data["messages"]?.asJsonList()?.let {
for ((index, line) in it.withIndex()) { for ((index, line) in it.withIndex()) {
this.text[index] = ChatComponent.of(line, translator = connection.language) this.text[index] = parseText(line, connection)
} }
} }
} }