Rename ClickWindow to WindowAction

This commit is contained in:
ReinforceZwei 2020-05-24 09:33:21 +08:00 committed by ORelio
parent 1e5b9fc94b
commit d6022d1ee9
7 changed files with 38 additions and 18 deletions

View file

@ -9,7 +9,7 @@ namespace MinecraftClient.Commands
class Inventory : Command class Inventory : Command
{ {
public override string CMDName { get { return "inventory"; } } public override string CMDName { get { return "inventory"; } }
public override string CMDDesc { get { return "inventory <<id>|player|container> <list|close|click <slot> <L|R|M>>: Interact with inventories"; } } public override string CMDDesc { get { return "inventory <<id>|player|container> <list|close|click <slot> <left|right|middle>>: Interact with inventories"; } }
public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars) public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars)
{ {
@ -63,23 +63,23 @@ namespace MinecraftClient.Commands
if (args.Length >= 3) if (args.Length >= 3)
{ {
int slot = int.Parse(args[2]); int slot = int.Parse(args[2]);
byte buttom = 0; WindowActionType actionType = WindowActionType.LeftClick;
string keyName = "Left"; string keyName = "Left";
if (args.Length == 4) if (args.Length == 4)
{ {
string b = args[3]; string b = args[3];
if (b.ToLower() == "r") if (b.ToLower()[0] == 'r')
{ {
buttom = 1; actionType = WindowActionType.RightClick;
keyName = "Right"; keyName = "Right";
} }
if (b.ToLower() == "m") if (b.ToLower()[0] == 'm')
{ {
buttom = 2; actionType = WindowActionType.MiddleClick;
keyName = "Middle"; keyName = "Middle";
} }
} }
handler.ClickWindowSlot(inventoryId, slot, buttom); handler.DoWindowAction(inventoryId, slot, actionType);
return keyName + " clicking slot " + slot + " in window #" + inventoryId; return keyName + " clicking slot " + slot + " in window #" + inventoryId;
} }
else return CMDDesc; else return CMDDesc;

View file

@ -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
}
}

View file

@ -1511,13 +1511,13 @@ namespace MinecraftClient
/// Click a slot in the specified window /// Click a slot in the specified window
/// </summary> /// </summary>
/// <returns>TRUE if the slot was successfully clicked</returns> /// <returns>TRUE if the slot was successfully clicked</returns>
public bool ClickWindowSlot(int windowId, int slotId, byte buttom) public bool DoWindowAction(int windowId, int slotId, WindowActionType action)
{ {
Item item = null; Item item = null;
if (inventories.ContainsKey(windowId) && inventories[windowId].Items.ContainsKey(slotId)) if (inventories.ContainsKey(windowId) && inventories[windowId].Items.ContainsKey(slotId))
item = inventories[windowId].Items[slotId]; item = inventories[windowId].Items[slotId];
return handler.SendClickWindow(windowId, slotId, buttom, item); return handler.SendWindowAction(windowId, slotId, action, item);
} }
/// <summary> /// <summary>

View file

@ -111,6 +111,7 @@
<Compile Include="Inventory\ItemType.cs" /> <Compile Include="Inventory\ItemType.cs" />
<Compile Include="Inventory\ItemTypeExtensions.cs" /> <Compile Include="Inventory\ItemTypeExtensions.cs" />
<Compile Include="Inventory\ItemTypeGenerator.cs" /> <Compile Include="Inventory\ItemTypeGenerator.cs" />
<Compile Include="Inventory\WindowActionType.cs" />
<Compile Include="Mapping\BlockPalettes\Palette112.cs" /> <Compile Include="Mapping\BlockPalettes\Palette112.cs" />
<Compile Include="Mapping\BlockPalettes\Palette113.cs" /> <Compile Include="Mapping\BlockPalettes\Palette113.cs" />
<Compile Include="Mapping\BlockPalettes\Palette114.cs" /> <Compile Include="Mapping\BlockPalettes\Palette114.cs" />

View file

@ -688,7 +688,7 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented 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 return false; //Currently not implemented
} }

View file

@ -1342,7 +1342,7 @@ namespace MinecraftClient.Protocol.Handlers
catch (ObjectDisposedException) { return false; } 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 try
{ {
@ -1355,16 +1355,21 @@ namespace MinecraftClient.Protocol.Handlers
window_actions[windowId] = actionNumber; 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<byte> packet = new List<byte>(); List<byte> packet = new List<byte>();
packet.Add((byte)windowId); packet.Add((byte)windowId);
packet.AddRange(dataTypes.GetShort((short)slotId)); packet.AddRange(dataTypes.GetShort((short)slotId));
packet.Add(buttom); packet.Add(button);
packet.AddRange(dataTypes.GetShort(actionNumber)); 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) if (protocolversion >= MC19Version)
packet.AddRange(dataTypes.GetVarInt(mode)); packet.AddRange(dataTypes.GetVarInt(mode));
else packet.Add(mode); else packet.Add(mode);

View file

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