3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00

Serialize to 1.20.3 components in conversion

Aside from hover events, only reading of components changed and we need the 1.20.3 hover input. Hover events are already handled by us.
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-04-23 13:39:15 +02:00
Ursprung 34bc5b9d36
Commit 71ab15b331
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
2 geänderte Dateien mit 6 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -99,6 +99,7 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Either; import com.viaversion.viaversion.util.Either;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.SerializerVersion;
import com.viaversion.viaversion.util.UUIDUtil; import com.viaversion.viaversion.util.UUIDUtil;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@ -1111,7 +1112,8 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
} }
private Tag jsonToTag(final UserConnection connection, final StringTag stringTag) { private Tag jsonToTag(final UserConnection connection, final StringTag stringTag) {
final Tag tag = ComponentUtil.jsonStringToTag(stringTag.getValue()); // Use the same version for deserializing and serializing, as the only write changes are in hovers, which we handle ourselves
final Tag tag = ComponentUtil.jsonStringToTag(stringTag.getValue(), SerializerVersion.V1_20_3, SerializerVersion.V1_20_3);
protocol.getComponentRewriter().processTag(connection, tag); protocol.getComponentRewriter().processTag(connection, tag);
return tag; return tag;
} }

Datei anzeigen

@ -102,14 +102,14 @@ public final class ComponentUtil {
} }
} }
public static @Nullable Tag jsonStringToTag(@Nullable final String json) { public static @Nullable Tag jsonStringToTag(@Nullable final String json, final SerializerVersion from, final SerializerVersion to) {
if (json == null) { if (json == null) {
return null; return null;
} }
try { try {
final ATextComponent component = TextComponentSerializer.V1_20_3.deserialize(json); final ATextComponent component = from.jsonSerializer.deserialize(json);
return SerializerVersion.V1_20_5.toTag(component); return to.toTag(component);
} catch (final Exception e) { } catch (final Exception e) {
Via.getPlatform().getLogger().log(Level.SEVERE, "Error converting component: " + json, e); Via.getPlatform().getLogger().log(Level.SEVERE, "Error converting component: " + json, e);
return new StringTag("<error>"); return new StringTag("<error>");