generate method

  1. @override
Widget generate(
  1. Context context
)
override

Implementation

@override
Widget generate(Context context) {
  if (slot.slot == null) {
    throw ('The Slot for a ReplaceItem needs a slot property!');
  }

  if (context.version < 17) return _pre117();

  var cmd = ['item'];

  cmd.add(_type == _ReplaceItemType.modify ? 'modify' : 'replace');

  cmd.add(entity != null ? 'entity $entity' : 'block $loc');

  cmd.add(slot.slot!);

  if (_type == _ReplaceItemType.replace && item != null) {
    cmd.add('with');
    cmd.add(item!.getGiveNotation());
  }

  if (_type == _ReplaceItemType.from && fromSlot != null) {
    cmd.add(
      fromEntity != null ? 'from entity $fromEntity' : 'from block $fromLoc',
    );
    cmd.add(fromSlot!.slot!);
  }

  if (modifier != null) {
    cmd.add(modifier!);
  }

  return Command(cmd.join(' '));
}