readTagForType static method

NbtTag? readTagForType(
  1. NbtReader nbtReader,
  2. int tagType, {
  3. NbtTag? parent,
  4. bool withName = true,
})

Reads the Tag with type tagType. If inside a NbtList or NbtArray, withName should be set to false to avoid reading the name of this Tag.

Implementation

static NbtTag? readTagForType(NbtReader nbtReader, int tagType,
    {NbtTag? parent, bool withName = true}) {
  switch (tagType) {
    case 0x00:
      return NbtEnd(parent as NbtCompound<NbtTag>);
    case 0x01:
      return NbtByte(name: '', value: 0)
          .readTag(nbtReader, withName: withName);
    case 0x02:
      return NbtShort(name: '', value: 0)
          .readTag(nbtReader, withName: withName);
    case 0x03:
      return NbtInt(name: '', value: 0)
          .readTag(nbtReader, withName: withName);
    case 0x04:
      return NbtLong(name: '', value: 0)
          .readTag(nbtReader, withName: withName);
    case 0x05:
      return NbtFloat(name: '', value: 0.0)
          .readTag(nbtReader, withName: withName);
    case 0x06:
      return NbtDouble(name: '', value: 0.0)
          .readTag(nbtReader, withName: withName);
    case 0x07:
      return NbtByteArray(name: '', children: <int>[])
          .readTag(nbtReader, withName: withName);
    case 0x08:
      return NbtString(name: '', value: '')
          .readTag(nbtReader, withName: withName);
    case 0x09:
      return NbtList(name: '', children: <NbtTag>[])
          .readTag(nbtReader, withName: withName);
    case 0x0A:
      return NbtCompound(name: '', children: <NbtTag>[])
          .readTag(nbtReader, withName: withName);
    case 0x0B:
      return NbtIntArray(name: '', children: [])
          .readTag(nbtReader, withName: withName);
    case 0x0C:
      return NbtLongArray(name: '', children: [])
          .readTag(nbtReader, withName: withName);
    default:
      return null;
  }
}