From 59ed18bb407c182a0cec04b5e562f858511126c3 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Sun, 24 Jul 2022 22:21:15 +0800 Subject: [PATCH] Fixed incorrect handling in 1.18(1.18.1) and 1.18.2 --- MinecraftClient/ChatBot.cs | 2 +- MinecraftClient/McClient.cs | 2 +- MinecraftClient/Protocol/Handlers/DataTypes.cs | 5 ++++- MinecraftClient/Protocol/Handlers/Protocol18.cs | 11 ++++++++--- MinecraftClient/Protocol/IMinecraftComHandler.cs | 2 +- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index 3b37d98b..5e354399 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -327,7 +327,7 @@ namespace MinecraftClient /// 0 to create/update an item. 1 to remove an item. /// The name of the objective the score belongs to /// The score to be displayed next to the entry. Only sent when Action does not equal 1. - public virtual void OnUpdateScore(string entityname, byte action, string objectivename, int value) { } + public virtual void OnUpdateScore(string entityname, int action, string objectivename, int value) { } /// /// Called when an inventory/container was updated by server diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index 9d0fbf7c..d608cc5d 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -2490,7 +2490,7 @@ namespace MinecraftClient /// 0 to create/update an item. 1 to remove an item. /// The name of the objective the score belongs to /// he score to be displayed next to the entry. Only sent when Action does not equal 1. - public void OnUpdateScore(string entityname, byte action, string objectivename, int value) + public void OnUpdateScore(string entityname, int action, string objectivename, int value) { DispatchBotEvent(bot => bot.OnUpdateScore(entityname, action, objectivename, value)); } diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index 3bcacf7b..b8f894b6 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -410,7 +410,10 @@ namespace MinecraftClient.Protocol.Handlers if (living) { - entityPitch = ReadNextByte(cache); + if (protocolversion >= Protocol18Handler.MC1182Version) + entityYaw = ReadNextByte(cache); + else + entityPitch = ReadNextByte(cache); } else { diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index a0b9766b..abc4f2bb 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -1208,7 +1208,7 @@ namespace MinecraftClient.Protocol.Handlers break; case PacketTypesIn.UpdateScore: string entityname = dataTypes.ReadNextString(packetData); - byte action3 = dataTypes.ReadNextByte(packetData); + int action3 = protocolversion >= MC1182Version ? dataTypes.ReadNextVarInt(packetData) : dataTypes.ReadNextByte(packetData); string objectivename2 = null; int value = -1; if (action3 != 1 || protocolversion >= MC18Version) @@ -1713,7 +1713,12 @@ namespace MinecraftClient.Protocol.Handlers if (protocolversion >= MC19Version) fields.AddRange(dataTypes.GetVarInt(mainHand)); if (protocolversion >= MC117Version) - fields.Add(1); // 1.17 and above - Disable text filtering. (Always true) + { + if (protocolversion == MC117Version || protocolversion == MC1171Version) + fields.Add(1); // 1.17 and 1.17.1 - Disable text filtering. (Always true) + else + fields.Add(0); // 1.18 and above - Enable text filtering. (Always false) + } if (protocolversion >= MC1181Version) fields.Add(1); // 1.18 and above - Allow server listings SendPacket(PacketTypesOut.ClientSettings, fields); @@ -2040,7 +2045,7 @@ namespace MinecraftClient.Protocol.Handlers packet.AddRange(arrayOfSlots); } - packet.AddRange(dataTypes.GetItemSlot(item, itemPalette)); // Clicked item + packet.AddRange(dataTypes.GetItemSlot(item, itemPalette)); // Carried item (Clicked item) log.Info("Packet data: " + dataTypes.ByteArrayToString(packet.ToArray())); diff --git a/MinecraftClient/Protocol/IMinecraftComHandler.cs b/MinecraftClient/Protocol/IMinecraftComHandler.cs index 2b63d5e7..4ca8faf9 100644 --- a/MinecraftClient/Protocol/IMinecraftComHandler.cs +++ b/MinecraftClient/Protocol/IMinecraftComHandler.cs @@ -374,7 +374,7 @@ namespace MinecraftClient.Protocol /// 0 to create/update an item. 1 to remove an item. /// The name of the objective the score belongs to /// he score to be displayed next to the entry. Only sent when Action does not equal 1. - void OnUpdateScore(string entityname, byte action, string objectivename, int value); + void OnUpdateScore(string entityname, int action, string objectivename, int value); /// /// Called when tradeList is received from server