diff --git a/MinecraftClient/Commands/Inventory.cs b/MinecraftClient/Commands/Inventory.cs index b44b3352..2f2bdd59 100644 --- a/MinecraftClient/Commands/Inventory.cs +++ b/MinecraftClient/Commands/Inventory.cs @@ -78,29 +78,23 @@ namespace MinecraftClient.Commands else return Translations.Get("cmd.inventory.close_fail", inventoryId); case "list": Container inventory = handler.GetInventory(inventoryId); - if(inventory==null) + if (inventory == null) return Translations.Get("cmd.inventory.not_exist", inventoryId); + SortedDictionary itemsSorted = new SortedDictionary(inventory.Items); List response = new List(); response.Add(Translations.Get("cmd.inventory.inventory") + " #" + inventoryId + " - " + inventory.Title + "§8"); - foreach (KeyValuePair item in inventory.Items) + int selectedHotbar = handler.GetCurrentSlot() + 1; + foreach (KeyValuePair item in itemsSorted) { - string displayName = item.Value.DisplayName; - if (String.IsNullOrEmpty(displayName)) - { - if (item.Value.Damage != 0) - response.Add(String.Format(" #{0}: {1} x{2} | {3}: {4}", item.Key, item.Value.Type, item.Value.Count, Translations.Get("cmd.inventory.damage"), item.Value.Damage)); - else - response.Add(String.Format(" #{0}: {1} x{2}", item.Key, item.Value.Type, item.Value.Count)); - } - else - { - if (item.Value.Damage != 0) - response.Add(String.Format(" #{0}: {1} x{2} - {3}§8 | {4}: {5}", item.Key, item.Value.Type, item.Value.Count, displayName, Translations.Get("cmd.inventory.damage"), item.Value.Damage)); - else - response.Add(String.Format(" #{0}: {1} x{2} - {3}§8", item.Key, item.Value.Type, item.Value.Count, displayName)); - } + int hotbar; + bool isHotbar = inventory.IsHotbar(item.Key, out hotbar); + string hotbarString = isHotbar ? (hotbar + 1).ToString() : " "; + if ((hotbar + 1) == selectedHotbar) + hotbarString = ">" + hotbarString; + response.Add(String.Format("{0,2} | #{1,-2}: {2}", hotbarString, item.Key, item.Value.ToString())); } - if (inventoryId == 0) response.Add(Translations.Get("cmd.inventory.hotbar", (handler.GetCurrentSlot() + 1))); + if (inventoryId == 0) + response.Add(Translations.Get("cmd.inventory.hotbar", (handler.GetCurrentSlot() + 1))); return String.Join("\n", response.ToArray()); case "click": if (args.Length >= 3) diff --git a/MinecraftClient/Inventory/Container.cs b/MinecraftClient/Inventory/Container.cs index 7b942753..85f3e9a8 100644 --- a/MinecraftClient/Inventory/Container.cs +++ b/MinecraftClient/Inventory/Container.cs @@ -191,5 +191,29 @@ namespace MinecraftClient.Inventory } return result.ToArray(); } + + /// + /// Check the given slot ID is a hotbar slot and give the hotbar number + /// + /// The slot ID to check + /// Zero-based, 0-8. -1 if not a hotbar + /// True if given slot ID is a hotbar slot + public bool IsHotbar(int slotId, out int hotbar) + { + int hotbarStart = Type.SlotCount() - 9; + // Remove offhand slot + if (Type == ContainerType.PlayerInventory) + hotbarStart--; + if ((slotId >= hotbarStart) && (slotId <= hotbarStart + 9)) + { + hotbar = slotId - hotbarStart; + return true; + } + else + { + hotbar = -1; + return false; + } + } } } diff --git a/MinecraftClient/Inventory/ContainerTypeExtensions.cs b/MinecraftClient/Inventory/ContainerTypeExtensions.cs index 95f84e64..a93936c0 100644 --- a/MinecraftClient/Inventory/ContainerTypeExtensions.cs +++ b/MinecraftClient/Inventory/ContainerTypeExtensions.cs @@ -7,30 +7,35 @@ namespace MinecraftClient.Inventory { public static class ContainerTypeExtensions { + /// + /// Get the slot count of the container + /// + /// + /// Slot count of the container public static int SlotCount(this ContainerType c) { switch (c) { - case ContainerType.PlayerInventory: return 44; - case ContainerType.Generic_9x3: return 62; - case ContainerType.Generic_9x6: return 89; - case ContainerType.Generic_3x3: return 44; - case ContainerType.Crafting: return 45; - case ContainerType.BlastFurnace: return 38; - case ContainerType.Furnace: return 38; - case ContainerType.Smoker: return 38; - case ContainerType.Enchantment: return 37; - case ContainerType.BrewingStand: return 40; - case ContainerType.Merchant: return 38; - case ContainerType.Beacon: return 36; - case ContainerType.Anvil: return 38; - case ContainerType.Hopper: return 40; - case ContainerType.ShulkerBox: return 62; - case ContainerType.Loom: return 39; - case ContainerType.Stonecutter: return 37; - case ContainerType.Lectern: return 36; - case ContainerType.Cartography: return 38; - case ContainerType.Grindstone: return 38; + case ContainerType.PlayerInventory: return 46; + case ContainerType.Generic_9x3: return 63; + case ContainerType.Generic_9x6: return 90; + case ContainerType.Generic_3x3: return 45; + case ContainerType.Crafting: return 46; + case ContainerType.BlastFurnace: return 39; + case ContainerType.Furnace: return 39; + case ContainerType.Smoker: return 39; + case ContainerType.Enchantment: return 38; + case ContainerType.BrewingStand: return 41; + case ContainerType.Merchant: return 39; + case ContainerType.Beacon: return 37; + case ContainerType.Anvil: return 39; + case ContainerType.Hopper: return 41; + case ContainerType.ShulkerBox: return 63; + case ContainerType.Loom: return 40; + case ContainerType.Stonecutter: return 38; + case ContainerType.Lectern: return 37; + case ContainerType.Cartography: return 39; + case ContainerType.Grindstone: return 39; case ContainerType.Unknown: return 0; default: return 0; } diff --git a/MinecraftClient/Inventory/Item.cs b/MinecraftClient/Inventory/Item.cs index 14e899f1..94f576bf 100644 --- a/MinecraftClient/Inventory/Item.cs +++ b/MinecraftClient/Inventory/Item.cs @@ -115,5 +115,22 @@ namespace MinecraftClient.Inventory return 0; } } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.AppendFormat("x{0,-2} {1}", Count, Type.ToString()); + string displayName = DisplayName; + if (!String.IsNullOrEmpty(displayName)) + { + sb.AppendFormat(" - {0}§8", displayName); + } + int damage = Damage; + if (damage != 0) + { + sb.AppendFormat(" | {0}: {1}", Translations.Get("cmd.inventory.damage"), damage); + } + return sb.ToString(); + } } }