From d6022d1ee9fb7445535414f75e1837e98d1b9fb9 Mon Sep 17 00:00:00 2001 From: ReinforceZwei Date: Sun, 24 May 2020 09:33:21 +0800 Subject: [PATCH] Rename ClickWindow to WindowAction --- MinecraftClient/Commands/Inventory.cs | 14 +++++++------- MinecraftClient/Inventory/WindowActionType.cs | 14 ++++++++++++++ MinecraftClient/McTcpClient.cs | 4 ++-- MinecraftClient/MinecraftClient.csproj | 1 + MinecraftClient/Protocol/Handlers/Protocol16.cs | 2 +- MinecraftClient/Protocol/Handlers/Protocol18.cs | 17 +++++++++++------ MinecraftClient/Protocol/IMinecraftCom.cs | 4 ++-- 7 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 MinecraftClient/Inventory/WindowActionType.cs diff --git a/MinecraftClient/Commands/Inventory.cs b/MinecraftClient/Commands/Inventory.cs index 057c3225..d1e0797a 100644 --- a/MinecraftClient/Commands/Inventory.cs +++ b/MinecraftClient/Commands/Inventory.cs @@ -9,7 +9,7 @@ namespace MinecraftClient.Commands class Inventory : Command { public override string CMDName { get { return "inventory"; } } - public override string CMDDesc { get { return "inventory <|player|container> >: Interact with inventories"; } } + public override string CMDDesc { get { return "inventory <|player|container> >: Interact with inventories"; } } public override string Run(McTcpClient handler, string command, Dictionary localVars) { @@ -63,23 +63,23 @@ namespace MinecraftClient.Commands if (args.Length >= 3) { int slot = int.Parse(args[2]); - byte buttom = 0; + WindowActionType actionType = WindowActionType.LeftClick; string keyName = "Left"; if (args.Length == 4) { string b = args[3]; - if (b.ToLower() == "r") + if (b.ToLower()[0] == 'r') { - buttom = 1; + actionType = WindowActionType.RightClick; keyName = "Right"; } - if (b.ToLower() == "m") + if (b.ToLower()[0] == 'm') { - buttom = 2; + actionType = WindowActionType.MiddleClick; keyName = "Middle"; } } - handler.ClickWindowSlot(inventoryId, slot, buttom); + handler.DoWindowAction(inventoryId, slot, actionType); return keyName + " clicking slot " + slot + " in window #" + inventoryId; } else return CMDDesc; diff --git a/MinecraftClient/Inventory/WindowActionType.cs b/MinecraftClient/Inventory/WindowActionType.cs new file mode 100644 index 00000000..c4688baa --- /dev/null +++ b/MinecraftClient/Inventory/WindowActionType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MinecraftClient.Inventory +{ + public enum WindowActionType + { + LeftClick, + RightClick, + MiddleClick + } +} diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index bc9a3815..c5fb4027 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -1511,13 +1511,13 @@ namespace MinecraftClient /// Click a slot in the specified window /// /// TRUE if the slot was successfully clicked - public bool ClickWindowSlot(int windowId, int slotId, byte buttom) + public bool DoWindowAction(int windowId, int slotId, WindowActionType action) { Item item = null; if (inventories.ContainsKey(windowId) && inventories[windowId].Items.ContainsKey(slotId)) item = inventories[windowId].Items[slotId]; - return handler.SendClickWindow(windowId, slotId, buttom, item); + return handler.SendWindowAction(windowId, slotId, action, item); } /// diff --git a/MinecraftClient/MinecraftClient.csproj b/MinecraftClient/MinecraftClient.csproj index ed121f24..a62ed363 100644 --- a/MinecraftClient/MinecraftClient.csproj +++ b/MinecraftClient/MinecraftClient.csproj @@ -111,6 +111,7 @@ + diff --git a/MinecraftClient/Protocol/Handlers/Protocol16.cs b/MinecraftClient/Protocol/Handlers/Protocol16.cs index 6e1bf70c..8372c247 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol16.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol16.cs @@ -688,7 +688,7 @@ namespace MinecraftClient.Protocol.Handlers return false; //Currently not implemented } - public bool SendClickWindow(int windowId, int slotId, byte buttom, Item item) + public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item) { return false; //Currently not implemented } diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 1ee17ec9..61940cf0 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -1342,7 +1342,7 @@ namespace MinecraftClient.Protocol.Handlers catch (ObjectDisposedException) { return false; } } - public bool SendClickWindow(int windowId, int slotId, byte buttom, Item item) + public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item) { try { @@ -1355,16 +1355,21 @@ namespace MinecraftClient.Protocol.Handlers window_actions[windowId] = actionNumber; } + byte button = 0; + byte mode = 0; + switch (action) + { + case WindowActionType.LeftClick: button = 0; break; + case WindowActionType.RightClick: button = 1; break; + case WindowActionType.MiddleClick: button = 2; mode = 3; break; + } + List packet = new List(); packet.Add((byte)windowId); packet.AddRange(dataTypes.GetShort((short)slotId)); - packet.Add(buttom); + packet.Add(button); packet.AddRange(dataTypes.GetShort(actionNumber)); - // Operation mode = 0 (default) - byte mode = 0; - if (buttom == 2) // middle-click mode is 3 - mode = 3; if (protocolversion >= MC19Version) packet.AddRange(dataTypes.GetVarInt(mode)); else packet.Add(mode); diff --git a/MinecraftClient/Protocol/IMinecraftCom.cs b/MinecraftClient/Protocol/IMinecraftCom.cs index 8db23c69..20ba4b64 100644 --- a/MinecraftClient/Protocol/IMinecraftCom.cs +++ b/MinecraftClient/Protocol/IMinecraftCom.cs @@ -144,10 +144,10 @@ namespace MinecraftClient.Protocol /// /// Id of the window being clicked /// Id of the clicked slot - /// 0 for left click, 1 for right click, 2 for middle click + /// Action to perform /// Item in the clicked slot /// True if packet was successfully sent - bool SendClickWindow(int windowId, int slotId, byte buttom, Item item); + bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item); /// /// Send a close window packet to the server