generate method

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

Implementation

@override
Widget generate(Context context) {
  var e = Entity(
      type: Entities.chest_minecart, tags: ['objd_version_check'], limit: 1);

  final s = serverVersion ??
      Score(Entity.PlayerName('server_version'), 'objd_data');

  final items = {
    13: Items.trident,
    14: Items.lectern,
    15: Items.bee_spawn_egg,
    16: Items.hoglin_spawn_egg,
    17: Items.glow_ink_sac,
    18: Items.music_disc_otherside,
  };

  return For.of([
    Summon(
      Entities.chest_minecart,
      tags: ['objd_version_check'],
      location: Location('~ 0 ~'),
      nbt: {
        'Items': items.keys
            .where((v) => v >= (minVersion ?? 0))
            .map((v) => Item(
                  items[v],
                  count: 1,
                  slot: Slot.chest(v - 12),
                  nbt: {
                    'objd': {'update': v}
                  },
                ).getMap())
            .toList(),
      },
    ),

    // check items e1
    for (var i in items.keys.where((v) => v >= (minVersion ?? 0)))
      If(
        e.copyWith(nbt: {
          'Items': [
            {
              'tag': {
                'objd': {'update': i}
              }
            }
          ]
        }),
        then: [
          s >> i,
        ],
      ),

    if (then != null) then!(s),

    if (minVersion != null && versionTooLow != null)
      If(
        Condition.not(s >= minVersion),
        then: versionTooLow!,
      ),

    Data.merge(e, nbt: {'Items': []}),
    Kill(e),
  ]);
}