Implement middle click

This commit is contained in:
ReinforceZwei 2020-05-23 09:20:48 +08:00 committed by ORelio
parent 02d393fe4d
commit 1e5b9fc94b
3 changed files with 17 additions and 5 deletions

View file

@ -9,7 +9,7 @@ namespace MinecraftClient.Commands
class Inventory : Command
{
public override string CMDName { get { return "inventory"; } }
public override string CMDDesc { get { return "inventory <<id>|player|container> <list|close|click <slot> <L|R>>: Interact with inventories"; } }
public override string CMDDesc { get { return "inventory <<id>|player|container> <list|close|click <slot> <L|R|M>>: Interact with inventories"; } }
public override string Run(McTcpClient handler, string command, Dictionary<string, object> 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:

View file

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

View file

@ -144,7 +144,7 @@ namespace MinecraftClient.Protocol
/// </summary>
/// <param name="windowId">Id of the window being clicked</param>
/// <param name="slotId">Id of the clicked slot</param>
/// <param name="buttom">0 for left click, 1 for right click</param>
/// <param name="buttom">0 for left click, 1 for right click, 2 for middle click</param>
/// <param name="item">Item in the clicked slot</param>
/// <returns>True if packet was successfully sent</returns>
bool SendClickWindow(int windowId, int slotId, byte buttom, Item item);