2020-03-26 15:01:42 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Inventory
|
|
|
|
|
|
{
|
2020-03-28 15:01:08 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents an item inside a Container
|
|
|
|
|
|
/// </summary>
|
2020-03-26 15:01:42 +08:00
|
|
|
|
public class Item
|
|
|
|
|
|
{
|
2020-03-28 15:01:08 +01:00
|
|
|
|
/// <summary>
|
2020-03-28 23:30:17 +01:00
|
|
|
|
/// Item Type
|
2020-03-28 15:01:08 +01:00
|
|
|
|
/// </summary>
|
2020-03-28 23:30:17 +01:00
|
|
|
|
public ItemType Type;
|
2020-03-28 15:01:08 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Item Count
|
|
|
|
|
|
/// </summary>
|
2020-03-26 15:01:42 +08:00
|
|
|
|
public int Count;
|
2020-03-28 15:01:08 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Item Metadata
|
|
|
|
|
|
/// </summary>
|
2020-03-26 15:01:42 +08:00
|
|
|
|
public Dictionary<string, object> NBT;
|
|
|
|
|
|
|
2020-03-28 15:01:08 +01:00
|
|
|
|
/// <summary>
|
2020-03-29 18:41:26 +02:00
|
|
|
|
/// Create an item with Type ID, Count and Metadata
|
2020-03-28 15:01:08 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="ID">Item Type ID</param>
|
|
|
|
|
|
/// <param name="Count">Item Count</param>
|
2020-03-29 18:41:26 +02:00
|
|
|
|
/// <param name="NBT">Item Metadata</param>
|
|
|
|
|
|
public Item(int id, int count, Dictionary<string, object> nbt)
|
2020-03-26 15:01:42 +08:00
|
|
|
|
{
|
2020-03-28 23:30:17 +01:00
|
|
|
|
this.Type = (ItemType)id;
|
2020-03-28 17:56:17 +01:00
|
|
|
|
this.Count = count;
|
2020-03-29 18:41:26 +02:00
|
|
|
|
this.NBT = nbt;
|
2020-03-26 15:01:42 +08:00
|
|
|
|
}
|
2020-03-28 15:01:08 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-03-29 18:41:26 +02:00
|
|
|
|
/// Check if the item slot is empty
|
2020-03-28 15:01:08 +01:00
|
|
|
|
/// </summary>
|
2020-03-29 18:41:26 +02:00
|
|
|
|
/// <returns>TRUE if the item is empty</returns>
|
|
|
|
|
|
public bool IsEmpty
|
2020-03-26 15:01:42 +08:00
|
|
|
|
{
|
2020-03-29 18:41:26 +02:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return Type == ItemType.Air || Count == 0;
|
|
|
|
|
|
}
|
2020-03-26 15:01:42 +08:00
|
|
|
|
}
|
2020-04-01 22:05:44 +02:00
|
|
|
|
|
|
|
|
|
|
/// <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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-04-08 00:28:03 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Check item is a food
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>True if is a food</returns>
|
|
|
|
|
|
public bool IsFood()
|
|
|
|
|
|
{
|
|
|
|
|
|
// non-poison and stackable food
|
|
|
|
|
|
// remarks: auto eat may works with non-stackable food <- not tested
|
|
|
|
|
|
int[] foods = { 524, 765, 821, 823, 562, 763, 680, 629, 801, 585, 788, 630, 670, 674, 588, 587, 768, 673, 764, 777, 677, 679, 625, 800, 584, 787, 626, 678, 876, 627 };
|
|
|
|
|
|
if (foods.Contains((int)Type))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-03-26 15:01:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|