Ejemplo n.º 1
0
        public override void RemoveAt(int index)
        {
            NbtTag item = this[index];

            item.Parent = null;
            _list.RemoveAt(index);
        }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 protected override void Remove(NbtTag item)
 {
     _list.Remove(item);
     item.Parent = null;
 }
Ejemplo n.º 7
0
 protected override void Remove(NbtTag item)
 {
     _dict.Remove(item.Name);
     item._name  = null;
     item.Parent = null;
 }
Ejemplo n.º 8
0
        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.");
            }
        }
Ejemplo n.º 9
0
        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 + "'.");
            }
        }
Ejemplo n.º 10
0
 public void Write(NbtTag tag)
 {
     Write(tag, true);
 }