mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add code documentation for inventories
This commit is contained in:
parent
195e162c7d
commit
6929ae236a
6 changed files with 134 additions and 18 deletions
|
|
@ -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<string, object> localVars)
|
||||
{
|
||||
|
|
@ -5,50 +5,123 @@ using System.Text;
|
|||
|
||||
namespace MinecraftClient.Inventory
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a Minecraft inventory (player inventory, chest, etc.)
|
||||
/// </summary>
|
||||
public class Container
|
||||
{
|
||||
/// <summary>
|
||||
/// ID of the container on the server
|
||||
/// </summary>
|
||||
public int ID;
|
||||
|
||||
/// <summary>
|
||||
/// Type of container
|
||||
/// </summary>
|
||||
public ContainerType Type;
|
||||
|
||||
/// <summary>
|
||||
/// title of container
|
||||
/// </summary>
|
||||
public string Title;
|
||||
|
||||
/// <summary>
|
||||
/// Container Items
|
||||
/// </summary>
|
||||
public Dictionary<int, Item> Items;
|
||||
|
||||
/// <summary>
|
||||
/// Create an empty container
|
||||
/// </summary>
|
||||
public Container() { }
|
||||
|
||||
/// <summary>
|
||||
/// Create an empty container with ID, Type and Title
|
||||
/// </summary>
|
||||
/// <param name="id">Container ID</param>
|
||||
/// <param name="type">Container Type</param>
|
||||
/// <param name="title">Container Title</param>
|
||||
public Container(int id, ContainerType type, string title)
|
||||
{
|
||||
ID = id;
|
||||
Type = type;
|
||||
Title = title;
|
||||
Items = new Dictionary<int, Item>();
|
||||
}
|
||||
public Container(int id, ContainerType type, string title,Dictionary<int,Item> items)
|
||||
|
||||
/// <summary>
|
||||
/// Create a container with ID, Type, Title and Items
|
||||
/// </summary>
|
||||
/// <param name="id">Container ID</param>
|
||||
/// <param name="type">Container Type</param>
|
||||
/// <param name="title">Container Title</param>
|
||||
/// <param name="items">Container Items (key: slot ID, value: item info)</param>
|
||||
public Container(int id, ContainerType type, string title, Dictionary<int, Item> items)
|
||||
{
|
||||
ID = id;
|
||||
Type = type;
|
||||
Title = title;
|
||||
Items = items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an empty container with ID, Type and Title
|
||||
/// </summary>
|
||||
/// <param name="id">Container ID</param>
|
||||
/// <param name="type">Container Type</param>
|
||||
/// <param name="title">Container title</param>
|
||||
public Container(int id, ContainerTypeOld type, string title)
|
||||
{
|
||||
ID = id;
|
||||
Title = title;
|
||||
Type = ConvertType.ToNew(type);
|
||||
Items = new Dictionary<int, Item>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an empty container with ID, Type and Title
|
||||
/// </summary>
|
||||
/// <param name="id">Container ID</param>
|
||||
/// <param name="typeID">Container Type</param>
|
||||
/// <param name="title">Container Title</param>
|
||||
public Container(int id, int typeID, string title)
|
||||
{
|
||||
ID = id;
|
||||
Type = GetContainerType(typeID);
|
||||
Title = title;
|
||||
Items = new Dictionary<int, Item>();
|
||||
}
|
||||
// for player inventory because they dont have ID and title
|
||||
|
||||
/// <summary>
|
||||
/// Create an empty container with Type
|
||||
/// </summary>
|
||||
/// <param name="type">Container Type</param>
|
||||
public Container(ContainerType type)
|
||||
{
|
||||
ID = -1;
|
||||
Type = type;
|
||||
Title = null;
|
||||
Items = new Dictionary<int, Item>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an empty container with T^ype and Items
|
||||
/// </summary>
|
||||
/// <param name="type">Container Type</param>
|
||||
/// <param name="items">Container Items (key: slot ID, value: item info)</param>
|
||||
public Container(ContainerType type, Dictionary<int, Item> items)
|
||||
{
|
||||
ID = -1;
|
||||
Type = type;
|
||||
Title = null;
|
||||
Items = items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get container type from Type ID
|
||||
/// </summary>
|
||||
/// <param name="typeID">Container Type ID</param>
|
||||
/// <returns>Container Type</returns>
|
||||
public static ContainerType GetContainerType(int typeID)
|
||||
{
|
||||
// https://wiki.vg/Inventory didn't state the inventory ID, assume that list start with 0
|
||||
|
|
|
|||
|
|
@ -5,26 +5,64 @@ using System.Text;
|
|||
|
||||
namespace MinecraftClient.Inventory
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an item inside a Container
|
||||
/// </summary>
|
||||
public class Item
|
||||
{
|
||||
/// <summary>
|
||||
/// Item Type ID
|
||||
/// </summary>
|
||||
public int ID;
|
||||
|
||||
/// <summary>
|
||||
/// Item Count
|
||||
/// </summary>
|
||||
public int Count;
|
||||
public int SlotID = -1; // which slot is this item at, -1 = not specified
|
||||
|
||||
/// <summary>
|
||||
/// Slot ID in the parent inventory (-1 means not specified)
|
||||
/// </summary>
|
||||
public int SlotID = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Item Metadata
|
||||
/// </summary>
|
||||
public Dictionary<string, object> NBT;
|
||||
|
||||
public Item(int ID,int Count,int SlotID, Dictionary<string,object> NBT)
|
||||
/// <summary>
|
||||
/// Create an item with Type ID, Count, Slot ID and Metadata
|
||||
/// </summary>
|
||||
/// <param name="ID">Item Type ID</param>
|
||||
/// <param name="Count">Item Count</param>
|
||||
/// <param name="SlotID">Item Slot ID in parent inventory</param>
|
||||
/// <param name="NBT">Item Metadata</param>
|
||||
public Item(int ID,int Count,int SlotID, Dictionary<string, object> NBT)
|
||||
{
|
||||
this.ID = ID;
|
||||
this.Count = Count;
|
||||
this.SlotID = SlotID;
|
||||
this.NBT = NBT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an item with Type ID, Count and Slot ID
|
||||
/// </summary>
|
||||
/// <param name="ID">Item Type ID</param>
|
||||
/// <param name="Count">Item Count</param>
|
||||
/// <param name="SlotID">Item Slot ID in parent inventory</param>
|
||||
public Item(int ID, int Count, int SlotID)
|
||||
{
|
||||
this.ID = ID;
|
||||
this.Count = Count;
|
||||
this.SlotID = SlotID;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an item with Type ID and Count
|
||||
/// </summary>
|
||||
/// <param name="ID">Item Type ID</param>
|
||||
/// <param name="Count">Item Count</param>
|
||||
public Item(int ID, int Count)
|
||||
{
|
||||
this.ID = ID;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -797,12 +803,18 @@ namespace MinecraftClient
|
|||
/// When received window items from server.
|
||||
/// </summary>
|
||||
/// <param name="type">Inventory type</param>
|
||||
/// <param name="itemList">Item list</param>
|
||||
/// <param name="itemList">Item list, key = slot ID, value = Item information</param>
|
||||
public void OnWindowItems(int type, Dictionary<int, Inventory.Item> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -1017,10 +1029,7 @@ namespace MinecraftClient
|
|||
/// <summary>
|
||||
/// Get a dictionary of online player names and their corresponding UUID
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// dictionary of online player whereby
|
||||
/// UUID represents the key
|
||||
/// playername represents the value</returns>
|
||||
/// <returns>Dictionay of online players, key is UUID, value is Player name</returns>
|
||||
public Dictionary<string, string> GetOnlinePlayersWithUUID()
|
||||
{
|
||||
Dictionary<string, string> uuid2Player = new Dictionary<string, string>();
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@
|
|||
<Compile Include="Commands\ChangeSlot.cs" />
|
||||
<Compile Include="Commands\Connect.cs" />
|
||||
<Compile Include="Commands\Debug.cs" />
|
||||
<Compile Include="Commands\GetInventory.cs" />
|
||||
<Compile Include="Commands\Inventory.cs" />
|
||||
<Compile Include="Commands\Look.cs" />
|
||||
<Compile Include="Commands\Move.cs" />
|
||||
<Compile Include="Commands\Exit.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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue