public override void RemoveAt(int index) { NbtTag item = this[index]; item.Parent = null; _list.RemoveAt(index); }
public override NbtTag Insert(int index, NbtTag item) { if (item == null) { throw new ArgumentNullException("item"); } if (item.Parent != null) { item = item.Clone(); } _list.Insert(index, item); item.Parent = this; return(item); }
public override NbtTag Add(NbtTag item) { if (item == null) { throw new ArgumentNullException("item"); } if (item.Parent != null) { item = item.Clone(); } _list.Add(item); item.Parent = this; return(item); }
public void Write(string name, NbtTag tag) { if (name == null) { throw new ArgumentNullException("name"); } if (tag == null) { throw new ArgumentNullException("tag"); } Write((byte)tag.Type); Write(name); Write(tag, false); }
public override NbtTag Add(string key, NbtTag item) { if (key == null) { throw new ArgumentNullException("key"); } if (item == null) { throw new ArgumentNullException("item"); } if (item.Parent != null) { item = item.Clone(); } _dict.Add(key, item); item._name = key; item.Parent = this; return(item); }
protected override void Remove(NbtTag item) { _list.Remove(item); item.Parent = null; }
protected override void Remove(NbtTag item) { _dict.Remove(item.Name); item._name = null; item.Parent = null; }
public NbtTag Read(NbtTagType type) { int length; switch (type) { case NbtTagType.End: return(null); case NbtTagType.Byte: return(NbtTag.Create(_reader.ReadByte())); case NbtTagType.Short: return(NbtTag.Create(_reader.ReadInt16())); case NbtTagType.Int: return(NbtTag.Create(_reader.ReadInt32())); case NbtTagType.Long: return(NbtTag.Create(_reader.ReadInt64())); case NbtTagType.Float: return(NbtTag.Create(_reader.ReadSingle())); case NbtTagType.Double: return(NbtTag.Create(_reader.ReadDouble())); case NbtTagType.ByteArray: length = _reader.ReadInt32(); return(NbtTag.Create(_reader.ReadBytes(length))); case NbtTagType.String: length = _reader.ReadInt16(); byte[] array = _reader.ReadBytes(length); return(NbtTag.Create(Encoding.UTF8.GetString(array))); case NbtTagType.List: NbtTagType listType = (NbtTagType)_reader.ReadByte(); if (listType < NbtTagType.End || listType > NbtTagType.Compound) { throw new FormatException("'" + (int)type + "' is not a valid ListType."); } int count = _reader.ReadInt32(); NbtTag list = NbtTag.CreateList(listType); for (int i = 0; i < count; i++) { list.Add(Read(listType)); } return(list); case NbtTagType.Compound: NbtTag compound = NbtTag.CreateCompound(); while (true) { string name; NbtTag item = Read(out name); if (item == null) { return(compound); } compound.Add(name, item); } case NbtTagType.IntArray: length = _reader.ReadInt32(); int[] intArray = new int[length]; for (int i = 0; i < length; i++) { intArray[i] = _reader.ReadInt32(); } return(NbtTag.Create(intArray)); default: throw new FormatException("'" + (int)type + "' is not a valid TagType."); } }
void Write(NbtTag tag, bool writeType) { if (tag == null) { throw new ArgumentNullException("tag"); } if (writeType) { Write((byte)tag.Type); } switch (tag.Type) { case NbtTagType.Byte: Write((byte)tag.Value); break; case NbtTagType.Short: Write((short)tag.Value); break; case NbtTagType.Int: Write((int)tag.Value); break; case NbtTagType.Long: Write((long)tag.Value); break; case NbtTagType.Float: Write((float)tag.Value); break; case NbtTagType.Double: Write((double)tag.Value); break; case NbtTagType.ByteArray: Write((byte[])tag.Value); break; case NbtTagType.String: Write((string)tag.Value); break; case NbtTagType.List: Write((byte)tag.ListType); Write(tag.Count); foreach (NbtTag item in tag) { Write(item, false); } break; case NbtTagType.Compound: foreach (NbtTag item in tag) { Write(item.Name, item); } Write((byte)NbtTagType.End); break; case NbtTagType.IntArray: Write((int[])tag.Value); break; default: throw new FormatException("Unknown TagType '" + (int)tag.Type + "'."); } }
public void Write(NbtTag tag) { Write(tag, true); }