mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Implement inventory right click
This commit is contained in:
parent
5da55a2f9a
commit
4f96aa2081
5 changed files with 16 additions and 8 deletions
|
|
@ -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>>: Interact with inventories"; } }
|
public override string CMDDesc { get { return "inventory <<id>|player|container> <list|close|click <slot> <L|R>>: 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)
|
||||||
{
|
{
|
||||||
|
|
@ -60,10 +60,17 @@ namespace MinecraftClient.Commands
|
||||||
if (inventoryId == 0) response.Add("Your selected hotbar is " + (handler.GetCurrentSlot() + 1));
|
if (inventoryId == 0) response.Add("Your selected hotbar is " + (handler.GetCurrentSlot() + 1));
|
||||||
return String.Join("\n", response.ToArray());
|
return String.Join("\n", response.ToArray());
|
||||||
case "click":
|
case "click":
|
||||||
|
byte buttom = 0;
|
||||||
|
if (args.Length == 4)
|
||||||
|
{
|
||||||
|
string b = args[3];
|
||||||
|
if (b.ToLower() == "r")
|
||||||
|
buttom = 1;
|
||||||
|
}
|
||||||
if (args.Length == 3)
|
if (args.Length == 3)
|
||||||
{
|
{
|
||||||
int slot = int.Parse(args[2]);
|
int slot = int.Parse(args[2]);
|
||||||
handler.ClickWindowSlot(inventoryId, slot);
|
handler.ClickWindowSlot(inventoryId, slot, buttom);
|
||||||
return "Clicking slot " + slot + " in window #" + inventoryId;
|
return "Clicking slot " + slot + " in window #" + inventoryId;
|
||||||
}
|
}
|
||||||
else return CMDDesc;
|
else return CMDDesc;
|
||||||
|
|
|
||||||
|
|
@ -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)
|
public bool ClickWindowSlot(int windowId, int slotId, byte buttom)
|
||||||
{
|
{
|
||||||
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, item);
|
return handler.SendClickWindow(windowId, slotId, buttom, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -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, Item item)
|
public bool SendClickWindow(int windowId, int slotId, byte buttom, Item item)
|
||||||
{
|
{
|
||||||
return false; //Currently not implemented
|
return false; //Currently not implemented
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1342,7 +1342,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
catch (ObjectDisposedException) { return false; }
|
catch (ObjectDisposedException) { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SendClickWindow(int windowId, int slotId, Item item)
|
public bool SendClickWindow(int windowId, int slotId, byte buttom, Item item)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -1358,7 +1358,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
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(0); // Left mouse click
|
packet.Add(buttom);
|
||||||
packet.AddRange(dataTypes.GetShort(actionNumber));
|
packet.AddRange(dataTypes.GetShort(actionNumber));
|
||||||
|
|
||||||
// Operation mode = 0 (default)
|
// Operation mode = 0 (default)
|
||||||
|
|
|
||||||
|
|
@ -144,9 +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</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, Item item);
|
bool SendClickWindow(int windowId, int slotId, byte buttom, Item item);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Send a close window packet to the server
|
/// Send a close window packet to the server
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue