From c2dc483d36dd1ac4c6ce1f90127787940d3cbd55 Mon Sep 17 00:00:00 2001 From: ORelio Date: Fri, 1 May 2020 13:41:26 +0200 Subject: [PATCH] Add /inventory player and /inventory container Allow interacting with an inventory without specifying an ID Useful for automated interactions when container has in incremental ID Eg. /inventory container click 1 See #981 --- MinecraftClient/Commands/Inventory.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/MinecraftClient/Commands/Inventory.cs b/MinecraftClient/Commands/Inventory.cs index e454bd50..0db3aa8d 100644 --- a/MinecraftClient/Commands/Inventory.cs +++ b/MinecraftClient/Commands/Inventory.cs @@ -9,7 +9,7 @@ namespace MinecraftClient.Commands class Inventory : Command { public override string CMDName { get { return "inventory"; } } - public override string CMDDesc { get { return "inventory >: Interact with inventories"; } } + public override string CMDDesc { get { return "inventory <|player|container> >: Interact with inventories"; } } public override string Run(McTcpClient handler, string command, Dictionary localVars) { @@ -20,7 +20,21 @@ namespace MinecraftClient.Commands { try { - int inventoryId = int.Parse(args[0]); + int inventoryId; + if (args[0].ToLower() == "player") + { + // player inventory is always ID 0 + inventoryId = 0; + } + else if (args[0].ToLower() == "container") + { + List availableIds = handler.GetInventories().Keys.ToList(); + availableIds.Remove(0); // remove player inventory ID from list + if (availableIds.Count == 1) + inventoryId = availableIds[0]; // one container, use it + else return "Cannot find container, please retry with explicit ID"; + } + else inventoryId = int.Parse(args[0]); string action = args.Length > 1 ? args[1].ToLower() : "list";