From 4599d150039b570ddaa093b8deea2c346dd393bc Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Wed, 8 Jun 2022 23:59:33 +0100 Subject: [PATCH] more work --- .../proxy/connection/registry/ChatData.java | 20 +++++++++++++++++-- .../connection/registry/ChatRegistry.java | 13 ++++++++++-- .../proxy/protocol/packet/JoinGame.java | 6 +++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ChatData.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ChatData.java index 5964735d0..20e1d972f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ChatData.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ChatData.java @@ -34,6 +34,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.network.ProtocolVersion; import java.util.List; +import net.kyori.adventure.nbt.BinaryTag; import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.ListBinaryTag; import net.kyori.adventure.text.format.NamedTextColor; @@ -49,8 +50,16 @@ public class ChatData { private final String identifier; private final int id; private final Decoration chatDecoration; - private Decoration narrationDecoration; + private final Decoration narrationDecoration; + /** + * Represents a ChatRegistry entry. + * + * @param id chat type id + * @param identifier chat type identifier + * @param chatDecoration chat decoration + * @param narrationDecoration narration decoration + */ public ChatData(int id, String identifier, Decoration chatDecoration, Decoration narrationDecoration) { this.id = id; this.identifier = identifier; @@ -105,7 +114,14 @@ public class ChatData { return id; } - + /** + * Encodes the chat data for the network. + * @param version The protocol version to encode this chat data for + * @return The encoded data structure + */ + public CompoundBinaryTag encodeAsCompoundTag(ProtocolVersion version) { + return null; + } public static class Decoration implements Translatable { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ChatRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ChatRegistry.java index f488bff94..fef1c7f82 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ChatRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/ChatRegistry.java @@ -52,7 +52,16 @@ public final class ChatRegistry { return builder.build(); } - public BinaryTag build() { - return null; + /** + * Serialises the Chat Registry for sending over the network. + * @param version the version to encode for + * @return The serialised tag list + */ + public ListBinaryTag encodeRegistry(ProtocolVersion version) { + final ListBinaryTag.Builder builder = ListBinaryTag.builder(); + for (ChatData data : registeredChatTypes.values()) { + builder.add(data.encodeAsCompoundTag(version)); + } + return builder.build(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java index 2085d97f2..10e10e875 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java @@ -393,7 +393,11 @@ public class JoinGame implements MinecraftPacket { registryContainer.put("minecraft:dimension_type", dimensionRegistryEntry.build()); registryContainer.put("minecraft:worldgen/biome", biomeRegistry); if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { - registryContainer.put("minecraft:chat_type", chatTypeRegistry.build()); + final ListBinaryTag encodedChatRegistry = chatTypeRegistry.encodeRegistry(version); + CompoundBinaryTag.Builder chatRegistryEntry = CompoundBinaryTag.builder(); + chatRegistryEntry.putString("type", "minecraft:chat_type"); + chatRegistryEntry.put("value", encodedChatRegistry); + registryContainer.put("minecraft:chat_type", encodedChatRegistry); } } else { registryContainer.put("dimension", encodedDimensionRegistry);