2022-01-16 22:29:50 +01:00
using Newtonsoft.Json ;
using System.Diagnostics ;
2022-01-18 11:46:23 +01:00
using System.Text ;
2022-01-16 22:29:50 +01:00
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 ; }
2022-01-18 11:46:23 +01:00
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 ( )
} ;
2022-01-16 22:29:50 +01:00
}