From dcfff3f1bafacf87d9b1c9a8ba1c0fef3449edff Mon Sep 17 00:00:00 2001 From: BruceChen Date: Thu, 26 Mar 2026 02:35:43 +0800 Subject: [PATCH 1/2] feat: enhance Protocol18 and SocketWrapper for improved functionality - Added support for the new world border hit flag in Protocol18 for protocol version 1.21.2. - Updated SocketWrapper to throw a SocketException if SendDataRAW is called when not connected, improving error handling. These changes enhance the protocol handling and error management in the Minecraft Console Client. --- MinecraftClient/Protocol/Handlers/Protocol18.cs | 5 ++++- MinecraftClient/Protocol/Handlers/SocketWrapper.cs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 84c7baac..b9128587 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -4587,7 +4587,10 @@ namespace MinecraftClient.Protocol.Handlers if(protocolVersion >= MC_1_14_Version) packet.Add(0); // insideBlock = false - + + if (protocolVersion >= MC_1_21_2_Version) + packet.Add(0); // worldBorderHit = false + if (protocolVersion >= MC_1_19_Version) packet.AddRange(DataTypes.GetVarInt(sequenceId)); diff --git a/MinecraftClient/Protocol/Handlers/SocketWrapper.cs b/MinecraftClient/Protocol/Handlers/SocketWrapper.cs index 338bcd46..a4f451b1 100644 --- a/MinecraftClient/Protocol/Handlers/SocketWrapper.cs +++ b/MinecraftClient/Protocol/Handlers/SocketWrapper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net.Sockets; using MinecraftClient.Crypto; @@ -90,6 +90,9 @@ namespace MinecraftClient.Protocol.Handlers /// data to send public void SendDataRAW(byte[] buffer) { + if (!IsConnected()) + throw new SocketException((int)SocketError.NotConnected); + if (encrypted) s!.Write(buffer, 0, buffer.Length); else From e5b81fe42843b677862ad3a45562f868988c4f63 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Thu, 26 Mar 2026 02:35:50 +0800 Subject: [PATCH 2/2] feat: add support for unsupported container type in inventory TUI - Implemented a check in the Inventory command to log a warning and return a failure status if the container type is not PlayerInventory. - Added a new localized string for the warning message to inform users about unsupported container types. These changes improve user feedback and error handling in the inventory management system. --- MinecraftClient/Commands/Inventory.cs | 6 ++++++ .../Resources/Translations/Translations.Designer.cs | 9 +++++++++ MinecraftClient/Resources/Translations/Translations.resx | 3 +++ 3 files changed, 18 insertions(+) diff --git a/MinecraftClient/Commands/Inventory.cs b/MinecraftClient/Commands/Inventory.cs index eeeee3d0..5936afd0 100644 --- a/MinecraftClient/Commands/Inventory.cs +++ b/MinecraftClient/Commands/Inventory.cs @@ -435,6 +435,12 @@ namespace MinecraftClient.Commands return r.SetAndReturn(CmdResult.Status.Fail, msg); } + if (container.Type != ContainerType.PlayerInventory) + { + handler.Log.Warn(string.Format(Translations.cmd_inventory_tui_unsupported_container, inventoryId)); + return r.SetAndReturn(CmdResult.Status.Fail); + } + handler.Log.Info(string.Format(Translations.cmd_inventory_tui_opening, inventoryId)); bool success = InventoryTuiHost.Launch(handler, inventoryId); diff --git a/MinecraftClient/Resources/Translations/Translations.Designer.cs b/MinecraftClient/Resources/Translations/Translations.Designer.cs index 10fddca1..d20d36af 100644 --- a/MinecraftClient/Resources/Translations/Translations.Designer.cs +++ b/MinecraftClient/Resources/Translations/Translations.Designer.cs @@ -6332,6 +6332,15 @@ namespace MinecraftClient { } } + /// + /// Looks up a localized string similar to TUI viewer does not support this container type (Inventory #{0}). Use '/inventory {0} list' to view its contents.. + /// + internal static string cmd_inventory_tui_unsupported_container { + get { + return ResourceManager.GetString("cmd.inventory.tui_unsupported_container", resourceCulture); + } + } + /// /// Looks up a localized string similar to Hold Shift + Left-click to select and copy text.. /// diff --git a/MinecraftClient/Resources/Translations/Translations.resx b/MinecraftClient/Resources/Translations/Translations.resx index a877ef80..5eb2fa76 100644 --- a/MinecraftClient/Resources/Translations/Translations.resx +++ b/MinecraftClient/Resources/Translations/Translations.resx @@ -2229,6 +2229,9 @@ Logging in... Failed to launch TUI inventory viewer. + + TUI viewer does not support this container type (Inventory #{0}). Use '/inventory {0} list' to view its contents. + Hold Shift + Left-click to select and copy text.