mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-21 12:07:38 +01:00
Finish up things
This commit is contained in:
parent
96293e6e66
commit
5334f77d49
@ -17,15 +17,13 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.chat;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.libs.gson.JsonParseException;
|
||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
|
||||
public class TranslatableRewriter1_16 extends TranslatableRewriter<ClientboundPackets1_16> {
|
||||
|
||||
@ -76,33 +74,8 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter<ClientboundPa
|
||||
}
|
||||
|
||||
// show_text as chat component json, show_entity and show_item serialized as snbt
|
||||
// Let adventure handle all of that
|
||||
try {
|
||||
Component component = ChatRewriter.HOVER_GSON_SERIALIZER.deserializeFromTree(object);
|
||||
JsonObject convertedObject;
|
||||
try {
|
||||
convertedObject = (JsonObject) ChatRewriter.HOVER_GSON_SERIALIZER.serializeToTree(component);
|
||||
} catch (JsonParseException e) {
|
||||
JsonObject contents = hoverEvent.getAsJsonObject("contents");
|
||||
if (contents.remove("tag") == null) {
|
||||
throw e; // Just rethrow if this is not an item with a tag provided
|
||||
}
|
||||
|
||||
// Most likely an invalid nbt tag - try again after its removal
|
||||
component = ChatRewriter.HOVER_GSON_SERIALIZER.deserializeFromTree(object);
|
||||
convertedObject = (JsonObject) ChatRewriter.HOVER_GSON_SERIALIZER.serializeToTree(component);
|
||||
}
|
||||
|
||||
// Remove new format
|
||||
JsonObject processedHoverEvent = convertedObject.getAsJsonObject("hoverEvent");
|
||||
processedHoverEvent.remove("contents");
|
||||
object.add("hoverEvent", processedHoverEvent);
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||
ViaBackwards.getPlatform().getLogger().severe("Error converting hover event component: " + object);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
JsonObject convertedObject = (JsonObject) ComponentUtil.convertJson(object, ComponentUtil.SerializerVersion.V1_16, ComponentUtil.SerializerVersion.V1_15);
|
||||
object.add("hoverEvent", convertedObject.getAsJsonObject("hoverEvent"));
|
||||
}
|
||||
|
||||
private String getClosestChatColor(int rgb) {
|
||||
|
@ -345,7 +345,7 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol<ClientboundP
|
||||
}
|
||||
|
||||
final JsonElement unsignedContent = wrapper.read(Type.OPTIONAL_COMPONENT);
|
||||
final JsonElement content = unsignedContent != null ? unsignedContent : ComponentUtil.plainTextToJson(plainContent);
|
||||
final JsonElement content = unsignedContent != null ? unsignedContent : ComponentUtil.plainToJson(plainContent);
|
||||
translatableRewriter.processText(content);
|
||||
final int filterMaskType = wrapper.read(Type.VAR_INT);
|
||||
if (filterMaskType == 2) {
|
||||
|
@ -156,7 +156,7 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol<ClientboundPac
|
||||
}
|
||||
if (message == null) {
|
||||
// If no decorated or unsigned message is given, use the plain one
|
||||
message = ComponentUtil.plainTextToJson(plainMessage);
|
||||
message = ComponentUtil.plainToJson(plainMessage);
|
||||
}
|
||||
|
||||
final int filterMaskType = wrapper.read(Type.VAR_INT);
|
||||
|
@ -47,10 +47,10 @@ import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.Protocol1_20_3
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.util.ComponentConverter;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import java.util.BitSet;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -368,13 +368,13 @@ public final class Protocol1_20_2To1_20_3 extends BackwardsProtocol<ClientboundP
|
||||
private void convertComponent(final PacketWrapper wrapper) throws Exception {
|
||||
final Tag tag = wrapper.read(Type.TAG);
|
||||
translatableRewriter.processTag(tag);
|
||||
wrapper.write(Type.COMPONENT, ComponentConverter.tagComponentToJson(tag));
|
||||
wrapper.write(Type.COMPONENT, ComponentUtil.tagToJson(tag));
|
||||
}
|
||||
|
||||
private void convertOptionalComponent(final PacketWrapper wrapper) throws Exception {
|
||||
final Tag tag = wrapper.read(Type.OPTIONAL_TAG);
|
||||
translatableRewriter.processTag(tag);
|
||||
wrapper.write(Type.OPTIONAL_COMPONENT, ComponentConverter.tagComponentToJson(tag));
|
||||
wrapper.write(Type.OPTIONAL_COMPONENT, ComponentUtil.tagToJson(tag));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,7 +33,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_20_2;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundConfigurationPackets1_20_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.util.ComponentConverter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
|
||||
public final class EntityPacketRewriter1_20_3 extends EntityRewriter<ClientboundPackets1_20_3, Protocol1_20_2To1_20_3> {
|
||||
|
||||
@ -99,10 +99,10 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
|
||||
filter().handler((event, meta) -> {
|
||||
final MetaType type = meta.metaType();
|
||||
if (type == Types1_20_3.META_TYPES.componentType) {
|
||||
meta.setTypeAndValue(Types1_20_2.META_TYPES.componentType, ComponentConverter.tagComponentToJson(meta.value()));
|
||||
meta.setTypeAndValue(Types1_20_2.META_TYPES.componentType, ComponentUtil.tagToJson(meta.value()));
|
||||
return;
|
||||
} else if (type == Types1_20_3.META_TYPES.optionalComponentType) {
|
||||
meta.setTypeAndValue(Types1_20_2.META_TYPES.optionalComponentType, ComponentConverter.tagComponentToJson(meta.value()));
|
||||
meta.setTypeAndValue(Types1_20_2.META_TYPES.optionalComponentType, ComponentUtil.tagToJson(meta.value()));
|
||||
return;
|
||||
} else if (type == Types1_20_3.META_TYPES.particleType) {
|
||||
final Particle particle = (Particle) meta.getValue();
|
||||
|
Loading…
Reference in New Issue
Block a user