readTag method

  1. @override
NbtCompound<NbtTag> readTag(
  1. NbtReader nbtReader, {
  2. bool withName = true,
})
override

Reads a NbtTag from fileReader. If the parent is a NbtList or NbtArray, withName should be set to false to avoid reading the name of this Tag.

Implementation

@override
NbtCompound readTag(NbtReader nbtReader, {bool withName = true}) {
  final name = withName ? nbtReader.readString() : 'None';
  var tag =
      NbtTag.readTagForType(nbtReader, nbtReader.readByte(), parent: this);

  while (tag != null && tag.nbtTagType != NbtTagType.TAG_END) {
    if (tag is T) add(tag);
    tag =
        NbtTag.readTagForType(nbtReader, nbtReader.readByte(), parent: this);
  }
  return this..name = name;
}