diff --git a/MinecraftClient/Commands/GetInventory.cs b/MinecraftClient/Commands/Inventory.cs similarity index 78% rename from MinecraftClient/Commands/GetInventory.cs rename to MinecraftClient/Commands/Inventory.cs index b9811b50..b55bd564 100644 --- a/MinecraftClient/Commands/GetInventory.cs +++ b/MinecraftClient/Commands/Inventory.cs @@ -8,8 +8,8 @@ namespace MinecraftClient.Commands { class GetInventory : Command { - public override string CMDName { get { return "getinventory"; } } - public override string CMDDesc { get { return "getinventory: Show your inventory."; } } + public override string CMDName { get { return "inventory"; } } + public override string CMDDesc { get { return "inventory: Show your inventory."; } } public override string Run(McTcpClient handler, string command, Dictionary localVars) { diff --git a/MinecraftClient/Inventory/Container.cs b/MinecraftClient/Inventory/Container.cs index be63b301..97f97e27 100644 --- a/MinecraftClient/Inventory/Container.cs +++ b/MinecraftClient/Inventory/Container.cs @@ -5,50 +5,123 @@ using System.Text; namespace MinecraftClient.Inventory { + /// + /// Represents a Minecraft inventory (player inventory, chest, etc.) + /// public class Container { + /// + /// ID of the container on the server + /// public int ID; + + /// + /// Type of container + /// public ContainerType Type; + + /// + /// title of container + /// public string Title; + + /// + /// Container Items + /// public Dictionary Items; - + + /// + /// Create an empty container + /// public Container() { } + + /// + /// Create an empty container with ID, Type and Title + /// + /// Container ID + /// Container Type + /// Container Title public Container(int id, ContainerType type, string title) { ID = id; Type = type; Title = title; + Items = new Dictionary(); } - public Container(int id, ContainerType type, string title,Dictionary items) + + /// + /// Create a container with ID, Type, Title and Items + /// + /// Container ID + /// Container Type + /// Container Title + /// Container Items (key: slot ID, value: item info) + public Container(int id, ContainerType type, string title, Dictionary items) { ID = id; Type = type; Title = title; Items = items; } + + /// + /// Create an empty container with ID, Type and Title + /// + /// Container ID + /// Container Type + /// Container title public Container(int id, ContainerTypeOld type, string title) { ID = id; Title = title; Type = ConvertType.ToNew(type); + Items = new Dictionary(); } + + /// + /// Create an empty container with ID, Type and Title + /// + /// Container ID + /// Container Type + /// Container Title public Container(int id, int typeID, string title) { ID = id; Type = GetContainerType(typeID); Title = title; + Items = new Dictionary(); } - // for player inventory because they dont have ID and title + + /// + /// Create an empty container with Type + /// + /// Container Type public Container(ContainerType type) { + ID = -1; Type = type; + Title = null; + Items = new Dictionary(); } + + /// + /// Create an empty container with T^ype and Items + /// + /// Container Type + /// Container Items (key: slot ID, value: item info) public Container(ContainerType type, Dictionary items) { + ID = -1; Type = type; + Title = null; Items = items; } + /// + /// Get container type from Type ID + /// + /// Container Type ID + /// Container Type public static ContainerType GetContainerType(int typeID) { // https://wiki.vg/Inventory didn't state the inventory ID, assume that list start with 0 diff --git a/MinecraftClient/Inventory/Item.cs b/MinecraftClient/Inventory/Item.cs index 2048641d..d2dc024b 100644 --- a/MinecraftClient/Inventory/Item.cs +++ b/MinecraftClient/Inventory/Item.cs @@ -5,26 +5,64 @@ using System.Text; namespace MinecraftClient.Inventory { + /// + /// Represents an item inside a Container + /// public class Item { + /// + /// Item Type ID + /// public int ID; + + /// + /// Item Count + /// public int Count; - public int SlotID = -1; // which slot is this item at, -1 = not specified + + /// + /// Slot ID in the parent inventory (-1 means not specified) + /// + public int SlotID = -1; + + /// + /// Item Metadata + /// public Dictionary NBT; - public Item(int ID,int Count,int SlotID, Dictionary NBT) + /// + /// Create an item with Type ID, Count, Slot ID and Metadata + /// + /// Item Type ID + /// Item Count + /// Item Slot ID in parent inventory + /// Item Metadata + public Item(int ID,int Count,int SlotID, Dictionary NBT) { this.ID = ID; this.Count = Count; this.SlotID = SlotID; this.NBT = NBT; } + + /// + /// Create an item with Type ID, Count and Slot ID + /// + /// Item Type ID + /// Item Count + /// Item Slot ID in parent inventory public Item(int ID, int Count, int SlotID) { this.ID = ID; this.Count = Count; this.SlotID = SlotID; } + + /// + /// Create an item with Type ID and Count + /// + /// Item Type ID + /// Item Count public Item(int ID, int Count) { this.ID = ID; diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 0047e205..8ce62b60 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -772,7 +772,13 @@ namespace MinecraftClient { inventories.Add(inventory); } - ConsoleIO.WriteLine(inventory.Type.ToString()); + + if (Settings.DebugMessages) + { + ConsoleIO.WriteLineFormatted("§8An Inventory opened: " + inventory.Type + " - " + inventory.Title); + foreach (var item in inventory.Items) + ConsoleIO.WriteLineFormatted("§8 - Slot " + item.Key + ": " + item.Value.ID + " x" + item.Value.Count); + } } /// @@ -797,12 +803,18 @@ namespace MinecraftClient /// When received window items from server. /// /// Inventory type - /// Item list + /// Item list, key = slot ID, value = Item information public void OnWindowItems(int type, Dictionary itemList) { // 0 is player inventory if (type == 0) playerInventory.Items = itemList; + if (Settings.DebugMessages) + { + ConsoleIO.WriteLineFormatted("§8Received Window of type " + type); + foreach (var item in itemList) + ConsoleIO.WriteLineFormatted("§8 - Slot " + item.Key + ": " + item.Value.ID + " x" + item.Value.Count); + } } /// @@ -1017,10 +1029,7 @@ namespace MinecraftClient /// /// Get a dictionary of online player names and their corresponding UUID /// - /// - /// dictionary of online player whereby - /// UUID represents the key - /// playername represents the value + /// Dictionay of online players, key is UUID, value is Player name public Dictionary GetOnlinePlayersWithUUID() { Dictionary uuid2Player = new Dictionary(); diff --git a/MinecraftClient/MinecraftClient.csproj b/MinecraftClient/MinecraftClient.csproj index ea332a12..8e42aaa1 100644 --- a/MinecraftClient/MinecraftClient.csproj +++ b/MinecraftClient/MinecraftClient.csproj @@ -91,7 +91,7 @@ - + diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 89dbdcdb..0d1ae841 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -504,9 +504,7 @@ namespace MinecraftClient.Protocol.Handlers ContainerTypeOld inventoryType = (ContainerTypeOld)Enum.Parse(typeof(ContainerTypeOld), type); string title = dataTypes.ReadNextString(packetData); byte slots = dataTypes.ReadNextByte(packetData); - Container inventory = new Container(windowID, inventoryType, title); - handler.OnInventoryOpen(inventory); } else @@ -515,7 +513,6 @@ namespace MinecraftClient.Protocol.Handlers int WindowType = dataTypes.ReadNextVarInt(packetData); string title = dataTypes.ReadNextString(packetData); Container inventory = new Container(WindowID, WindowType, title); - handler.OnInventoryOpen(inventory); } } @@ -524,7 +521,6 @@ namespace MinecraftClient.Protocol.Handlers if (handler.GetInventoryEnabled()) { byte windowID = dataTypes.ReadNextByte(packetData); - handler.OnInventoryClose(windowID); } break;