From 1e5b9fc94b9e5b1c2bfbd14a23353e5aea5b85bd Mon Sep 17 00:00:00 2001 From: ReinforceZwei Date: Sat, 23 May 2020 09:20:48 +0800 Subject: [PATCH] Implement middle click --- MinecraftClient/Commands/Inventory.cs | 13 +++++++++++-- MinecraftClient/Protocol/Handlers/Protocol18.cs | 7 +++++-- MinecraftClient/Protocol/IMinecraftCom.cs | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/MinecraftClient/Commands/Inventory.cs b/MinecraftClient/Commands/Inventory.cs index 0c9b1452..057c3225 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) { @@ -64,14 +64,23 @@ namespace MinecraftClient.Commands { int slot = int.Parse(args[2]); byte buttom = 0; + string keyName = "Left"; if (args.Length == 4) { string b = args[3]; if (b.ToLower() == "r") + { buttom = 1; + keyName = "Right"; + } + if (b.ToLower() == "m") + { + buttom = 2; + keyName = "Middle"; + } } handler.ClickWindowSlot(inventoryId, slot, buttom); - return buttom + " Clicking slot " + slot + " in window #" + inventoryId; + return keyName + " clicking slot " + slot + " in window #" + inventoryId; } else return CMDDesc; default: diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index c3a69cf2..1ee17ec9 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -1362,9 +1362,12 @@ namespace MinecraftClient.Protocol.Handlers 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(0)); - else packet.Add(0); + packet.AddRange(dataTypes.GetVarInt(mode)); + else packet.Add(mode); packet.AddRange(dataTypes.GetItemSlot(item)); diff --git a/MinecraftClient/Protocol/IMinecraftCom.cs b/MinecraftClient/Protocol/IMinecraftCom.cs index c8134de1..8db23c69 100644 --- a/MinecraftClient/Protocol/IMinecraftCom.cs +++ b/MinecraftClient/Protocol/IMinecraftCom.cs @@ -144,7 +144,7 @@ namespace MinecraftClient.Protocol /// /// Id of the window being clicked /// Id of the clicked slot - /// 0 for left click, 1 for right click + /// 0 for left click, 1 for right click, 2 for middle click /// Item in the clicked slot /// True if packet was successfully sent bool SendClickWindow(int windowId, int slotId, byte buttom, Item item);