Add getLegacyFormatString method

[no changelog]
This commit is contained in:
Linnea Gräf
2024-10-24 14:49:21 +02:00
parent 6100b8c9a0
commit 0357245e88
5 changed files with 223 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ import net.minecraft.item.ItemStack
import net.minecraft.nbt.NbtCompound
import net.minecraft.nbt.NbtOps
import net.minecraft.nbt.StringNbtReader
import net.minecraft.text.Text
import net.minecraft.text.TextCodecs
import moe.nea.firmament.test.FirmTestBootstrap
object ItemResources {
@@ -22,6 +24,11 @@ object ItemResources {
return StringNbtReader.parse(loadString(path))
}
fun loadText(name: String): Text {
return TextCodecs.CODEC.parse(NbtOps.INSTANCE, loadSNbt("testdata/chat/$name.snbt"))
.getOrThrow { IllegalStateException("Could not load test chat '$name': $it") }
}
fun loadItem(name: String): ItemStack {
// TODO: make the load work with enchantments
return ItemStack.CODEC.parse(NbtOps.INSTANCE, loadSNbt("testdata/items/$name.snbt"))

View File

@@ -0,0 +1,15 @@
package moe.nea.firmament.test.util
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import moe.nea.firmament.test.testutil.ItemResources
import moe.nea.firmament.util.getLegacyFormatString
class TextUtilText {
@Test
fun testThing() {
// TODO: add more tests that are directly validated with 1.8.9 code
val text = ItemResources.loadText("all-chat")
Assertions.assertEquals("§r§r§8[§r§9302§r§8] §r§6♫ §r§b[MVP§r§d+§r§b] lrg89§r§f: test§r", text.getLegacyFormatString())
}
}

View File

@@ -0,0 +1,162 @@
{
extra: [
{
bold: 0b,
color: "#555555",
hoverEvent: {
action: "show_text",
contents: {
clickEvent: {
action: "run_command",
value: "command"
},
strikethrough: 0b,
text: "§b[MVP§d+§b] lrg89§f
§7SkyBlock Level: §8[§9302§8]
§7Skill Average: §648.1
§7Emblem: §6♫
§8Harp Master
§7§8Unlocked for All Harp Songs Perfected.
§7Perfect Completions: §b37"
}
},
italic: 0b,
obfuscated: 0b,
strikethrough: 0b,
text: "[",
underlined: 0b
},
{
bold: 0b,
color: "#5555FF",
hoverEvent: {
action: "show_text",
contents: {
clickEvent: {
action: "run_command",
value: "command"
},
strikethrough: 0b,
text: "§b[MVP§d+§b] lrg89§f
§7SkyBlock Level: §8[§9302§8]
§7Skill Average: §648.1
§7Emblem: §6♫
§8Harp Master
§7§8Unlocked for All Harp Songs Perfected.
§7Perfect Completions: §b37"
}
},
italic: 0b,
obfuscated: 0b,
strikethrough: 0b,
text: "302",
underlined: 0b
},
{
bold: 0b,
color: "#555555",
hoverEvent: {
action: "show_text",
contents: {
clickEvent: {
action: "run_command",
value: "command"
},
strikethrough: 0b,
text: "§b[MVP§d+§b] lrg89§f
§7SkyBlock Level: §8[§9302§8]
§7Skill Average: §648.1
§7Emblem: §6♫
§8Harp Master
§7§8Unlocked for All Harp Songs Perfected.
§7Perfect Completions: §b37"
}
},
italic: 0b,
obfuscated: 0b,
strikethrough: 0b,
text: "] ",
underlined: 0b
},
{
bold: 0b,
color: "#FFAA00",
hoverEvent: {
action: "show_text",
contents: {
clickEvent: {
action: "run_command",
value: "command"
},
strikethrough: 0b,
text: "§b[MVP§d+§b] lrg89§f
§7SkyBlock Level: §8[§9302§8]
§7Skill Average: §648.1
§7Emblem: §6♫
§8Harp Master
§7§8Unlocked for All Harp Songs Perfected.
§7Perfect Completions: §b37"
}
},
italic: 0b,
obfuscated: 0b,
strikethrough: 0b,
text: "♫ ",
underlined: 0b
},
{
bold: 0b,
color: "#55FFFF",
italic: 0b,
obfuscated: 0b,
strikethrough: 0b,
text: "[MVP",
underlined: 0b
},
{
bold: 0b,
color: "#FF55FF",
italic: 0b,
obfuscated: 0b,
strikethrough: 0b,
text: "+",
underlined: 0b
},
{
bold: 0b,
color: "#55FFFF",
italic: 0b,
obfuscated: 0b,
strikethrough: 0b,
text: "] lrg89",
underlined: 0b
},
{
bold: 0b,
color: "#FFFFFF",
italic: 0b,
obfuscated: 0b,
strikethrough: 0b,
text: ": test",
underlined: 0b
}
],
strikethrough: 0b,
text: ""
}