Exemple #1
0
 private void ReadTagValue(NBTTag tag)
 {
     switch(tag.Type) {
     case NBTTag.TagType.Byte:
         tag.Byte = ReadByte();
         break;
     case NBTTag.TagType.Short:
         tag.Short = ReadInt16();
         break;
     case NBTTag.TagType.Int:
         tag.Int = ReadInt32();
         break;
     case NBTTag.TagType.Long:
         tag.Long = ReadInt64();
         break;
     case NBTTag.TagType.Float:
         tag.Float = ReadSingle();
         break;
     case NBTTag.TagType.Double:
         tag.Double = ReadDouble();
         break;
     case NBTTag.TagType.ByteArray:
         tag.ByteArray = ReadBytes(ReadInt32());
         break;
     case NBTTag.TagType.String:
         tag.String = new String(ReadChars(ReadInt16()));
         break;
     case NBTTag.TagType.List:
         NBTTag.TagType tagType = (NBTTag.TagType)ReadByte ();
         Int32 length = ReadInt32();
         tag.List = new NBTTag[length];
         for(int j = 0; j < length; j++) {
             tag.List[j] = ReadTag(tagType, false);
         }
         break;
     case NBTTag.TagType.Compound:
         bool endTagFound = false;
         while(!endTagFound)
         {
             NBTTag _tag = ReadTag();
             if(_tag.Type != NBTTag.TagType.End) {
                 tag.Compound[_tag.Name] = _tag;
             }else{
                 endTagFound = true;
             }
         }
         break;
     case NBTTag.TagType.IntArray:
         throw new NotImplementedException(NBTTag.TagType.IntArray.ToString());
         //break;
     }
 }
Exemple #2
0
        public NBTTag ReadTag(NBTTag.TagType type = NBTTag.TagType.Unknown, bool named = true)
        {
            NBTTag tag = new NBTTag (type);
            if (type == NBTTag.TagType.Unknown) {
                tag.Type = (NBTTag.TagType)ReadByte ();
            }

            if (tag.Type != NBTTag.TagType.End) {
                if(named) {
                    Int16 nameLength = ReadInt16();
                    tag.Name = new String(ReadChars(nameLength));
                }
            #if DEBUG
                Console.WriteLine((named ? tag.Name : "Unnamed") + ": " + tag.Type);
            #endif
                ReadTagValue(tag);
            }

            return tag;
        }