Fix open container crash (#2996)

This commit is contained in:
BruceChen 2026-03-26 02:37:11 +08:00 committed by GitHub
commit 6beb00bae4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 2 deletions

View file

@ -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);

View file

@ -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));

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Sockets;
using MinecraftClient.Crypto;
@ -90,6 +90,9 @@ namespace MinecraftClient.Protocol.Handlers
/// <param name="buffer">data to send</param>
public void SendDataRAW(byte[] buffer)
{
if (!IsConnected())
throw new SocketException((int)SocketError.NotConnected);
if (encrypted)
s!.Write(buffer, 0, buffer.Length);
else

View file

@ -6332,6 +6332,15 @@ namespace MinecraftClient {
}
}
/// <summary>
/// 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..
/// </summary>
internal static string cmd_inventory_tui_unsupported_container {
get {
return ResourceManager.GetString("cmd.inventory.tui_unsupported_container", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Hold Shift + Left-click to select and copy text..
/// </summary>

View file

@ -2229,6 +2229,9 @@ Logging in...</value>
<data name="cmd.inventory.tui_launch_failed" xml:space="preserve">
<value>Failed to launch TUI inventory viewer.</value>
</data>
<data name="cmd.inventory.tui_unsupported_container" xml:space="preserve">
<value>TUI viewer does not support this container type (Inventory #{0}). Use '/inventory {0} list' to view its contents.</value>
</data>
<data name="tui.select_copy_hint" xml:space="preserve">
<value>Hold Shift + Left-click to select and copy text.</value>
</data>