mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Inventory handling
This commit is contained in:
parent
c870f080f2
commit
bc449b404e
20 changed files with 538 additions and 44 deletions
83
MinecraftClient/Inventory/Container.cs
Normal file
83
MinecraftClient/Inventory/Container.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MinecraftClient.Inventory
|
||||
{
|
||||
public class Container
|
||||
{
|
||||
public int ID;
|
||||
public ContainerType Type;
|
||||
public string Title;
|
||||
public Dictionary<int, Item> Items;
|
||||
|
||||
public Container() { }
|
||||
public Container(int id, ContainerType type, string title)
|
||||
{
|
||||
ID = id;
|
||||
Type = type;
|
||||
Title = title;
|
||||
}
|
||||
public Container(int id, ContainerType type, string title,Dictionary<int,Item> items)
|
||||
{
|
||||
ID = id;
|
||||
Type = type;
|
||||
Title = title;
|
||||
Items = items;
|
||||
}
|
||||
public Container(int id, Protocol.InventoryType type, string title)
|
||||
{
|
||||
ID = id;
|
||||
Title = title;
|
||||
}
|
||||
public Container(int id, int typeID, string title)
|
||||
{
|
||||
ID = id;
|
||||
Type = GetContainerType(typeID);
|
||||
Title = title;
|
||||
}
|
||||
// for player inventory because they dont have ID and title
|
||||
public Container(ContainerType type)
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
public Container(ContainerType type, Dictionary<int, Item> items)
|
||||
{
|
||||
Type = type;
|
||||
Items = items;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
MinecraftClient/Inventory/ContainerType.cs
Normal file
38
MinecraftClient/Inventory/ContainerType.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MinecraftClient.Inventory
|
||||
{
|
||||
// For MC 1.14 after ONLY
|
||||
public enum ContainerType
|
||||
{
|
||||
Generic_9x1,
|
||||
Generic_9x2,
|
||||
Generic_9x3, // chest, ender chest, minecart with chest, barrel
|
||||
Generic_9x4,
|
||||
Generic_9x5,
|
||||
Generic_9x6,
|
||||
Generic_3x3,
|
||||
Anvil,
|
||||
Beacon,
|
||||
BlastFurnace,
|
||||
BrewingStand,
|
||||
Crafting,
|
||||
Enchantment,
|
||||
Furnace,
|
||||
Grindstone,
|
||||
Hopper,
|
||||
Lectern,
|
||||
Loom,
|
||||
Merchant,
|
||||
ShulkerBox,
|
||||
Smoker,
|
||||
Cartography,
|
||||
Stonecutter,
|
||||
// not in the list
|
||||
PlayerInventory,
|
||||
Unknown
|
||||
}
|
||||
}
|
||||
34
MinecraftClient/Inventory/Item.cs
Normal file
34
MinecraftClient/Inventory/Item.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MinecraftClient.Inventory
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
public int ID;
|
||||
public int Count;
|
||||
public int SlotID = -1; // which slot is this item at, -1 = not specified
|
||||
public Dictionary<string, object> NBT;
|
||||
|
||||
public Item(int ID,int Count,int SlotID, Dictionary<string,object> NBT)
|
||||
{
|
||||
this.ID = ID;
|
||||
this.Count = Count;
|
||||
this.SlotID = SlotID;
|
||||
this.NBT = NBT;
|
||||
}
|
||||
public Item(int ID, int Count, int SlotID)
|
||||
{
|
||||
this.ID = ID;
|
||||
this.Count = Count;
|
||||
this.SlotID = SlotID;
|
||||
}
|
||||
public Item(int ID, int Count)
|
||||
{
|
||||
this.ID = ID;
|
||||
this.Count = Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue