Inventory handling improvements

Fix click issue for item with NBT
Show custom display names in inventory
See issues #910 #912 #914
This commit is contained in:
ORelio 2020-04-01 22:05:44 +02:00
parent b01c50b792
commit dbe02c063c
4 changed files with 51 additions and 9 deletions

View file

@ -49,5 +49,26 @@ namespace MinecraftClient.Inventory
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;
}
}
}
}