Use correct deserialization method in SerializerVersion#toComponent (#3795)

MCStructs has multiple methods for parsing jsons depending on the version, we should use them correctly in our wrapper to support all possible cases of components.
This commit is contained in:
EnZaXD 2024-04-19 17:05:07 +02:00 committed by GitHub
parent 128e191132
commit fb434a79bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -93,11 +93,11 @@ public final class ComponentUtil {
}
public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) {
return element != null ? convert(from, to, from.jsonSerializer.deserialize(element)) : null;
return element != null ? convert(from, to, from.toComponent(element)) : null;
}
public static @Nullable JsonElement convertJson(@Nullable final String json, final SerializerVersion from, final SerializerVersion to) {
return json != null ? convert(from, to, from.jsonSerializer.deserializeReader(json)) : null;
return json != null ? convert(from, to, from.toComponent(json)) : null;
}
private static JsonElement convert(final SerializerVersion from, final SerializerVersion to, final ATextComponent component) {

View File

@ -77,7 +77,13 @@ public enum SerializerVersion {
}
public ATextComponent toComponent(final String json) {
return jsonSerializer.deserializeReader(json);
if (ordinal() >= SerializerVersion.V1_20_3.ordinal()) {
return jsonSerializer.deserializeParser(json);
} else if (ordinal() >= SerializerVersion.V1_9.ordinal()) {
return jsonSerializer.deserializeReader(json);
} else {
return jsonSerializer.deserialize(json);
}
}
public ATextComponent toComponent(final Tag tag) {