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

Start working on mcstructs usage (missing TranslatableRewriter1_16)

Dieser Commit ist enthalten in:
Nassim Jahnke 2023-12-27 00:24:56 +01:00
Ursprung 65faeb8574
Commit 96293e6e66
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
12 geänderte Dateien mit 38 neuen und 104 gelöschten Zeilen

Datei anzeigen

@ -17,7 +17,7 @@
*/
package com.viaversion.viabackwards.api.data;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import org.checkerframework.checker.nullness.qual.Nullable;
public class MappedItem {
@ -32,7 +32,7 @@ public class MappedItem {
public MappedItem(final int id, final String name, @Nullable final Integer customModelData) {
this.id = id;
this.jsonName = ChatRewriter.legacyTextToJsonString("§f" + name, true);
this.jsonName = ComponentUtil.legacyToJsonString("§f" + name, true);
this.customModelData = customModelData;
}

Datei anzeigen

@ -18,11 +18,10 @@
package com.viaversion.viabackwards.api.entities.storage;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -87,7 +86,7 @@ public class EntityData {
}
if (componentType == ComponentType.JSON) {
return ChatRewriter.legacyTextToJson(name);
return ComponentUtil.legacyToJson(name);
} else if (componentType == ComponentType.TAG) {
return new StringTag(name);
}

Datei anzeigen

@ -24,7 +24,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -103,7 +103,7 @@ public class EnchantmentRewriter {
int level = ((NumberTag) enchantmentEntry.get("lvl")).asInt();
String loreValue = remappedName + " " + getRomanNumber(level);
if (jsonFormat) {
loreValue = ChatRewriter.legacyTextToJsonString(loreValue);
loreValue = ComponentUtil.legacyToJsonString(loreValue);
}
loreToAdd.add(new StringTag(loreValue));

Datei anzeigen

@ -41,7 +41,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -278,7 +278,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
CompoundTag tag = new CompoundTag();
tag.put("display", new CompoundTag());
text = "§r" + text;
((CompoundTag) tag.get("display")).put("Name", new StringTag(jsonNameFormat ? ChatRewriter.legacyTextToJsonString(text) : text));
((CompoundTag) tag.get("display")).put("Name", new StringTag(jsonNameFormat ? ComponentUtil.legacyToJsonString(text) : text));
return tag;
}

Datei anzeigen

@ -25,10 +25,9 @@ import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
import com.viaversion.viaversion.util.ComponentUtil;
public class PlayerPackets1_11 {
private static final ValueTransformer<Short, Float> TO_NEW_FLOAT = new ValueTransformer<Short, Float>(Type.FLOAT) {
@ -53,8 +52,8 @@ public class PlayerPackets1_11 {
wrapper.clearPacket();
wrapper.setPacketType(ClientboundPackets1_9_3.CHAT_MESSAGE);
// https://bugs.mojang.com/browse/MC-119145to
String legacy = LegacyComponentSerializer.legacySection().serialize(GsonComponentSerializer.gson().deserialize(message.toString()));
// https://bugs.mojang.com/browse/MC-119145
String legacy = ComponentUtil.jsonToLegacy(message);
message = new JsonObject();
message.getAsJsonObject().addProperty("text", legacy);

Datei anzeigen

@ -39,15 +39,13 @@ import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.gson.JsonParser;
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import org.checkerframework.checker.nullness.qual.Nullable;
public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_12_1, ServerboundPackets1_13, ServerboundPackets1_12_1> {
@ -167,14 +165,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
}
translatableToLegacyRewriter.processText(value);
try {
Component component = ChatRewriter.HOVER_GSON_SERIALIZER.deserializeFromTree(value);
return LegacyComponentSerializer.legacySection().serialize(component);
} catch (Exception e) {
ViaBackwards.getPlatform().getLogger().warning("Error converting json text to legacy: " + value);
e.printStackTrace();
}
return "";
return ComponentUtil.jsonToLegacy(value);
}
}

Datei anzeigen

@ -50,11 +50,11 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.BlockIdData;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Key;
import java.util.ArrayList;
import java.util.HashMap;
@ -755,7 +755,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
StringTag name = displayTag.get("Name");
if (name != null) {
StringTag via = displayTag.remove(extraNbtTag + "|Name");
name.setValue(via != null ? via.getValue() : ChatRewriter.legacyTextToJsonString(name.getValue()));
name.setValue(via != null ? via.getValue() : ComponentUtil.legacyToJsonString(name.getValue()));
}
}

Datei anzeigen

@ -25,7 +25,12 @@ import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLi
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
import com.viaversion.viaversion.api.minecraft.chunks.*;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLight;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLightImpl;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.api.minecraft.item.Item;
@ -42,15 +47,14 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.RecipeRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Key;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@ -143,7 +147,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
if (title.isJsonObject() && (object = title.getAsJsonObject()).has("translate")) {
// Don't rewrite other 9x3 translatable containers
if (type != 2 || object.getAsJsonPrimitive("translate").getAsString().equals("container.barrel")) {
title = ChatRewriter.legacyTextToJson(containerTitle);
title = ComponentUtil.legacyToJson(containerTitle);
}
}
}
@ -479,7 +483,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
StringTag loreEntryTag = (StringTag) loreEntry;
String value = loreEntryTag.getValue();
if (value != null && !value.isEmpty()) {
loreEntryTag.setValue(ChatRewriter.jsonToLegacyText(value));
loreEntryTag.setValue(ComponentUtil.jsonToLegacy(value));
}
}
}
@ -503,7 +507,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) {
StringTag loreEntryTag = (StringTag) loreEntry;
loreEntryTag.setValue(ChatRewriter.legacyTextToJsonString(loreEntryTag.getValue()));
loreEntryTag.setValue(ComponentUtil.legacyToJsonString(loreEntryTag.getValue()));
}
}
}

