New replacements

This commit is contained in:
Nassim Jahnke 2024-11-04 20:31:44 +01:00
parent 6f7392262f
commit 9b14d8d2fe
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 9 additions and 3 deletions

View File

@ -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)

View File

@ -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 {