using System; using LibAC.NBT.API; namespace LibAC.NBT { public class IntTag : Tag { public int Value { get; private set; } = 0; public IntTag() { } private IntTag(int value) { this.Value = value; } public static IntTag ValueOf(int value) { return new IntTag(value); } public override void ReadValue(ByteLayer data) { Value = data.ReadInt(); } public override void WriteValue(ByteLayer data) { data.WriteInt(Value); } public override TagType GetTagType() { return TagType.Int; } public override void SetValue(dynamic val) { if (val is int) Value = val; } public override dynamic GetValue() { return Value; } public override void PrettyPrint(int indent, bool recurse) { Console.WriteLine($"{new string('\t', indent)}{Tag.GetCanonicalName(GetTagType())}: {Value}"); } public override void WriteStringifiedValue(StringBuilder builder, int indent, bool isList) { builder.Append($"{(isList ? new string('\t', indent) : "")}{Value}i"); } public override void ReadStringifiedValue(StringReader reader) { string val = reader.ReadNumber(); Value = int.Parse(val); // Since a type indicator is optional for an int, check for a comma if (reader.Peek() == ',') return; else reader.Expect('i'); } } }