itemActions method

List<Widget> itemActions()

Implementation

List<Widget> itemActions() {
  return _slots.map((s) {
    var item = gson.encode(
      {
        'Slot': Byte(s.slot!.id!),
        'tag': {
          'objd': {'gui': true},
        },
      },
    );

    Data checkItem;
    var copyFrom;
    var copyFromPath = 'Items';

    switch (container) {
      case GuiContainer.inventory:
        {
          checkItem = Data.get(Entity.Self(), path: 'Inventory[$item]');
          copyFrom = Entity.Self();
          copyFromPath = 'Inventory';
          break;
        }
      case GuiContainer.enderchest:
        {
          checkItem = Data.get(Entity.Self(), path: 'EnderItems[$item]');
          copyFrom = Entity.Self();
          copyFromPath = 'EnderItems';
          break;
        }
      case GuiContainer.minecart:
        {
          checkItem = Data.get(Entity.Self(), path: 'Items[$item]');
          copyFrom = Entity.Self();
          break;
        }

      default:
        {
          checkItem = Data.get(Location.here(), path: 'Items[$item]');
          copyFrom = Location.here();
        }
    }

    // edge case if just one slot is occupied. Check for slot not needed
    if (_slots.length == 1) {
      return For.of(
        buildActionCommands(
          s,
          copyFrom: copyFrom,
          copyFromPath: copyFromPath,
        ),
      );
    }

    return If(
      Condition.not(checkItem),
      then: buildActionCommands(
        s,
        copyFrom: copyFrom,
        copyFromPath: copyFromPath,
      ),
    );
  }).toList();
}