mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Rename ClickWindow to WindowAction
This commit is contained in:
parent
1e5b9fc94b
commit
d6022d1ee9
7 changed files with 38 additions and 18 deletions
|
|
@ -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|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)
|
||||
{
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
14
MinecraftClient/Inventory/WindowActionType.cs
Normal file
14
MinecraftClient/Inventory/WindowActionType.cs
Normal 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
|
||||
}
|
||||
}
|
||||
|
|
@ -1511,13 +1511,13 @@ namespace MinecraftClient
|
|||
/// Click a slot in the specified window
|
||||
/// </summary>
|
||||
/// <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;
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@
|
|||
<Compile Include="Inventory\ItemType.cs" />
|
||||
<Compile Include="Inventory\ItemTypeExtensions.cs" />
|
||||
<Compile Include="Inventory\ItemTypeGenerator.cs" />
|
||||
<Compile Include="Inventory\WindowActionType.cs" />
|
||||
<Compile Include="Mapping\BlockPalettes\Palette112.cs" />
|
||||
<Compile Include="Mapping\BlockPalettes\Palette113.cs" />
|
||||
<Compile Include="Mapping\BlockPalettes\Palette114.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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<byte> packet = new List<byte>();
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -144,10 +144,10 @@ 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, 2 for middle click</param>
|
||||
/// <param name="buttom">Action to perform</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);
|
||||
bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item);
|
||||
|
||||
/// <summary>
|
||||
/// Send a close window packet to the server
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue