aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-05-05 15:33:21 +0200
committerLinnea Gräf <nea@nea.moe>2025-05-05 15:33:21 +0200
commit38fd61fdcc70f75f5b8b5eb39e21c34aaf5ceb90 (patch)
treeb530b475da81a6b31814f96719b249e4e7136a6b
parent0a5a108b157762d251e547c08d206391177e4af9 (diff)
downloadFirmament-38fd61fdcc70f75f5b8b5eb39e21c34aaf5ceb90.tar.gz
Firmament-38fd61fdcc70f75f5b8b5eb39e21c34aaf5ceb90.tar.bz2
Firmament-38fd61fdcc70f75f5b8b5eb39e21c34aaf5ceb90.zip
fix(test): Unit Tests not DFUing itemsHEADmaster
-rw-r--r--src/main/kotlin/features/debug/AnimatedClothingScanner.kt1
-rw-r--r--src/main/kotlin/features/debug/ExportedTestConstantMeta.kt19
-rw-r--r--src/main/kotlin/features/debug/PowerUserTools.kt8
-rw-r--r--src/test/kotlin/testutil/ItemResources.kt52
-rw-r--r--src/test/resources/testdata/chat/all-chat.snbt3
-rw-r--r--src/test/resources/testdata/chat/sacks/gain-and-lose-regular.snbt3
-rw-r--r--src/test/resources/testdata/chat/sacks/gain-rotten-flesh.snbt3
-rw-r--r--src/test/resources/testdata/items/aspect-of-the-void.snbt3
-rw-r--r--src/test/resources/testdata/items/books/feather_falling.snbt3
-rw-r--r--src/test/resources/testdata/items/diamond-pickaxe.snbt3
-rw-r--r--src/test/resources/testdata/items/gemstone-gauntlet.snbt3
-rw-r--r--src/test/resources/testdata/items/hyperion.snbt3
-rw-r--r--src/test/resources/testdata/items/implosion-belt.snbt3
-rw-r--r--src/test/resources/testdata/items/necron-boots.snbt3
-rw-r--r--src/test/resources/testdata/items/pets/lion-item.snbt3
-rw-r--r--src/test/resources/testdata/items/pets/mithril-golem-not-selected.snbt3
-rw-r--r--src/test/resources/testdata/items/pets/rabbit-selected.snbt3
-rw-r--r--src/test/resources/testdata/items/rune-in-sack.snbt3
-rw-r--r--src/test/resources/testdata/items/titanium-drill.snbt3
19 files changed, 114 insertions, 11 deletions
diff --git a/src/main/kotlin/features/debug/AnimatedClothingScanner.kt b/src/main/kotlin/features/debug/AnimatedClothingScanner.kt
index d0db252..47da7d6 100644
--- a/src/main/kotlin/features/debug/AnimatedClothingScanner.kt
+++ b/src/main/kotlin/features/debug/AnimatedClothingScanner.kt
@@ -81,7 +81,6 @@ object AnimatedClothingScanner {
if (subject == null) run {
val entity = MC.instance.targetedEntity ?: return@run null
val clipboard = ClipboardUtils.getTextContents()
- MC.instance.entit
if (!clipboard.startsWith(EXPORT_WATERMARK)) {
ClipboardUtils.setTextContent(EXPORT_WATERMARK)
} else {
diff --git a/src/main/kotlin/features/debug/ExportedTestConstantMeta.kt b/src/main/kotlin/features/debug/ExportedTestConstantMeta.kt
new file mode 100644
index 0000000..a817dd6
--- /dev/null
+++ b/src/main/kotlin/features/debug/ExportedTestConstantMeta.kt
@@ -0,0 +1,19 @@
+package moe.nea.firmament.features.debug
+
+import com.mojang.serialization.Codec
+import com.mojang.serialization.codecs.RecordCodecBuilder
+import java.util.Optional
+
+data class ExportedTestConstantMeta(
+ val dataVersion: Int,
+ val modVersion: Optional<String>,
+) {
+ companion object {
+ val CODEC: Codec<ExportedTestConstantMeta> = RecordCodecBuilder.create {
+ it.group(
+ Codec.INT.fieldOf("dataVersion").forGetter(ExportedTestConstantMeta::dataVersion),
+ Codec.STRING.optionalFieldOf("modVersion").forGetter(ExportedTestConstantMeta::modVersion),
+ ).apply(it, ::ExportedTestConstantMeta)
+ }
+ }
+}
diff --git a/src/main/kotlin/features/debug/PowerUserTools.kt b/src/main/kotlin/features/debug/PowerUserTools.kt
index 251fc8b..4387ced 100644
--- a/src/main/kotlin/features/debug/PowerUserTools.kt
+++ b/src/main/kotlin/features/debug/PowerUserTools.kt
@@ -180,10 +180,10 @@ object PowerUserTools : FirmamentFeature {
Pair(item, Text.stringifiedTranslatable("firmament.tooltip.copied.skull-id", skullTexture.toString()))
println("Copied skull id: $skullTexture")
} else if (it.matches(TConfig.copyItemStack)) {
- ClipboardUtils.setTextContent(
- ItemStack.CODEC
- .encodeStart(MC.currentOrDefaultRegistries.getOps(NbtOps.INSTANCE), item)
- .orThrow.toPrettyString())
+ val nbt = ItemStack.CODEC
+ .encodeStart(MC.currentOrDefaultRegistries.getOps(NbtOps.INSTANCE), item)
+ .orThrow
+ ClipboardUtils.setTextContent(nbt.toPrettyString())
lastCopiedStack = Pair(item, Text.stringifiedTranslatable("firmament.tooltip.copied.stack"))
}
}
diff --git a/src/test/kotlin/testutil/ItemResources.kt b/src/test/kotlin/testutil/ItemResources.kt
index 8631c21..17198f1 100644
--- a/src/test/kotlin/testutil/ItemResources.kt
+++ b/src/test/kotlin/testutil/ItemResources.kt
@@ -1,13 +1,23 @@
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
+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.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 moe.nea.firmament.features.debug.ExportedTestConstantMeta
import moe.nea.firmament.test.FirmTestBootstrap
import moe.nea.firmament.util.MC
@@ -28,15 +38,45 @@ object ItemResources {
}
fun getNbtOps(): RegistryOps<NbtElement> = MC.currentOrDefaultRegistries.getOps(NbtOps.INSTANCE)
+ fun tryMigrateNbt(
+ nbtCompound: NbtCompound,
+ typ: DSL.TypeReference,
+ ): NbtElement {
+ val source = nbtCompound.get("source", ExportedTestConstantMeta.CODEC)
+ nbtCompound.remove("source")
+ if (source.isPresent) {
+ val wrappedNbtSource = if (typ == TypeReferences.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(
+ NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, nbtCompound)
+ .toString())
+ } else {
+ nbtCompound
+ }
+ return Schemas.getFixer()
+ .update(
+ typ,
+ Dynamic(NbtOps.INSTANCE, wrappedNbtSource),
+ source.get().dataVersion,
+ SharedConstants.getGameVersion().saveVersion.id
+ ).value
+ }
+ return nbtCompound
+ }
+
fun loadText(name: String): Text {
- return TextCodecs.CODEC.parse(getNbtOps(), loadSNbt("testdata/chat/$name.snbt"))
- .getOrThrow { IllegalStateException("Could not load test chat '$name': $it") }
+ return TextCodecs.CODEC.parse(
+ getNbtOps(),
+ tryMigrateNbt(loadSNbt("testdata/chat/$name.snbt"), TypeReferences.TEXT_COMPONENT)
+ ).getOrThrow { IllegalStateException("Could not load test chat '$name': $it") }
}
fun loadItem(name: String): ItemStack {
- // TODO: make the load work with enchantments
- // TODO: use DFU to load older items
- return ItemStack.CODEC.parse(getNbtOps(), loadSNbt("testdata/items/$name.snbt"))
- .getOrThrow { IllegalStateException("Could not load test item '$name': $it") }
+ try {
+ val itemNbt = loadSNbt("testdata/items/$name.snbt")
+ return ItemStack.CODEC.parse(getNbtOps(), tryMigrateNbt(itemNbt, TypeReferences.ITEM_STACK)).orThrow
+ } catch (ex: Exception) {
+ throw RuntimeException("Could not load item resource '$name'", ex)
+ }
}
}
diff --git a/src/test/resources/testdata/chat/all-chat.snbt b/src/test/resources/testdata/chat/all-chat.snbt
index 15cc2de..386194b 100644
--- a/src/test/resources/testdata/chat/all-chat.snbt
+++ b/src/test/resources/testdata/chat/all-chat.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
extra: [
{
bold: 0b,
diff --git a/src/test/resources/testdata/chat/sacks/gain-and-lose-regular.snbt b/src/test/resources/testdata/chat/sacks/gain-and-lose-regular.snbt
index 924a558..d7b8b90 100644
--- a/src/test/resources/testdata/chat/sacks/gain-and-lose-regular.snbt
+++ b/src/test/resources/testdata/chat/sacks/gain-and-lose-regular.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
color: "#FFAA00",
extra: [
{
diff --git a/src/test/resources/testdata/chat/sacks/gain-rotten-flesh.snbt b/src/test/resources/testdata/chat/sacks/gain-rotten-flesh.snbt
index 924a558..d7b8b90 100644
--- a/src/test/resources/testdata/chat/sacks/gain-rotten-flesh.snbt
+++ b/src/test/resources/testdata/chat/sacks/gain-rotten-flesh.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
color: "#FFAA00",
extra: [
{
diff --git a/src/test/resources/testdata/items/aspect-of-the-void.snbt b/src/test/resources/testdata/items/aspect-of-the-void.snbt
index 180c069..9ffd385 100644
--- a/src/test/resources/testdata/items/aspect-of-the-void.snbt
+++ b/src/test/resources/testdata/items/aspect-of-the-void.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:attribute_modifiers": {
modifiers: [
diff --git a/src/test/resources/testdata/items/books/feather_falling.snbt b/src/test/resources/testdata/items/books/feather_falling.snbt
index 1de4632..4a0b7c6 100644
--- a/src/test/resources/testdata/items/books/feather_falling.snbt
+++ b/src/test/resources/testdata/items/books/feather_falling.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:attribute_modifiers": {
modifiers: [
diff --git a/src/test/resources/testdata/items/diamond-pickaxe.snbt b/src/test/resources/testdata/items/diamond-pickaxe.snbt
index cce12f9..aa5e590 100644
--- a/src/test/resources/testdata/items/diamond-pickaxe.snbt
+++ b/src/test/resources/testdata/items/diamond-pickaxe.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:attribute_modifiers": {
modifiers: [
diff --git a/src/test/resources/testdata/items/gemstone-gauntlet.snbt b/src/test/resources/testdata/items/gemstone-gauntlet.snbt
index 92ce739..92bb806 100644
--- a/src/test/resources/testdata/items/gemstone-gauntlet.snbt
+++ b/src/test/resources/testdata/items/gemstone-gauntlet.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:attribute_modifiers": {
modifiers: [
diff --git a/src/test/resources/testdata/items/hyperion.snbt b/src/test/resources/testdata/items/hyperion.snbt
index c57d457..f0025b9 100644
--- a/src/test/resources/testdata/items/hyperion.snbt
+++ b/src/test/resources/testdata/items/hyperion.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:attribute_modifiers": {
modifiers: [
diff --git a/src/test/resources/testdata/items/implosion-belt.snbt b/src/test/resources/testdata/items/implosion-belt.snbt
index b73542d..875047d 100644
--- a/src/test/resources/testdata/items/implosion-belt.snbt
+++ b/src/test/resources/testdata/items/implosion-belt.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:attribute_modifiers": {
modifiers: [
diff --git a/src/test/resources/testdata/items/necron-boots.snbt b/src/test/resources/testdata/items/necron-boots.snbt
index 35f8cf0..fd740ce 100644
--- a/src/test/resources/testdata/items/necron-boots.snbt
+++ b/src/test/resources/testdata/items/necron-boots.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:attribute_modifiers": {
modifiers: [
diff --git a/src/test/resources/testdata/items/pets/lion-item.snbt b/src/test/resources/testdata/items/pets/lion-item.snbt
index 6e92685..c364032 100644
--- a/src/test/resources/testdata/items/pets/lion-item.snbt
+++ b/src/test/resources/testdata/items/pets/lion-item.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:attribute_modifiers": {
modifiers: [
diff --git a/src/test/resources/testdata/items/pets/mithril-golem-not-selected.snbt b/src/test/resources/testdata/items/pets/mithril-golem-not-selected.snbt
index c0ef585..79f32c9 100644
--- a/src/test/resources/testdata/items/pets/mithril-golem-not-selected.snbt
+++ b/src/test/resources/testdata/items/pets/mithril-golem-not-selected.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:custom_data": {
id: "PET",
diff --git a/src/test/resources/testdata/items/pets/rabbit-selected.snbt b/src/test/resources/testdata/items/pets/rabbit-selected.snbt
index 48a6f6f..d4c7235 100644
--- a/src/test/resources/testdata/items/pets/rabbit-selected.snbt
+++ b/src/test/resources/testdata/items/pets/rabbit-selected.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:custom_data": {
id: "PET",
diff --git a/src/test/resources/testdata/items/rune-in-sack.snbt b/src/test/resources/testdata/items/rune-in-sack.snbt
index b15488a..4624c0f 100644
--- a/src/test/resources/testdata/items/rune-in-sack.snbt
+++ b/src/test/resources/testdata/items/rune-in-sack.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:custom_data": {
},
diff --git a/src/test/resources/testdata/items/titanium-drill.snbt b/src/test/resources/testdata/items/titanium-drill.snbt
index e3b6819..e49c6b0 100644
--- a/src/test/resources/testdata/items/titanium-drill.snbt
+++ b/src/test/resources/testdata/items/titanium-drill.snbt
@@ -1,4 +1,7 @@
{
+ source: {
+ dataVersion: 4189,
+ },
components: {
"minecraft:attribute_modifiers": {
modifiers: [