From 5855cc41939f225c74262b1eae7cf45f61d405ea Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 21 Apr 2024 11:34:15 +0200 Subject: [PATCH] Update hacks --- .github/workflows/main.yml | 2 +- .github/workflows/publish.yml | 2 +- MCStructs | 2 +- mcstructs.py | 4 + patch.patch | 153 +++++++++++++++++++++++++++++++++- 5 files changed, 159 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 459aada..b545fdb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,7 +47,7 @@ jobs: env: via_username: ${{ secrets.VIA_USERNAME }} via_password: ${{ secrets.VIA_PASSWORD }} - run: ./gradlew publish + run: ./gradlew publish -x checkstyleMain -x checkstyleTest -x test working-directory: MCStructs - name: Commit changes diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0ab84da..8b906fe 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -34,7 +34,7 @@ jobs: env: via_username: ${{ secrets.VIA_USERNAME }} via_password: ${{ secrets.VIA_PASSWORD }} - run: ./gradlew publish + run: ./gradlew publish -x checkstyleMain -x checkstyleTest -x test working-directory: MCStructs - name: Commit changes diff --git a/MCStructs b/MCStructs index 7a41b95..aa0bc8d 160000 --- a/MCStructs +++ b/MCStructs @@ -1 +1 @@ -Subproject commit 7a41b9527fe6d913b02bdfcb94dd1d0bde04159a +Subproject commit aa0bc8d64cb7bfbdd3338959c5116d26051f95af diff --git a/mcstructs.py b/mcstructs.py index ae43806..31f5db3 100644 --- a/mcstructs.py +++ b/mcstructs.py @@ -41,7 +41,11 @@ extra_replacements = { '.getTag().name()': '.getClass()', 'tag.name()': 'tag.getClass()', 'list.getType().isNumber()': 'list.getElementType().isAssignableFrom(com.github.steveice10.opennbt.tag.builtin.NumberTag.class)', + 'values.get(i).asNumberTag().intValue()': '((NumberTag) values.get(i)).asInt()', 'this.styleSerializer.serialize(object.getStyle()).asCompoundTag()': '(CompoundTag) this.styleSerializer.serialize(object.getStyle())', + 'JsonNbtConverter.toNbt(json).asCompoundTag()': '((CompoundTag) JsonNbtConverter.toNbt(json))', + 'Tag.COMPOUND.equals(list.getType())': 'CompoundTag.class == list.getElementType()', + 'Tag.COMPOUND.equals(listTag.getType())': 'CompoundTag.class == listTag.getElementType()', 'compound.add(': 'compound.put(', '.numberValue()': '.getValue()', '(ACTION)': '("action")', diff --git a/patch.patch b/patch.patch index 393ca7b..3b5f2bb 100644 --- a/patch.patch +++ b/patch.patch @@ -35,8 +35,159 @@ index 851d33c..2a55603 100644 } protected Tag readValue(final StringReader_v1_12 reader) throws SNbtDeserializeException { +diff --git a/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/events/hover/impl/EntityHoverEvent.java b/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/events/hover/impl/EntityHoverEvent.java +index fd93efd..8125838 100644 +--- a/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/events/hover/impl/EntityHoverEvent.java ++++ b/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/events/hover/impl/EntityHoverEvent.java +@@ -117,10 +117,10 @@ public class EntityHoverEvent extends AHoverEvent { + @Override + public String toString() { + return ToString.of(this) +- .put("action", this.action) +- .put("entityType", this.entityType) +- .put("uuid", this.uuid) +- .put("name", this.name, Objects::nonNull) ++ .add("action", this.action) ++ .add("entityType", this.entityType) ++ .add("uuid", this.uuid) ++ .add("name", this.name, Objects::nonNull) + .toString(); + } + +diff --git a/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/events/hover/impl/ItemHoverEvent.java b/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/events/hover/impl/ItemHoverEvent.java +index 3fed9a3..7d9f356 100644 +--- a/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/events/hover/impl/ItemHoverEvent.java ++++ b/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/events/hover/impl/ItemHoverEvent.java +@@ -119,10 +119,10 @@ public class ItemHoverEvent extends AHoverEvent { + @Override + public String toString() { + return ToString.of(this) +- .put("action", this.action) +- .put("item", this.item) +- .put("count", this.count, count -> count != 1) +- .put("nbt", this.nbt, Objects::nonNull) ++ .add("action", this.action) ++ .add("item", this.item) ++ .add("count", this.count, count -> count != 1) ++ .add("nbt", this.nbt, Objects::nonNull) + .toString(); + } + +diff --git a/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/utils/JsonNbtConverter.java b/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/utils/JsonNbtConverter.java +index 4ca4cc8..618d52a 100644 +--- a/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/utils/JsonNbtConverter.java ++++ b/MCStructs-text/src/main/java/net/lenni0451/mcstructs/text/utils/JsonNbtConverter.java +@@ -22,23 +22,17 @@ public class JsonNbtConverter { + * @return The converted json element + */ + public static JsonElement toJson(final Tag tag) { +- switch (tag) { +- case END: ++ if (tag == null) { + return null; +- case BYTE: +- case SHORT: +- case INT: +- case LONG: +- case FLOAT: +- case DOUBLE: ++ } else if (tag instanceof NumberTag) { + return new JsonPrimitive(((NumberTag) tag).getValue()); +- case BYTE_ARRAY: ++ } else if (tag instanceof ByteArrayTag) { + JsonArray byteArray = new JsonArray(); + for (byte b : ((ByteArrayTag) tag).getValue()) byteArray.add(b); + return byteArray; +- case STRING: ++ } else if (tag instanceof StringTag) { + return new JsonPrimitive(((StringTag) tag).getValue()); +- case LIST: ++ } else if (tag instanceof ListTag) { + JsonArray list = new JsonArray(); + ListTag listTag = ((ListTag) tag); + for (Tag tagInList : listTag.getValue()) { +@@ -52,19 +46,19 @@ public class JsonNbtConverter { + list.add(toJson(tagInList)); + } + return list; +- case COMPOUND: ++ } else if (tag instanceof CompoundTag) { + JsonObject compound = new JsonObject(); +- for (Map.Entry entry : ((CompoundTag) tag).getValue().entrySet()) compound.put(entry.getKey(), toJson(entry.getValue())); ++ for (Map.Entry entry : ((CompoundTag) tag).getValue().entrySet()) compound.add(entry.getKey(), toJson(entry.getValue())); + return compound; +- case INT_ARRAY: ++ } else if (tag instanceof IntArrayTag) { + JsonArray intArray = new JsonArray(); + for (int i : ((IntArrayTag) tag).getValue()) intArray.add(i); + return intArray; +- case LONG_ARRAY: ++ } else if (tag instanceof LongArrayTag) { + JsonArray longArray = new JsonArray(); + for (long l : ((LongArrayTag) tag).getValue()) longArray.add(l); + return longArray; +- default: ++ } else { + throw new IllegalArgumentException("Unknown Nbt type: " + tag); + } + } +@@ -85,31 +79,37 @@ public class JsonNbtConverter { + JsonArray array = element.getAsJsonArray(); + List nbtTags = new ArrayList<>(); + Tag listType = null; ++ boolean mixedList = false; + for (JsonElement arrayElement : array) { + Tag tag = toNbt(arrayElement); + nbtTags.add(tag); + listType = getListType(listType, tag); ++ if (listType == null) mixedList = true; + } + if (listType == null) { + return new ListTag<>(); +- } else if (listType == Tag.END) { //Mixed list ++ } else if (mixedList) { //Mixed list + ListTag list = new ListTag<>(); + for (Tag tag : nbtTags) { + if (tag instanceof CompoundTag) list.add(((CompoundTag) tag)); +- else list.add(new CompoundTag().put("", tag)); ++ else { ++ final CompoundTag entries = new CompoundTag(); ++ entries.put("", tag); ++ list.add(entries); ++ } + } + return list; +- } else if (listType == Tag.BYTE) { ++ } else if (listType instanceof ByteTag) { + byte[] bytes = new byte[nbtTags.size()]; +- for (int i = 0; i < nbtTags.size(); i++) bytes[i] = nbtTags.get(i).asByteTag().byteValue(); ++ for (int i = 0; i < nbtTags.size(); i++) bytes[i] = ((NumberTag) nbtTags.get(i)).asByte(); + return new ByteArrayTag(bytes); +- } else if (listType == Tag.INT) { ++ } else if (listType instanceof IntTag) { + int[] ints = new int[nbtTags.size()]; +- for (int i = 0; i < nbtTags.size(); i++) ints[i] = nbtTags.get(i).asIntTag().intValue(); ++ for (int i = 0; i < nbtTags.size(); i++) ints[i] = ((NumberTag) nbtTags.get(i)).asInt(); + return new IntArrayTag(ints); +- } else if (listType == Tag.LONG) { ++ } else if (listType instanceof LongTag) { + long[] longs = new long[nbtTags.size()]; +- for (int i = 0; i < nbtTags.size(); i++) longs[i] = nbtTags.get(i).asIntTag().intValue(); ++ for (int i = 0; i < nbtTags.size(); i++) longs[i] = ((NumberTag) nbtTags.get(i)).asLong(); + return new LongArrayTag(longs); + } else { + return new ListTag<>(nbtTags); +@@ -143,7 +143,7 @@ public class JsonNbtConverter { + + private static Tag getListType(final Tag current, final Tag tag) { + if (current == null) return tag; +- if (current != tag) return Tag.END; //Placeholder for mixed lists ++ if (current != tag) return null; //Placeholder for mixed lists + return current; + } + 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 b252411..80d3a81 100644 +index 503878a..00572d9 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 {