diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-06-26 18:21:02 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-06-26 18:21:11 +0200 |
| commit | 1c5d0df368471031f892330de7628ff78a6204ed (patch) | |
| tree | 6d222fb45f3fbacff255de5347314204189a8b3c /src/test/kotlin | |
| parent | e926550bd19bddb0a0e026723bc6113ac09ea76f (diff) | |
| download | Firmament-1c5d0df368471031f892330de7628ff78a6204ed.tar.gz Firmament-1c5d0df368471031f892330de7628ff78a6204ed.tar.bz2 Firmament-1c5d0df368471031f892330de7628ff78a6204ed.zip | |
feat(internal): Add a tab list api
Diffstat (limited to 'src/test/kotlin')
| -rw-r--r-- | src/test/kotlin/testutil/ItemResources.kt | 34 | ||||
| -rw-r--r-- | src/test/kotlin/util/skyblock/TabListAPITest.kt | 48 |
2 files changed, 71 insertions, 11 deletions
diff --git a/src/test/kotlin/testutil/ItemResources.kt b/src/test/kotlin/testutil/ItemResources.kt index 17198f1..e996fc2 100644 --- a/src/test/kotlin/testutil/ItemResources.kt +++ b/src/test/kotlin/testutil/ItemResources.kt @@ -1,8 +1,6 @@ package moe.nea.firmament.test.testutil import com.mojang.datafixers.DSL -import com.mojang.datafixers.DataFixUtils -import com.mojang.datafixers.types.templates.Named import com.mojang.serialization.Dynamic import com.mojang.serialization.JsonOps import net.minecraft.SharedConstants @@ -20,6 +18,7 @@ import net.minecraft.text.TextCodecs import moe.nea.firmament.features.debug.ExportedTestConstantMeta import moe.nea.firmament.test.FirmTestBootstrap import moe.nea.firmament.util.MC +import moe.nea.firmament.util.mc.MCTabListAPI object ItemResources { init { @@ -36,11 +35,12 @@ object ItemResources { fun loadSNbt(path: String): NbtCompound { return StringNbtReader.readCompound(loadString(path)) } + fun getNbtOps(): RegistryOps<NbtElement> = MC.currentOrDefaultRegistries.getOps(NbtOps.INSTANCE) fun tryMigrateNbt( nbtCompound: NbtCompound, - typ: DSL.TypeReference, + typ: DSL.TypeReference?, ): NbtElement { val source = nbtCompound.get("source", ExportedTestConstantMeta.CODEC) nbtCompound.remove("source") @@ -49,21 +49,33 @@ object ItemResources { // Per 1.21.5 text components are wrapped in a string, which firmament unwrapped in the snbt files NbtString.of( NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, nbtCompound) - .toString()) + .toString() + ) } else { nbtCompound } - return Schemas.getFixer() - .update( - typ, - Dynamic(NbtOps.INSTANCE, wrappedNbtSource), - source.get().dataVersion, - SharedConstants.getGameVersion().saveVersion.id - ).value + if (typ != null) { + return Schemas.getFixer() + .update( + typ, + Dynamic(NbtOps.INSTANCE, wrappedNbtSource), + source.get().dataVersion, + SharedConstants.getGameVersion().saveVersion.id + ).value + } else { + wrappedNbtSource + } } return nbtCompound } + fun loadTablist(name: String): MCTabListAPI.CurrentTabList { + return MCTabListAPI.CurrentTabList.CODEC.parse( + getNbtOps(), + tryMigrateNbt(loadSNbt("testdata/tablist/$name.snbt"), null), + ).getOrThrow { IllegalStateException("Could not load tablist '$name': $it") } + } + fun loadText(name: String): Text { return TextCodecs.CODEC.parse( getNbtOps(), diff --git a/src/test/kotlin/util/skyblock/TabListAPITest.kt b/src/test/kotlin/util/skyblock/TabListAPITest.kt new file mode 100644 index 0000000..26eafe0 --- /dev/null +++ b/src/test/kotlin/util/skyblock/TabListAPITest.kt @@ -0,0 +1,48 @@ +package moe.nea.firmament.test.util.skyblock + +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test +import moe.nea.firmament.test.testutil.ItemResources +import moe.nea.firmament.util.skyblock.TabListAPI + +class TabListAPITest { + val tablist = ItemResources.loadTablist("dungeon_hub") + + @Test + fun checkWithTitle() { + Assertions.assertEquals( + listOf( + "Profile: Strawberry", + " SB Level: [210] 26/100 XP", + " Bank: 1.4B", + " Interest: 12 Hours (689.1k)", + ), + TabListAPI.getWidgetLines(TabListAPI.WidgetName.PROFILE, includeTitle = true, from = tablist).map { it.string }) + } + + @Test + fun checkEndOfColumn() { + Assertions.assertEquals( + listOf( + " Bonzo IV: 110/150", + " Scarf II: 25/50", + " The Professor IV: 141/150", + " Thorn I: 29/50", + " Livid II: 91/100", + " Sadan V: 388/500", + " Necron VI: 531/750", + ), + TabListAPI.getWidgetLines(TabListAPI.WidgetName.COLLECTION, from = tablist).map { it.string } + ) + } + + @Test + fun checkWithoutTitle() { + Assertions.assertEquals( + listOf( + " Undead: 1,907", + " Wither: 318", + ), + TabListAPI.getWidgetLines(TabListAPI.WidgetName.ESSENCE, from = tablist).map { it.string }) + } +} |
