internal void ReadTag(NbtReader readStream, bool readName) { // First read the name of this tag if (readName) { Name = readStream.ReadString(); } // read list type, and make sure it's defined ListType = readStream.ReadTagType(); if (!Enum.IsDefined(typeof(NbtTagType), ListType) || ListType == NbtTagType.Unknown) { throw new NbtFormatException("Unrecognized TAG_List tag type: " + ListType); } int length = readStream.ReadInt32(); if (length < 0) { throw new NbtFormatException("Negative count given in TAG_List"); } tags.Clear(); for (int i = 0; i < length; i++) { switch (ListType) { case NbtTagType.Byte: var nextByte = new NbtByte(); nextByte.ReadTag(readStream, false); tags.Add(nextByte); break; case NbtTagType.Short: var nextShort = new NbtShort(); nextShort.ReadTag(readStream, false); tags.Add(nextShort); break; case NbtTagType.Int: var nextInt = new NbtInt(); nextInt.ReadTag(readStream, false); tags.Add(nextInt); break; case NbtTagType.Long: var nextLong = new NbtLong(); nextLong.ReadTag(readStream, false); tags.Add(nextLong); break; case NbtTagType.Float: var nextFloat = new NbtFloat(); nextFloat.ReadTag(readStream, false); tags.Add(nextFloat); break; case NbtTagType.Double: var nextDouble = new NbtDouble(); nextDouble.ReadTag(readStream, false); tags.Add(nextDouble); break; case NbtTagType.ByteArray: var nextByteArray = new NbtByteArray(); nextByteArray.ReadTag(readStream, false); tags.Add(nextByteArray); break; case NbtTagType.String: var nextString = new NbtString(); nextString.ReadTag(readStream, false); tags.Add(nextString); break; case NbtTagType.List: var nextList = new NbtList(); nextList.ReadTag(readStream, false); tags.Add(nextList); break; case NbtTagType.Compound: var nextCompound = new NbtCompound(); nextCompound.ReadTag(readStream, false); tags.Add(nextCompound); break; case NbtTagType.IntArray: var nextIntArray = new NbtIntArray(); nextIntArray.ReadTag(readStream, false); tags.Add(nextIntArray); break; } } }