Added item lore/description to be displayed in the list of items in the inventory

This commit is contained in:
Anon 2023-04-30 15:18:33 +02:00
parent 3570ef605e
commit df6eeb9b4a

View file

@ -46,10 +46,7 @@ namespace MinecraftClient.Inventory
/// <returns>TRUE if the item is empty</returns>
public bool IsEmpty
{
get
{
return Type == ItemType.Air || Count == 0;
}
get { return Type == ItemType.Air || Count == 0; }
}
/// <summary>
@ -61,13 +58,15 @@ namespace MinecraftClient.Inventory
{
if (NBT != null && NBT.ContainsKey("display"))
{
if (NBT["display"] is Dictionary<string, object> displayProperties && displayProperties.ContainsKey("Name"))
if (NBT["display"] is Dictionary<string, object> displayProperties &&
displayProperties.ContainsKey("Name"))
{
string? displayName = displayProperties["Name"] as string;
if (!String.IsNullOrEmpty(displayName))
return ChatParser.ParseText(displayProperties["Name"].ToString() ?? string.Empty);
}
}
return null;
}
}
@ -82,7 +81,8 @@ namespace MinecraftClient.Inventory
List<string> lores = new();
if (NBT != null && NBT.ContainsKey("display"))
{
if (NBT["display"] is Dictionary<string, object> displayProperties && displayProperties.ContainsKey("Lore"))
if (NBT["display"] is Dictionary<string, object> displayProperties &&
displayProperties.ContainsKey("Lore"))
{
object[] displayName = (object[])displayProperties["Lore"];
lores.AddRange(from string st in displayName
@ -91,6 +91,7 @@ namespace MinecraftClient.Inventory
return lores.ToArray();
}
}
return null;
}
}
@ -107,9 +108,11 @@ namespace MinecraftClient.Inventory
object damage = NBT["Damage"];
if (damage != null)
{
return int.Parse(damage.ToString() ?? string.Empty, NumberStyles.Any, CultureInfo.CurrentCulture);
return int.Parse(damage.ToString() ?? string.Empty, NumberStyles.Any,
CultureInfo.CurrentCulture);
}
}
return 0;
}
}
@ -139,7 +142,8 @@ namespace MinecraftClient.Inventory
try
{
if (NBT != null && (NBT.TryGetValue("Enchantments", out object? enchantments) || NBT.TryGetValue("StoredEnchantments", out enchantments)))
if (NBT != null && (NBT.TryGetValue("Enchantments", out object? enchantments) ||
NBT.TryGetValue("StoredEnchantments", out enchantments)))
{
foreach (Dictionary<string, object> enchantment in (object[])enchantments)
{
@ -150,8 +154,16 @@ namespace MinecraftClient.Inventory
ChatParser.TranslateString("enchantment.level." + level) ?? level.ToString());
}
}
if (Lores != null && Lores.Length > 0)
{
foreach (var lore in Lores)
sb.AppendFormat(" | {0}", lore);
}
}
catch (Exception)
{
}
catch (Exception) { }
return sb.ToString();
}