From 96293e6e66813e2c1e00214499093598bbf8875b Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 27 Dec 2023 00:24:56 +0100 Subject: [PATCH 1/3] Start working on mcstructs usage (missing TranslatableRewriter1_16) --- .../viabackwards/api/data/MappedItem.java | 4 +- .../api/entities/storage/EntityData.java | 5 +- .../api/rewriters/EnchantmentRewriter.java | 4 +- .../rewriters/LegacyBlockItemRewriter.java | 4 +- .../packets/PlayerPackets1_11.java | 7 +- .../Protocol1_12_2To1_13.java | 14 +--- .../packets/BlockItemPackets1_13.java | 4 +- .../packets/BlockItemPackets1_14.java | 16 +++-- .../Protocol1_13To1_13_1.java | 4 +- .../chat/TranslatableRewriter1_16.java | 2 - .../Protocol1_19_1To1_19_3.java | 6 +- .../Protocol1_19To1_19_1.java | 72 +++---------------- 12 files changed, 38 insertions(+), 104 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java b/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java index 0460f341..04d0176d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java @@ -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; } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java index 58296637..1d2666b7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java @@ -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); } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java index c11087a5..3f57fd70 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java @@ -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)); diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java index a995f8b3..5919280c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java @@ -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 TO_NEW_FLOAT = new ValueTransformer(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); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java index e3fff6f7..7ac0ce0b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java @@ -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 { @@ -167,14 +165,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { @@ -115,7 +115,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java index 869e597a..a843f0ce 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java @@ -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 { @@ -160,7 +156,7 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocolget(key).asByte() == 1); - } - } - componentBuilder.style(styleBuilder.build()); - } - - // Add the replacements - final ListTag parameters = chatType.get("parameters"); - if (parameters != null) { - final List 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); } } From 5334f77d49e68853ab80c3497f0f4678f673010f Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 27 Dec 2023 17:30:47 +0100 Subject: [PATCH 2/3] Finish up things --- .../chat/TranslatableRewriter1_16.java | 33 ++----------------- .../Protocol1_19_1To1_19_3.java | 2 +- .../Protocol1_19To1_19_1.java | 2 +- .../Protocol1_20_2To1_20_3.java | 6 ++-- .../rewriter/EntityPacketRewriter1_20_3.java | 6 ++-- 5 files changed, 11 insertions(+), 38 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java index 76b60395..f37b59f0 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java @@ -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 { @@ -76,33 +74,8 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter { @@ -99,10 +99,10 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter { 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(); From 83fa0c613f6194464c6212f7872c4725c4981276 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 27 Dec 2023 17:51:16 +0100 Subject: [PATCH 3/3] Update copyright profile --- .idea/copyright/viabackwards_gpl.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/copyright/viabackwards_gpl.xml b/.idea/copyright/viabackwards_gpl.xml index bf99558e..8ac66561 100644 --- a/.idea/copyright/viabackwards_gpl.xml +++ b/.idea/copyright/viabackwards_gpl.xml @@ -1,6 +1,6 @@ - \ No newline at end of file