mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Interact with inventories
The /inventory command allow listing inventory and clicking on items Should be enough for operating GUI menus such as Server chooser/teleporter
This commit is contained in:
parent
bc3d6aba00
commit
e04f06cece
13 changed files with 574 additions and 217 deletions
|
|
@ -6,23 +6,63 @@ using MinecraftClient.Inventory;
|
|||
|
||||
namespace MinecraftClient.Commands
|
||||
{
|
||||
class GetInventory : Command
|
||||
class Inventory : Command
|
||||
{
|
||||
public override string CMDName { get { return "inventory"; } }
|
||||
public override string CMDDesc { get { return "inventory: Show your inventory."; } }
|
||||
public override string CMDDesc { get { return "inventory <id> <list|close|click <slot>>: Interact with inventories"; } }
|
||||
|
||||
public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars)
|
||||
{
|
||||
List<string> response = new List<string>();
|
||||
|
||||
response.Add("Inventory slots:");
|
||||
|
||||
foreach (KeyValuePair<int, Item> item in handler.GetPlayerInventory().Items)
|
||||
if (handler.GetInventoryEnabled())
|
||||
{
|
||||
response.Add(String.Format(" #{0}: {1} x{2}", item.Key, item.Value.Type, item.Value.Count));
|
||||
string[] args = getArgs(command);
|
||||
if (args.Length >= 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
int inventoryId = int.Parse(args[0]);
|
||||
string action = args.Length > 1
|
||||
? args[1].ToLower()
|
||||
: "list";
|
||||
switch (action)
|
||||
{
|
||||
case "close":
|
||||
if (handler.CloseInventory(inventoryId))
|
||||
return "Closing Inventoy #" + inventoryId;
|
||||
else return "Failed to close Inventory #" + inventoryId;
|
||||
case "list":
|
||||
Container inventory = handler.GetInventory(inventoryId);
|
||||
List<string> response = new List<string>();
|
||||
response.Add("Inventory #" + inventoryId + " - " + inventory.Title + "§8");
|
||||
foreach (KeyValuePair<int, Item> item in inventory.Items)
|
||||
response.Add(String.Format(" #{0}: {1} x{2}", item.Key, item.Value.Type, item.Value.Count));
|
||||
return String.Join("\n", response.ToArray());
|
||||
case "click":
|
||||
if (args.Length == 3)
|
||||
{
|
||||
int slot = int.Parse(args[2]);
|
||||
handler.ClickWindowSlot(inventoryId, slot);
|
||||
return "Clicking slot " + slot + " in window #" + inventoryId;
|
||||
}
|
||||
else return CMDDesc;
|
||||
default:
|
||||
return CMDDesc;
|
||||
}
|
||||
}
|
||||
catch (FormatException) { return CMDDesc; }
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<int, Container> inventories = handler.GetInventories();
|
||||
List<string> response = new List<string>();
|
||||
response.Add("Inventories:");
|
||||
foreach (var inventory in inventories)
|
||||
response.Add(String.Format(" #{0}: {1}", inventory.Key, inventory.Value.Title + "§8"));
|
||||
response.Add(CMDDesc);
|
||||
return String.Join("\n", response);
|
||||
}
|
||||
}
|
||||
|
||||
return String.Join("\n", response.ToArray());
|
||||
else return "Please enable inventoryhandling in config to use this command.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,12 @@ namespace MinecraftClient.Commands
|
|||
|
||||
public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars)
|
||||
{
|
||||
handler.UseItemOnHand();
|
||||
return "Use an item";
|
||||
if (handler.GetInventoryEnabled())
|
||||
{
|
||||
handler.UseItemOnHand();
|
||||
return "Used an item";
|
||||
}
|
||||
else return "Please enable inventoryhandling in config to use this command.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue