mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Added item lore/description to display name in the inventory
Added item lore/description to display name in the inventory
This commit is contained in:
commit
f94c1ed60d
1 changed files with 26 additions and 14 deletions
|
|
@ -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,15 +81,17 @@ 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
|
||||
let str = ChatParser.ParseText(st.ToString())
|
||||
select str);
|
||||
let str = ChatParser.ParseText(st.ToString())
|
||||
select str);
|
||||
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,19 +142,28 @@ 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)
|
||||
{
|
||||
short level = (short)enchantment["lvl"];
|
||||
string id = ((string)enchantment["id"]).Replace(':', '.');
|
||||
sb.AppendFormat(" | {0} {1}",
|
||||
ChatParser.TranslateString("enchantment." + id) ?? id,
|
||||
ChatParser.TranslateString("enchantment.level." + level) ?? level.ToString());
|
||||
ChatParser.TranslateString("enchantment." + id) ?? id,
|
||||
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();
|
||||
}
|
||||
|
|
@ -173,4 +185,4 @@ namespace MinecraftClient.Inventory
|
|||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue