mcdiscordbot/MinecraftDiscordBot/Models/Item.cs
Michael Chen 735bc8e8ae
Bump version to 1.1.2
Cleaner item list display
Allow full item list as file
Fixed online status message with new handler
2022-01-18 11:46:23 +01:00

34 lines
1.3 KiB
C#

using Newtonsoft.Json;
using System.Diagnostics;
using System.Text;
namespace MinecraftDiscordBot.Models;
[JsonObject(MemberSerialization.OptIn, Description = "Describes an item in a Refined Storage system.", MissingMemberHandling = MissingMemberHandling.Ignore)]
[DebuggerDisplay($"{{{nameof(ToString)}(),nq}}")]
public class Item : Fluid {
[JsonProperty("fingerprint", Required = Required.Always)]
public Md5Hash Fingerprint { get; set; } = default!;
[JsonProperty("nbt", Required = Required.DisallowNull)]
public dynamic? NBT { get; set; }
public override string ToString() => $"{AmountString} {CleanDisplayName}";
[JsonIgnore]
public string DetailString {
get {
var sb = new StringBuilder();
sb.AppendFormat("{0} {1}, fp: {2}", AmountString, CleanDisplayName, Fingerprint);
if (TagString is string tags)
sb.AppendFormat(", tags: [{0}]", tags);
if (NBT is not null)
sb.AppendFormat(", NBT: {0}", JsonConvert.SerializeObject(NBT));
return sb.ToString();
}
}
[JsonIgnore]
public string AmountString => Amount switch {
> 1000000 => $"> {Amount / 1000000:n0}m",
> 10000 => $"~ {Amount / 1000.0f:n2}k",
_ => Amount.ToString()
};
}