Update ViaNBT

This commit is contained in:
Nassim Jahnke 2024-03-07 13:19:44 +01:00
parent d062e4d066
commit b403949438
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 194 additions and 23 deletions

View File

@ -2,7 +2,7 @@ import os
import re
import subprocess
via_nbt_version = '3.5.0'
via_nbt_version = '4.4.0'
# All of this would work better with bytecode rewriting, but here we go
replacements = {
@ -16,11 +16,6 @@ replacements = {
'import net.lenni0451.mcstructs.nbt.': 'import com.github.steveice10.opennbt.tag.builtin.',
'INbtTag': 'Tag',
'INbtNumber': 'NumberTag',
'ListTag<>': 'ListTag',
'ListTag<Tag>': 'ListTag',
'ListTag<CompoundTag>': 'ListTag',
'ListTag<T>': 'ListTag',
'ListTag<?>': 'ListTag',
'tag.getNbtType()': 'tag',
'ArrayTag.getLength()': 'ArrayTag.length()',
'ArrayTag.get(': 'ArrayTag.getValue(',
@ -104,7 +99,7 @@ def replace_get_value(content, obj):
content)
content = replace_nonnull_get(obj, 'Compound', '', 'new CompoundTag()', content)
content = replace_nonnull_get(obj, 'List', '', 'new ListTag()', content)
content = replace_nonnull_get(obj, 'List', '', 'new ListTag<>()', content)
content = replace_nonnull_get(obj, 'String', '.getValue()', '""', content)
content = replace_nonnull_get(obj, 'ByteArray', '.getValue()', 'new byte[0]', content)
content = replace_nonnull_get(obj, 'IntArray', '.getValue()', 'new int[0]', content)

View File

@ -1,5 +1,5 @@
diff --git a/MCStructs-snbt/src/main/java/net/lenni0451/mcstructs/snbt/impl/v1_12/SNbtDeserializer_v1_12.java b/MCStructs-snbt/src/main/java/net/lenni0451/mcstructs/snbt/impl/v1_12/SNbtDeserializer_v1_12.java
index 8bec86c..3525056 100644
index 851d33c..2a55603 100644
--- a/MCStructs-snbt/src/main/java/net/lenni0451/mcstructs/snbt/impl/v1_12/SNbtDeserializer_v1_12.java
+++ b/MCStructs-snbt/src/main/java/net/lenni0451/mcstructs/snbt/impl/v1_12/SNbtDeserializer_v1_12.java
@@ -95,10 +95,28 @@ public class SNbtDeserializer_v1_12 implements ISNbtDeserializer<CompoundTag> {
@ -11,21 +11,21 @@ index 8bec86c..3525056 100644
- else if (c == 'I') return new IntArrayTag(this.readPrimitiveList(reader, IntTag.class, IntArrayTag.class));
- else throw new SNbtDeserializeException("Invalid array type '" + c + "' found");
+ else if (c == 'B') {
+ final ListTag tags = this.readPrimitiveList(reader, ByteTag.class, ByteArrayTag.class);
+ final ListTag<ByteTag> tags = this.readPrimitiveList(reader, ByteTag.class, ByteArrayTag.class);
+ final byte[] array = new byte[tags.size()];
+ for (int i = 0; i < tags.size(); i++) {
+ array[i] = tags.get(i).value();
+ }
+ return new ByteArrayTag(array);
+ } else if (c == 'L') {
+ final ListTag tags = this.readPrimitiveList(reader, LongTag.class, LongArrayTag.class);
+ final ListTag<LongTag> tags = this.readPrimitiveList(reader, LongTag.class, LongArrayTag.class);
+ final long[] array = new long[tags.size()];
+ for (int i = 0; i < tags.size(); i++) {
+ array[i] = tags.get(i).value();
+ }
+ return new LongArrayTag(array);
+ } else if (c == 'I') {
+ final ListTag tags = this.readPrimitiveList(reader, IntTag.class, IntArrayTag.class);
+ final ListTag<IntTag> tags = this.readPrimitiveList(reader, IntTag.class, IntArrayTag.class);
+ final int[] array = new int[tags.size()];
+ for (int i = 0; i < tags.size(); i++) {
+ array[i] = tags.get(i).value();
@ -33,14 +33,14 @@ index 8bec86c..3525056 100644
+ return new IntArrayTag(array);
+ } else throw new SNbtDeserializeException("Invalid array type '" + c + "' found");
}
protected Tag readValue(final StringReader_v1_12 reader) throws SNbtDeserializeException {
diff --git a/MCStructs-text/src/test/java/net/lenni0451/mcstructs/text/serializer/TextComponentCodecTest.java b/MCStructs-text/src/test/java/net/lenni0451/mcstructs/text/serializer/TextComponentCodecTest.java
index 4fdfde0..dd48c1a 100644
index b252411..80d3a81 100644
--- a/MCStructs-text/src/test/java/net/lenni0451/mcstructs/text/serializer/TextComponentCodecTest.java
+++ b/MCStructs-text/src/test/java/net/lenni0451/mcstructs/text/serializer/TextComponentCodecTest.java
@@ -61,9 +61,9 @@ class TextComponentCodecTest {
@Test
void legacyItemDeserialization() throws SNbtSerializeException {
- CompoundTag legacyNbt = new CompoundTag()
@ -68,10 +68,10 @@ index 4fdfde0..dd48c1a 100644
.setStyle(new Style()
.setHoverEvent(new TextHoverEvent(HoverEventAction.SHOW_ENTITY, new StringComponent(SNbtSerializer.LATEST.serialize(legacyNbt))))
@@ -100,19 +100,31 @@ class TextComponentCodecTest {
@Test
void arrayWithTag() {
- ListTag tags = new ListTag()
- ListTag<Tag> tags = new ListTag<>()
- .add(new CompoundTag()
- .putString("translate", "test")
- .addByteArray("with", (byte) 1, (byte) 2, (byte) 3))
@ -97,14 +97,14 @@ index 4fdfde0..dd48c1a 100644
+ translateWithLongArray.put("with", new LongArrayTag(new long[]{1, 2, 3}));
+
+ CompoundTag translateWithList = new CompoundTag();
+ ListTag numberList = new ListTag();
+ ListTag<IntTag> numberList = new ListTag<>(IntTag.class);
+ numberList.add(new IntTag(1));
+ numberList.add(new IntTag(2));
+ numberList.add(new IntTag(3));
+ translateWithList.putString("translate", "test");
+ translateWithList.put("with", numberList);
+
+ ListTag tags = new ListTag();
+ ListTag<CompoundTag> tags = new ListTag<>(CompoundTag.class);
+ tags.add(translateWithByteArray);
+ tags.add(translateWithIntArray);
+ tags.add(translateWithLongArray);
@ -113,10 +113,10 @@ index 4fdfde0..dd48c1a 100644
.append(new TranslationComponent("test", 1, 2, 3))
.append(new TranslationComponent("test", 1L, 2L, 3L))
diff --git a/build.gradle b/build.gradle
index a8c4682..6929dc4 100644
index 62daf4c..382f00b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -48,17 +48,17 @@ subprojects {
@@ -49,17 +49,17 @@ subprojects {
publishing {
repositories {
maven {
@ -142,7 +142,7 @@ index a8c4682..6929dc4 100644
name = "ossrh"
def releasesUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
@@ -68,7 +68,7 @@ subprojects {
@@ -69,7 +69,7 @@ subprojects {
authentication {
basic(BasicAuthentication)
}
@ -151,14 +151,190 @@ index a8c4682..6929dc4 100644
}
publications {
maven(MavenPublication) {
diff --git a/patch.patch b/patch.patch
index 709f4c1..8bb9614 100644
--- a/patch.patch
+++ b/patch.patch
@@ -1,171 +0,0 @@
-diff --git a/MCStructs-snbt/src/main/java/net/lenni0451/mcstructs/snbt/impl/v1_12/SNbtDeserializer_v1_12.java b/MCStructs-snbt/src/main/java/net/lenni0451/mcstructs/snbt/impl/v1_12/SNbtDeserializer_v1_12.java
-index 8bec86c..3525056 100644
---- a/MCStructs-snbt/src/main/java/net/lenni0451/mcstructs/snbt/impl/v1_12/SNbtDeserializer_v1_12.java
-+++ b/MCStructs-snbt/src/main/java/net/lenni0451/mcstructs/snbt/impl/v1_12/SNbtDeserializer_v1_12.java
-@@ -95,10 +95,28 @@ public class SNbtDeserializer_v1_12 implements ISNbtDeserializer<CompoundTag> {
- reader.read();
- reader.skipWhitespaces();
- if (!reader.canRead()) throw this.makeException(reader, "Expected value");
-- else if (c == 'B') return new ByteArrayTag(this.readPrimitiveList(reader, ByteTag.class, ByteArrayTag.class));
-- else if (c == 'L') return new LongArrayTag(this.readPrimitiveList(reader, LongTag.class, LongArrayTag.class));
-- else if (c == 'I') return new IntArrayTag(this.readPrimitiveList(reader, IntTag.class, IntArrayTag.class));
-- else throw new SNbtDeserializeException("Invalid array type '" + c + "' found");
-+ else if (c == 'B') {
-+ final ListTag tags = this.readPrimitiveList(reader, ByteTag.class, ByteArrayTag.class);
-+ final byte[] array = new byte[tags.size()];
-+ for (int i = 0; i < tags.size(); i++) {
-+ array[i] = tags.get(i).value();
-+ }
-+ return new ByteArrayTag(array);
-+ } else if (c == 'L') {
-+ final ListTag tags = this.readPrimitiveList(reader, LongTag.class, LongArrayTag.class);
-+ final long[] array = new long[tags.size()];
-+ for (int i = 0; i < tags.size(); i++) {
-+ array[i] = tags.get(i).value();
-+ }
-+ return new LongArrayTag(array);
-+ } else if (c == 'I') {
-+ final ListTag tags = this.readPrimitiveList(reader, IntTag.class, IntArrayTag.class);
-+ final int[] array = new int[tags.size()];
-+ for (int i = 0; i < tags.size(); i++) {
-+ array[i] = tags.get(i).value();
-+ }
-+ return new IntArrayTag(array);
-+ } else throw new SNbtDeserializeException("Invalid array type '" + c + "' found");
- }
-
- protected Tag readValue(final StringReader_v1_12 reader) throws SNbtDeserializeException {
-diff --git a/MCStructs-text/src/test/java/net/lenni0451/mcstructs/text/serializer/TextComponentCodecTest.java b/MCStructs-text/src/test/java/net/lenni0451/mcstructs/text/serializer/TextComponentCodecTest.java
-index 4fdfde0..dd48c1a 100644
---- a/MCStructs-text/src/test/java/net/lenni0451/mcstructs/text/serializer/TextComponentCodecTest.java
-+++ b/MCStructs-text/src/test/java/net/lenni0451/mcstructs/text/serializer/TextComponentCodecTest.java
-@@ -61,9 +61,9 @@ class TextComponentCodecTest {
-
- @Test
- void legacyItemDeserialization() throws SNbtSerializeException {
-- CompoundTag legacyNbt = new CompoundTag()
-- .put("id", "stone")
-- .putByte("Count", (byte) 5);
-+ CompoundTag legacyNbt = new CompoundTag();
-+ legacyNbt.put("id", new StringTag("stone"));
-+ legacyNbt.putByte("Count", (byte) 5);
- ATextComponent legacyComponent = new StringComponent("test")
- .setStyle(new Style()
- .setHoverEvent(new TextHoverEvent(HoverEventAction.SHOW_ITEM, new StringComponent(SNbtSerializer.LATEST.serialize(legacyNbt))))
-@@ -80,10 +80,10 @@ class TextComponentCodecTest {
- @Test
- void legacyEntityDeserialization() throws SNbtSerializeException {
- UUID randomUUID = UUID.randomUUID();
-- CompoundTag legacyNbt = new CompoundTag()
-- .put("name", "{\"text\":\"test\"}")
-- .put("type", "cow")
-- .put("id", randomUUID.toString());
-+ CompoundTag legacyNbt = new CompoundTag();
-+ legacyNbt.put("name", new StringTag("{\"text\":\"test\"}"));
-+ legacyNbt.put("type", new StringTag("cow"));
-+ legacyNbt.put("id", new StringTag(randomUUID.toString()));
- ATextComponent legacyComponent = new StringComponent("test")
- .setStyle(new Style()
- .setHoverEvent(new TextHoverEvent(HoverEventAction.SHOW_ENTITY, new StringComponent(SNbtSerializer.LATEST.serialize(legacyNbt))))
-@@ -100,19 +100,31 @@ class TextComponentCodecTest {
-
- @Test
- void arrayWithTag() {
-- ListTag tags = new ListTag()
-- .add(new CompoundTag()
-- .putString("translate", "test")
-- .addByteArray("with", (byte) 1, (byte) 2, (byte) 3))
-- .add(new CompoundTag()
-- .putString("translate", "test")
-- .addIntArray("with", 1, 2, 3))
-- .add(new CompoundTag()
-- .putString("translate", "test")
-- .addLongArray("with", 1, 2, 3))
-- .add(new CompoundTag()
-- .putString("translate", "test")
-- .addList("with", 1, 2, 3));
-+ CompoundTag translateWithByteArray = new CompoundTag();
-+ translateWithByteArray.putString("translate", "test");
-+ translateWithByteArray.put("with", new ByteArrayTag(new byte[]{1, 2, 3}));
-+
-+ CompoundTag translateWithIntArray = new CompoundTag();
-+ translateWithIntArray.putString("translate", "test");
-+ translateWithIntArray.put("with", new IntArrayTag(new int[]{1, 2, 3}));
-+
-+ CompoundTag translateWithLongArray = new CompoundTag();
-+ translateWithLongArray.putString("translate", "test");
-+ translateWithLongArray.put("with", new LongArrayTag(new long[]{1, 2, 3}));
-+
-+ CompoundTag translateWithList = new CompoundTag();
-+ ListTag numberList = new ListTag();
-+ numberList.add(new IntTag(1));
-+ numberList.add(new IntTag(2));
-+ numberList.add(new IntTag(3));
-+ translateWithList.putString("translate", "test");
-+ translateWithList.put("with", numberList);
-+
-+ ListTag tags = new ListTag();
-+ tags.add(translateWithByteArray);
-+ tags.add(translateWithIntArray);
-+ tags.add(translateWithLongArray);
-+ tags.add(translateWithList);
- ATextComponent component = new TranslationComponent("test", (byte) 1, (byte) 2, (byte) 3)
- .append(new TranslationComponent("test", 1, 2, 3))
- .append(new TranslationComponent("test", 1L, 2L, 3L))
-diff --git a/build.gradle b/build.gradle
-index a8c4682..6929dc4 100644
---- a/build.gradle
-+++ b/build.gradle
-@@ -48,17 +48,17 @@ subprojects {
- publishing {
- repositories {
- maven {
-- name = "reposilite"
-- def releasesUrl = "https://maven.lenni0451.net/releases"
-- def snapshotsUrl = "https://maven.lenni0451.net/snapshots"
-- url = project.maven_version.endsWith("SNAPSHOT") ? snapshotsUrl : releasesUrl
--
-- credentials(PasswordCredentials)
-+ name = "Via"
-+ url = uri("https://repo.viaversion.com/")
-+ credentials {
-+ username = System.getenv("via_username")
-+ password = System.getenv("via_password")
-+ }
- authentication {
-- basic(BasicAuthentication)
-+ create(BasicAuthentication)
- }
- }
-- maven {
-+ /*maven {
- name = "ossrh"
- def releasesUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
- def snapshotsUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
-@@ -68,7 +68,7 @@ subprojects {
- authentication {
- basic(BasicAuthentication)
- }
-- }
-+ }*/
- }
- publications {
- maven(MavenPublication) {
-diff --git a/settings.gradle b/settings.gradle
-index 678ff0b..dd6c9cc 100644
---- a/settings.gradle
-+++ b/settings.gradle
-@@ -7,13 +7,6 @@ pluginManagement {
-
- rootProject.name = "MCStructs"
-
--include(":MCStructs-all")
--include(":MCStructs-data")
--include(":MCStructs-enchantments")
- include(":MCStructs-core")
--include(":MCStructs-inventory")
--include(":MCStructs-items")
--include(":MCStructs-nbt")
--include(":MCStructs-recipes")
- include(":MCStructs-snbt")
- include(":MCStructs-text")
diff --git a/settings.gradle b/settings.gradle
index 678ff0b..dd6c9cc 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -7,13 +7,6 @@ pluginManagement {
rootProject.name = "MCStructs"
-include(":MCStructs-all")
-include(":MCStructs-data")
-include(":MCStructs-enchantments")