diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-11-17 19:55:02 +0100 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-11-17 19:55:02 +0100 |
| commit | c93a04a001b0f66b2724d46b04b6d1ed49a08d07 (patch) | |
| tree | 5869ca70acc482ef0362f27785c3d3f1cbb9ffae /src/test/kotlin/testutil | |
| parent | af9893b59407c69d31ebd2ed513f0396ab4d2dc9 (diff) | |
| download | Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.gz Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.bz2 Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.zip | |
refactor: port to mojmaps
Diffstat (limited to 'src/test/kotlin/testutil')
| -rw-r--r-- | src/test/kotlin/testutil/ItemResources.kt | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/test/kotlin/testutil/ItemResources.kt b/src/test/kotlin/testutil/ItemResources.kt index 60925c7..5f08847 100644 --- a/src/test/kotlin/testutil/ItemResources.kt +++ b/src/test/kotlin/testutil/ItemResources.kt @@ -4,17 +4,17 @@ import com.mojang.datafixers.DSL import com.mojang.serialization.Dynamic import com.mojang.serialization.JsonOps import net.minecraft.SharedConstants -import net.minecraft.datafixer.Schemas -import net.minecraft.datafixer.TypeReferences -import net.minecraft.item.ItemStack -import net.minecraft.nbt.NbtCompound -import net.minecraft.nbt.NbtElement +import net.minecraft.util.datafix.DataFixers +import net.minecraft.util.datafix.fixes.References +import net.minecraft.world.item.ItemStack +import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.Tag import net.minecraft.nbt.NbtOps -import net.minecraft.nbt.NbtString -import net.minecraft.nbt.StringNbtReader -import net.minecraft.registry.RegistryOps -import net.minecraft.text.Text -import net.minecraft.text.TextCodecs +import net.minecraft.nbt.StringTag +import net.minecraft.nbt.TagParser +import net.minecraft.resources.RegistryOps +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.ComponentSerialization import moe.nea.firmament.features.debug.ExportedTestConstantMeta import moe.nea.firmament.test.FirmTestBootstrap import moe.nea.firmament.util.MC @@ -32,22 +32,22 @@ object ItemResources { .readAllBytes().decodeToString() } - fun loadSNbt(path: String): NbtCompound { - return StringNbtReader.readCompound(loadString(path)) + fun loadSNbt(path: String): CompoundTag { + return TagParser.parseCompoundFully(loadString(path)) } - fun getNbtOps(): RegistryOps<NbtElement> = MC.currentOrDefaultRegistries.getOps(NbtOps.INSTANCE) + fun getNbtOps(): RegistryOps<Tag> = MC.currentOrDefaultRegistries.createSerializationContext(NbtOps.INSTANCE) fun tryMigrateNbt( - nbtCompound: NbtCompound, - typ: DSL.TypeReference?, - ): NbtElement { - val source = nbtCompound.get("source", ExportedTestConstantMeta.CODEC) + nbtCompound: CompoundTag, + typ: DSL.TypeReference?, + ): Tag { + val source = nbtCompound.read("source", ExportedTestConstantMeta.CODEC) nbtCompound.remove("source") if (source.isPresent) { - val wrappedNbtSource = if (typ == TypeReferences.TEXT_COMPONENT && source.get().dataVersion < 4325) { + val wrappedNbtSource = if (typ == References.TEXT_COMPONENT && source.get().dataVersion < 4325) { // Per 1.21.5 text components are wrapped in a string, which firmament unwrapped in the snbt files - NbtString.of( + StringTag.valueOf( NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, nbtCompound) .toString() ) @@ -55,12 +55,12 @@ object ItemResources { nbtCompound } if (typ != null) { - return Schemas.getFixer() + return DataFixers.getDataFixer() .update( typ, Dynamic(NbtOps.INSTANCE, wrappedNbtSource), source.get().dataVersion, - SharedConstants.getGameVersion().dataVersion().id + SharedConstants.getCurrentVersion().dataVersion().version ).value } else { wrappedNbtSource @@ -76,17 +76,17 @@ object ItemResources { ).getOrThrow { IllegalStateException("Could not load tablist '$name': $it") } } - fun loadText(name: String): Text { - return TextCodecs.CODEC.parse( + fun loadText(name: String): Component { + return ComponentSerialization.CODEC.parse( getNbtOps(), - tryMigrateNbt(loadSNbt("testdata/chat/$name.snbt"), TypeReferences.TEXT_COMPONENT) + tryMigrateNbt(loadSNbt("testdata/chat/$name.snbt"), References.TEXT_COMPONENT) ).getOrThrow { IllegalStateException("Could not load test chat '$name': $it") } } fun loadItem(name: String): ItemStack { try { val itemNbt = loadSNbt("testdata/items/$name.snbt") - return ItemStack.CODEC.parse(getNbtOps(), tryMigrateNbt(itemNbt, TypeReferences.ITEM_STACK)).orThrow + return ItemStack.CODEC.parse(getNbtOps(), tryMigrateNbt(itemNbt, References.ITEM_STACK)).orThrow } catch (ex: Exception) { throw RuntimeException("Could not load item resource '$name'", ex) } |
