Exemple #1
0
        public void Insert(int index, TagBase tag)
        {
            if (tag == null)
            {
                return;
            }

            tag._parent = this;
            _tagList.Insert(index, tag);
        }
Exemple #2
0
 public TagList(TagList original)
     : base(original.Name)
 {
     _listTagType = original.ListType;
     for (int i = 0; i < original.Value.Count; i++)
     {
         TagBase _bs = original.Value[i].Clone();
         _bs._parent = this;
         Add(_bs);
     }
 }
Exemple #3
0
        public static void WriteNamedTag(TagBase tag, NBTBinaryWriter bw)
        {
            byte tagId = (byte)tag.TagType;

            bw.Write(tagId);
            if (tagId != 0)
            {
                bw.Write(tag.Name);
                tag.WriteBinary(bw);
            }
        }
Exemple #4
0
        internal override void ReadBinary(NBTBinaryReader br)
        {
            _tagList.Clear();
            _listTagType = (TagType)br.ReadByte();
            int count = br.ReadInt32();

            _tagList = new List <TagBase>();
            for (int i = 0; i < count; i++)
            {
                TagBase nbt = TagBase.CreateNewTag(_listTagType, null);
                nbt._parent = this;
                nbt.ReadBinary(br);
                _tagList.Add(nbt);
            }
        }
Exemple #5
0
        public static TagBase ReadNamedTag(NBTBinaryReader br)
        {
            byte type = br.ReadByte();

            if (type == 0)
            {
                return(new TagEnd());
            }
            else
            {
                string  n   = br.ReadString();
                TagBase nbt = CreateNewTag((TagType)type, n);
                nbt.ReadBinary(br);
                return(nbt);
            }
        }
Exemple #6
0
        public string GetPath()
        {
            string  result = "";
            TagBase tag    = this;

            while (true)
            {
                if (tag != null && tag._parent != null)
                {
                    result = "/" + tag._parent.Name + result;
                    tag    = tag._parent;
                }
                else
                {
                    break;
                }
            }
            return(result);
        }
Exemple #7
0
        public bool Rename(string newName)
        {
            if (_parent != null)
            {
                TagCompound compound = _parent as TagCompound;

                if (compound != null && !compound.ContainsKey(newName))
                {
                    TagBase tag = this;
                    tag._name = newName;
                    compound.Add(newName, tag);
                    compound.Remove(Name);
                    return(true);
                }

                TagList tagList = _parent as TagList;
                if (tagList != null)
                {
                    _name = newName;
                    return(true);
                }
            }
            return(false);
        }
Exemple #8
0
 public void Remove(TagBase tag)
 {
     _tagList.Remove(tag);
 }
Exemple #9
0
 public void Add(TagBase tag)
 {
     tag._parent = this;
     _tagList.Add(tag);
 }