fromJson static method

Item fromJson(
  1. Map<String, dynamic> json
)

creates an Item based on nbt or json data.

Implementation

static Item fromJson(Map<String, dynamic> json) {
  var type = '';
  Slot? slot;
  int? damage;
  Map<String, dynamic>? tag;
  if (json['item'] != null) type = json['item'].toString();
  if (json['id'] != null) type = json['id'].toString();
  if (json['Slot'] != null) {
    slot = Slot(id: int.parse(json['Slot'].toString()));
  }
  if (json['Count'] != null && int.parse(json['Count'].toString()) > 0) {
    int.parse(json['Count'].toString());
  }
  if (json['Damage'] != null && int.parse(json['Damage'].toString()) > 0) {
    damage = int.parse(json['Damage'].toString());
  }

  if (json['tag'] != null) tag = json['tag'] as Map<String, dynamic>;
  return Item(
    type,
    slot: slot,
    damage: damage,
    nbt: tag,
    model: null,
  );
}