Datei anzeigen

@ -38,12 +38,12 @@ import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_13, ServerboundPackets1_13, ServerboundPackets1_13> {
@ -115,7 +115,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
// https://bugs.mojang.com/browse/MC-124543
JsonObject legacyComponent = new JsonObject();
legacyComponent.addProperty("text", ChatRewriter.jsonToLegacyText(title.toString()));
legacyComponent.addProperty("text", ComponentUtil.jsonToLegacy(title));
wrapper.set(Type.COMPONENT, 0, legacyComponent);
}
});

Datei anzeigen

@ -25,8 +25,6 @@ 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.libs.kyori.adventure.text.Component;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
public class TranslatableRewriter1_16 extends TranslatableRewriter<ClientboundPackets1_16> {

Datei anzeigen

@ -44,8 +44,6 @@ import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.ByteArrayType;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1;
@ -57,8 +55,8 @@ import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.util.CipherUtil;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Pair;
import java.util.BitSet;
import java.util.List;
@ -347,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 : GsonComponentSerializer.gson().serializeToTree(Component.text(plainContent));
final JsonElement content = unsignedContent != null ? unsignedContent : ComponentUtil.plainTextToJson(plainContent);
translatableRewriter.processText(content);
final int filterMaskType = wrapper.read(Type.VAR_INT);
if (filterMaskType == 2) {

Datei anzeigen

@ -17,7 +17,6 @@
*/
package com.viaversion.viabackwards.protocol.protocol1_19to1_19_1;
import com.google.common.base.Preconditions;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
@ -41,28 +40,25 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
import com.viaversion.viaversion.libs.kyori.adventure.text.TranslatableComponent;
import com.viaversion.viaversion.libs.kyori.adventure.text.format.NamedTextColor;
import com.viaversion.viaversion.libs.kyori.adventure.text.format.Style;
import com.viaversion.viaversion.libs.kyori.adventure.text.format.TextDecoration;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.Protocol1_19_1To1_19;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ServerboundPackets1_19_1;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.EntityPackets;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.util.CipherUtil;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Pair;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class Protocol1_19To1_19_1 extends BackwardsProtocol<ClientboundPackets1_19_1, ClientboundPackets1_19, ServerboundPackets1_19_1, ServerboundPackets1_19> {
@ -160,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 = GsonComponentSerializer.gson().serializeToTree(Component.text(plainMessage));
message = ComponentUtil.plainTextToJson(plainMessage);
}
final int filterMaskType = wrapper.read(Type.VAR_INT);
@ -408,56 +404,6 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol<ClientboundPac
return null;
}
final String translationKey = (String) chatType.get("translation_key").getValue();
final TranslatableComponent.Builder componentBuilder = Component.translatable().key(translationKey);
// Add the style
final CompoundTag style = chatType.get("style");
if (style != null) {
final Style.Builder styleBuilder = Style.style();
final StringTag color = style.get("color");
if (color != null) {
final NamedTextColor textColor = NamedTextColor.NAMES.value(color.getValue());
if (textColor != null) {
styleBuilder.color(NamedTextColor.NAMES.value(color.getValue()));
}
}
for (final String key : TextDecoration.NAMES.keys()) {
if (style.contains(key)) {
styleBuilder.decoration(TextDecoration.NAMES.value(key), style.<ByteTag>get(key).asByte() == 1);
}
}
componentBuilder.style(styleBuilder.build());
}
// Add the replacements
final ListTag parameters = chatType.get("parameters");
if (parameters != null) {
final List<Component> arguments = new ArrayList<>();
for (final Tag element : parameters) {
JsonElement argument = null;
switch ((String) element.getValue()) {
case "sender":
argument = senderName;
break;
case "content":
argument = message;
break;
case "target":
Preconditions.checkNotNull(targetName, "Target name is null");
argument = targetName;
break;
default:
ViaBackwards.getPlatform().getLogger().warning("Unknown parameter for chat decoration: " + element.getValue());
}
if (argument != null) {
arguments.add(GsonComponentSerializer.gson().deserializeFromTree(argument));
}
}
componentBuilder.args(arguments);
}
return GsonComponentSerializer.gson().serializeToTree(componentBuilder.build());
return Protocol1_19_1To1_19.translatabaleComponentFromTag(chatType, senderName, targetName, message);
}
}