@@ -25,7 +25,7 @@ public sealed class NbtFile {
2525 /// <summary> Root tag of this file. Must be a named CompoundTag. Defaults to an empty-named tag. </summary>
2626 /// <exception cref="ArgumentException"> If given tag is unnamed. </exception>
2727 [ NotNull ]
28- public NbtCompound RootTag {
28+ public NbtTag RootTag {
2929 get { return rootTag ; }
3030 set {
3131 if ( value == null ) throw new ArgumentNullException ( "value" ) ;
@@ -34,8 +34,10 @@ public NbtCompound RootTag {
3434 }
3535 }
3636
37+ public T GetRootTag < T > ( ) where T : NbtTag => RootTag as T ;
38+
3739 [ NotNull ]
38- NbtCompound rootTag ;
40+ NbtTag rootTag ;
3941
4042 /// <summary> Whether new NbtFiles should default to big-endian encoding (default: true). </summary>
4143 public static bool BigEndianByDefault { get ; set ; }
@@ -94,7 +96,7 @@ public NbtFile() {
9496 /// <summary> Creates a new NBT file with the given root tag. </summary>
9597 /// <param name="rootTag"> Compound tag to set as the root tag. May be <c>null</c>. </param>
9698 /// <exception cref="ArgumentException"> If given <paramref name="rootTag"/> is unnamed. </exception>
97- public NbtFile ( [ NotNull ] NbtCompound rootTag )
99+ public NbtFile ( [ NotNull ] NbtTag rootTag )
98100 : this ( ) {
99101 if ( rootTag == null ) throw new ArgumentNullException ( "rootTag" ) ;
100102 RootTag = rootTag ;
@@ -317,7 +319,18 @@ static NbtCompression DetectCompression([NotNull] Stream stream) {
317319 case - 1 :
318320 throw new EndOfStreamException ( ) ;
319321
320- case ( byte ) NbtTagType . Compound : // 0x0A
322+ case ( byte ) NbtTagType . Byte :
323+ case ( byte ) NbtTagType . Short :
324+ case ( byte ) NbtTagType . Int :
325+ case ( byte ) NbtTagType . Long :
326+ case ( byte ) NbtTagType . Float :
327+ case ( byte ) NbtTagType . Double :
328+ case ( byte ) NbtTagType . String :
329+ case ( byte ) NbtTagType . ByteArray :
330+ case ( byte ) NbtTagType . IntArray :
331+ case ( byte ) NbtTagType . LongArray :
332+ case ( byte ) NbtTagType . Compound :
333+ case ( byte ) NbtTagType . List :
321334 compression = NbtCompression . None ;
322335 break ;
323336
@@ -345,16 +358,14 @@ void LoadFromStreamInternal([NotNull] Stream stream, [CanBeNull] TagSelector tag
345358 if ( firstByte < 0 ) {
346359 throw new EndOfStreamException ( ) ;
347360 }
348- if ( firstByte != ( int ) NbtTagType . Compound ) {
349- throw new NbtFormatException ( "Given NBT stream does not start with a TAG_Compound" ) ;
350- }
351361 var reader = new NbtBinaryReader ( stream , BigEndian ) {
352362 Selector = tagSelector
353363 } ;
354364
355- var rootCompound = new NbtCompound ( reader . ReadString ( ) ) ;
356- rootCompound . ReadTag ( reader ) ;
357- RootTag = rootCompound ;
365+ var rootValue = NbtCompound . CreateTag ( ( NbtTagType ) firstByte ) ;
366+ rootValue . Name = reader . ReadString ( ) ;
367+ rootValue . ReadTag ( reader ) ;
368+ RootTag = rootValue ;
358369 }
359370
360371 #endregion
0 commit comments