From 27e66433cdd1997a7ff69e0dfb7ca6d79646e30d Mon Sep 17 00:00:00 2001 From: breadbyte <14045257+breadbyte@users.noreply.github.com> Date: Sat, 7 Sep 2024 03:45:45 +0800 Subject: [PATCH] Hotfix for 'minecraft:chat_type' not present in the dictionary (#2794) --- .../Protocol/Message/ChatParser.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/MinecraftClient/Protocol/Message/ChatParser.cs b/MinecraftClient/Protocol/Message/ChatParser.cs index 5bfd2b66..c4ef9837 100644 --- a/MinecraftClient/Protocol/Message/ChatParser.cs +++ b/MinecraftClient/Protocol/Message/ChatParser.cs @@ -34,8 +34,25 @@ namespace MinecraftClient.Protocol.Message public static void ReadChatType(Dictionary registryCodec) { Dictionary chatTypeDictionary = ChatId2Type ?? new(); - var chatTypeListNbt = - (object[])(((Dictionary)registryCodec["minecraft:chat_type"])["value"]); + + // Check if the chat type registry is in the correct format + if (!registryCodec.ContainsKey("minecraft:chat_type")) { + + // If not, then we force the registry to be in the correct format + if (registryCodec.ContainsKey("chat_type")) { + + foreach (var key in registryCodec.Keys.ToArray()) { + // Skip entries with a namespace already + if (key.Contains(':', StringComparison.OrdinalIgnoreCase)) continue; + + // Assume all other entries are in the minecraft namespace + registryCodec["minecraft:" + key] = registryCodec[key]; + registryCodec.Remove(key); + } + } + } + + var chatTypeListNbt = (object[])(((Dictionary)registryCodec["minecraft:chat_type"])["value"]); foreach (var (chatName, chatId) in from Dictionary chatTypeNbt in chatTypeListNbt let chatName = (string)chatTypeNbt["name"] let chatId = (int)chatTypeNbt["id"]