From 9b14d8d2fef97dc4235be528d46db3b7cfde423c Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 4 Nov 2024 20:31:44 +0100 Subject: [PATCH] New replacements --- mcstructs.py | 8 +++++++- patch.patch | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mcstructs.py b/mcstructs.py index 4f885f2..e75f0de 100644 --- a/mcstructs.py +++ b/mcstructs.py @@ -40,9 +40,11 @@ extra_replacements = { '.addCompound(': '.put(', '.addAll(': '.putAll(', '.getTag().name()': '.getClass()', + '.intValue()': '.asInt()', 'tag.name()': 'tag.getClass()', + 'super.serialize(object).asCompoundTag()': '((CompoundTag) super.serialize(object))', 'list.getType().isNumber()': 'list.getElementType().isAssignableFrom(com.viaversion.nbt.tag.NumberTag.class)', - 'values.get(i).asNumberTag().intValue()': '((NumberTag) values.get(i)).asInt()', + 'values.get(i).asNumberTag().asInt()': '((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()', @@ -157,9 +159,13 @@ def handle_file(path): changed_content = changed_content.replace('.add("', '.put("') # tag.isXTag() -> (tag instanceof XTag) + # Special case ArrayTag + changed_content = re.sub(r'(\w+)\.isArrayTag\(\)', r'(\1 instanceof NumberArrayTag)', changed_content) changed_content = re.sub(r'(\w+)\.is(\w+Tag)\(\)', r'(\1 instanceof \2)', changed_content) # asXTag() -> cast + # Deal with the base ArrayTag separately + changed_content = re.sub(r'(\w+)\.asArrayTag\(\)', r'((NumberArrayTag) \1)', changed_content) changed_content = re.sub(r'(\w+)\.as(\w+Tag)\(\)', r'((\2) \1)', changed_content) changed_content = re.sub(r'tags.get\(i\)\.as(\w+Tag)\(\)', r'((\1) tags.get(i))', changed_content) diff --git a/patch.patch b/patch.patch index 26ed4ac..5a291ef 100644 --- a/patch.patch +++ b/patch.patch @@ -278,13 +278,13 @@ index 8bd6503..e512af7 100644 - } 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] = nbtTags.get(i).asIntTag().asInt(); + 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] = nbtTags.get(i).asIntTag().asInt(); + for (int i = 0; i < nbtTags.size(); i++) longs[i] = ((NumberTag) nbtTags.get(i)).asLong(); return new LongArrayTag(longs); } else {