Minecraft-Console-Client/MinecraftClient/Inventory/Item.cs
ReinforceZwei 6bbb7236e3
Add support for Minecraft 1.16.2 (#1214)
* Implement MC version 1.16.2 basic support
All packets ID update done
Tested in 1.16.2 craftbukkit server
* Implement MC 1.16.2 entity handling
New EntityPalette
* Add back protocol version checking for entity handling
Was removed during testing and forgot to add it back
* Implement inventory handling for MC 1.16+
Item ID got changed in 1.16+ so a palette is needed.
* Fix ChangeSlot command
What a joke
* Handle 1.16 new entity properties name
Convert new naming style to old style
* Revert "Handle 1.16 new entity properties name"
This reverts commit 52c7d29062.
* Update AutoAttack to use the new entity properties key
* Fix item type to ID conversion
* Sort item types by name
* Remove ZombiePigmanSpawnEgg
User ZombifiedPiglinSpawnEgg instead (new name for same item)
* Add missing 1.16.2 version strings
* Remove old ItemTypeGenerator
* Sort entity types by name
* Palette loading, instructions, NotImplemented err
Co-authored-by: ORelio <ORelio@users.noreply.github.com>
2020-08-17 17:08:50 +02:00

93 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Inventory
{
/// <summary>
/// Represents an item inside a Container
/// </summary>
public class Item
{
/// <summary>
/// Item Type
/// </summary>
public ItemType Type;
/// <summary>
/// Item Count
/// </summary>
public int Count;
/// <summary>
/// Item Metadata
/// </summary>
public Dictionary<string, object> NBT;
/// <summary>
/// Create an item with ItemType, Count and Metadata
/// </summary>
/// <param name="itemType">Type of the item</param>
/// <param name="count">Item Count</param>
/// <param name="nbt">Item Metadata</param>
public Item(ItemType itemType, int count, Dictionary<string, object> nbt)
{
this.Type = itemType;
this.Count = count;
this.NBT = nbt;
}
/// <summary>
/// Check if the item slot is empty
/// </summary>
/// <returns>TRUE if the item is empty</returns>
public bool IsEmpty
{
get
{
return Type == ItemType.Air || Count == 0;
}
}
/// <summary>
/// Retrieve item display name from NBT properties. NULL if no display name is defined.
/// </summary>
public string DisplayName
{
get
{
if (NBT != null && NBT.ContainsKey("display"))
{
var displayProperties = NBT["display"] as Dictionary<string, object>;
if (displayProperties != null && displayProperties.ContainsKey("Name"))
{
string displayName = displayProperties["Name"] as string;
if (!String.IsNullOrEmpty(displayName))
return MinecraftClient.Protocol.ChatParser.ParseText(displayProperties["Name"].ToString());
}
}
return null;
}
}
/// <summary>
/// Retrieve item damage from NBT properties. Returns 0 if no damage is defined.
/// </summary>
public int Damage
{
get
{
if (NBT != null && NBT.ContainsKey("Damage"))
{
object damage = NBT["Damage"];
if (damage != null)
{
return int.Parse(damage.ToString());
}
}
return 0;
}
}
}
}