mcdiscordbot/MinecraftDiscordBot/Models/Item.cs

34 lines
1.3 KiB
C#
Raw Normal View History

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()
};
}