Fix recursively converting JSON Text Components

See 142ec80d28
This commit is contained in:
Spottedleaf 2025-06-17 16:38:01 -07:00
parent 023e6c2953
commit 40d5d31c83

View file

@ -217,10 +217,10 @@ index 0000000000000000000000000000000000000000..515f6691c72ffa82ac8b92646768be7a
+}
diff --git a/ca/spottedleaf/dataconverter/minecraft/MCVersionRegistry.java b/ca/spottedleaf/dataconverter/minecraft/MCVersionRegistry.java
new file mode 100644
index 0000000000000000000000000000000000000000..79b65b275a698d86cb43d8b14e9ed7f6bf5c9da6
index 0000000000000000000000000000000000000000..9ed6c1512139c33dd695e4b3523b0382e4cde0ff
--- /dev/null
+++ b/ca/spottedleaf/dataconverter/minecraft/MCVersionRegistry.java
@@ -0,0 +1,485 @@
@@ -0,0 +1,487 @@
+package ca.spottedleaf.dataconverter.minecraft;
+
+import ca.spottedleaf.dataconverter.converters.DataConverter;
@ -503,7 +503,7 @@ index 0000000000000000000000000000000000000000..79b65b275a698d86cb43d8b14e9ed7f6
+ 4314,
+ 4420,
+ 4424,
+ // All up to 1.21.6-rc1
+ // All up to 1.21.6
+ };
+ Arrays.sort(converterVersions);
+
@ -530,6 +530,8 @@ index 0000000000000000000000000000000000000000..79b65b275a698d86cb43d8b14e9ed7f6
+ registerSubVersion(MCVersions.V24W07A + 1, 5);
+ registerSubVersion(MCVersions.V24W07A + 1, 6);
+
+ registerSubVersion(V4290.VERSION, 1);
+
+ // register breakpoints here
+ // for all major releases after 1.16, add them. this reduces the work required to determine if a breakpoint
+ // is needed for new converters
@ -556,7 +558,7 @@ index 0000000000000000000000000000000000000000..79b65b275a698d86cb43d8b14e9ed7f6
+
+ // There is a read of entity sub data in V4299 (salmon) which was written to after V1_20_6
+ // There is also a sub type read in V4290 as it reads and converts all data within a text component
+ registerBreakpointBefore(V4290.VERSION);
+ registerBreakpointAfter(V4290.VERSION);
+ }
+
+ static {
@ -708,10 +710,10 @@ index 0000000000000000000000000000000000000000..79b65b275a698d86cb43d8b14e9ed7f6
+}
diff --git a/ca/spottedleaf/dataconverter/minecraft/MCVersions.java b/ca/spottedleaf/dataconverter/minecraft/MCVersions.java
new file mode 100644
index 0000000000000000000000000000000000000000..469a3241f1d81d82394efbf8da3258210321046c
index 0000000000000000000000000000000000000000..03cf3ecebdb6629f11465d842bdd6263f19863c6
--- /dev/null
+++ b/ca/spottedleaf/dataconverter/minecraft/MCVersions.java
@@ -0,0 +1,596 @@
@@ -0,0 +1,597 @@
+package ca.spottedleaf.dataconverter.minecraft;
+
+@SuppressWarnings("unused")
@ -1305,6 +1307,7 @@ index 0000000000000000000000000000000000000000..469a3241f1d81d82394efbf8da325821
+ public static final int V1_21_6_PRE3 = 4432;
+ public static final int V1_21_6_PRE4 = 4433;
+ public static final int V1_21_6_RC1 = 4434;
+ public static final int V1_21_6 = 4435;
+
+ private MCVersions() {}
+}
@ -9898,6 +9901,90 @@ index 0000000000000000000000000000000000000000..17ded002b5546de8be4a5238c20ccfda
+
+ private ComponentUtils() {}
+}
diff --git a/ca/spottedleaf/dataconverter/minecraft/util/StringWalker.java b/ca/spottedleaf/dataconverter/minecraft/util/StringWalker.java
new file mode 100644
index 0000000000000000000000000000000000000000..4e1add641c092b241b48e93732dab4ef646eafc3
--- /dev/null
+++ b/ca/spottedleaf/dataconverter/minecraft/util/StringWalker.java
@@ -0,0 +1,78 @@
+package ca.spottedleaf.dataconverter.minecraft.util;
+
+public final class StringWalker {
+
+ public final String string;
+ private int index; // index of next value to return
+ private final int maxIndex; // exclusive
+
+ public StringWalker(final String string) {
+ this(string, 0);
+ }
+
+ public StringWalker(final String string, final int index) {
+ this(string, index, string.length());
+ }
+
+ public StringWalker(final String string, final int index, final int maxIndex) {
+ this.string = string;
+ this.index = index;
+ this.maxIndex = maxIndex;
+
+ if (maxIndex < 0 || maxIndex > string.length()) {
+ throw new IllegalArgumentException("Max index out of string range");
+ }
+
+ if (index < 0 || index > maxIndex) {
+ throw new IllegalArgumentException("Index out of string range");
+ }
+ }
+
+ public int getIndex() {
+ return this.index;
+ }
+
+ public void setIndex(final int to) {
+ this.index = to;
+ }
+
+ private void checkNext() {
+ if (!this.hasNext()) {
+ throw this.parseFail(this.getIndex(), "Expecting more input");
+ }
+ }
+
+ public boolean hasNext() {
+ return this.index < this.maxIndex;
+ }
+
+ public char next() {
+ return this.string.charAt(this.index++);
+ }
+
+ public char peek() {
+ return this.string.charAt(this.index);
+ }
+
+ public void advance() {
+ ++this.index;
+ }
+
+ public void skipWhitespace() {
+ while (this.hasNext() || Character.isWhitespace(this.peek())) {
+ this.advance();
+ }
+ }
+
+ public boolean skipIf(final char c) {
+ if (this.hasNext() && this.peek() == c) {
+ this.advance();
+ return true;
+ }
+ return false;
+ }
+
+ public IllegalStateException parseFail(final int index, final String reason) {
+ return new IllegalStateException("At column " + index + ": " + reason);
+ }
+}
diff --git a/ca/spottedleaf/dataconverter/minecraft/util/Version.java b/ca/spottedleaf/dataconverter/minecraft/util/Version.java
new file mode 100644
index 0000000000000000000000000000000000000000..c289ec6b7f6d199182ffdfb1cd95a1746bfd6e76
@ -24764,15 +24851,13 @@ index 0000000000000000000000000000000000000000..7d09c4218d0db8119d1681bf95900be8
+}
diff --git a/ca/spottedleaf/dataconverter/minecraft/versions/V4290.java b/ca/spottedleaf/dataconverter/minecraft/versions/V4290.java
new file mode 100644
index 0000000000000000000000000000000000000000..4197a5e89aec77f2893f0f118a927b96d5377ec1
index 0000000000000000000000000000000000000000..ca9e3667b420f54f42b358068c102fe0cae4102d
--- /dev/null
+++ b/ca/spottedleaf/dataconverter/minecraft/versions/V4290.java
@@ -0,0 +1,248 @@
@@ -0,0 +1,247 @@
+package ca.spottedleaf.dataconverter.minecraft.versions;
+
+import ca.spottedleaf.dataconverter.converters.DataConverter;
+import ca.spottedleaf.dataconverter.converters.datatypes.DataType;
+import ca.spottedleaf.dataconverter.minecraft.MCDataConverter;
+import ca.spottedleaf.dataconverter.minecraft.MCVersions;
+import ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry;
+import ca.spottedleaf.dataconverter.minecraft.walkers.generic.WalkerUtils;
@ -24968,7 +25053,8 @@ index 0000000000000000000000000000000000000000..4197a5e89aec77f2893f0f118a927b96
+ }
+ });
+
+ MCTypeRegistry.TEXT_COMPONENT.addStructureWalker(VERSION, (final Object input, final long fromVersion, final long toVersion) -> {
+ // step 1
+ MCTypeRegistry.TEXT_COMPONENT.addStructureWalker(VERSION, 1, (final Object input, final long fromVersion, final long toVersion) -> {
+ if (input instanceof ListType listType) {
+ WalkerUtils.convert(MCTypeRegistry.TEXT_COMPONENT, listType, fromVersion, toVersion);
+ } else if (input instanceof MapType root) {
@ -30357,10 +30443,10 @@ index 0000000000000000000000000000000000000000..6704da4a40522a4f40cd770a4cbaaa8e
+}
diff --git a/ca/spottedleaf/dataconverter/types/json/JsonTypeUtil.java b/ca/spottedleaf/dataconverter/types/json/JsonTypeUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..d96808060623f73b08dec8eb6d6fdfca4d309d16
index 0000000000000000000000000000000000000000..3ace24bdd5e5da4333e25c9c681007e6a85d52ab
--- /dev/null
+++ b/ca/spottedleaf/dataconverter/types/json/JsonTypeUtil.java
@@ -0,0 +1,189 @@
@@ -0,0 +1,181 @@
+package ca.spottedleaf.dataconverter.types.json;
+
+import ca.spottedleaf.dataconverter.minecraft.converters.helpers.CopyHelper;
@ -30541,14 +30627,6 @@ index 0000000000000000000000000000000000000000..d96808060623f73b08dec8eb6d6fdfca
+
+ return ret;
+ }
+
+ private static MapType convertJson(final TypeUtil<?> to, final JsonMapType json) {
+ return convertJson(to, json.map, json.compressed);
+ }
+
+ private static ListType convertJson(final TypeUtil<?> to, final JsonListType json) {
+ return convertJson(to, json.array, json.compressed);
+ }
+}
diff --git a/ca/spottedleaf/dataconverter/types/nbt/NBTListType.java b/ca/spottedleaf/dataconverter/types/nbt/NBTListType.java
new file mode 100644
@ -31588,10 +31666,10 @@ index 0000000000000000000000000000000000000000..2558d9014e1daff6dd4a44ad85bbc025
+}
diff --git a/ca/spottedleaf/dataconverter/types/nbt/NBTTypeUtil.java b/ca/spottedleaf/dataconverter/types/nbt/NBTTypeUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..32d90fc5ab415b0261af8377b130404ad37e19ee
index 0000000000000000000000000000000000000000..61e98240a221a75780e311c0777a8c43c4297d65
--- /dev/null
+++ b/ca/spottedleaf/dataconverter/types/nbt/NBTTypeUtil.java
@@ -0,0 +1,136 @@
@@ -0,0 +1,128 @@
+package ca.spottedleaf.dataconverter.types.nbt;
+
+import ca.spottedleaf.dataconverter.minecraft.converters.helpers.CopyHelper;
@ -31719,14 +31797,6 @@ index 0000000000000000000000000000000000000000..32d90fc5ab415b0261af8377b130404a
+
+ return ret;
+ }
+
+ public static MapType convertNBT(final TypeUtil<?> to, final NBTMapType nbt) {
+ return convertNBT(to, nbt.map);
+ }
+
+ public static ListType convertNBT(final TypeUtil<?> to, final NBTListType nbt) {
+ return convertNBT(to, nbt.list);
+ }
+}
diff --git a/ca/spottedleaf/dataconverter/util/Int2IntArraySortedMap.java b/ca/spottedleaf/dataconverter/util/Int2IntArraySortedMap.java
new file mode 100644