using System; using System.Collections.Generic; using System.Linq; 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(); } /// /// 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(); } /// /// 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 switch (typeID) { case 0: return ContainerType.Generic_9x1; case 1: return ContainerType.Generic_9x2; case 2: return ContainerType.Generic_9x3; case 3: return ContainerType.Generic_9x4; case 4: return ContainerType.Generic_9x5; case 5: return ContainerType.Generic_9x6; case 6: return ContainerType.Generic_3x3; case 7: return ContainerType.Anvil; case 8: return ContainerType.Beacon; case 9: return ContainerType.BlastFurnace; case 10: return ContainerType.BrewingStand; case 11: return ContainerType.Crafting; case 12: return ContainerType.Enchantment; case 13: return ContainerType.Furnace; case 14: return ContainerType.Grindstone; case 15: return ContainerType.Hopper; case 16: return ContainerType.Lectern; case 17: return ContainerType.Loom; case 18: return ContainerType.Merchant; case 19: return ContainerType.ShulkerBox; case 20: return ContainerType.Smoker; case 21: return ContainerType.Cartography; case 22: return ContainerType.Stonecutter; default: return ContainerType.Unknown; } } /// /// Search an item in the container /// /// The item to search /// An array of slot ID public int[] SearchItem(ItemType itemType) { List result = new List(); if (Items != null) { foreach (var item in Items) { if (item.Value.Type == itemType) result.Add(item.Key); } } return result.ToArray(); } } }