BlockEvents.rightClicked("kubejs:pokemon_gamba_package", function (e) {
  let { player, block, level, server } = e;

  if (level.isClientSide()) return;
  if (!player.isCrouching()) return;
  if (!player.mainHandItem.isEmpty()) return;

  global.CarePackageFX.pokemon({
    server: server,
    player: player,
    block: block,
  });

  let x = block.pos.x + 0.5;
  let y = block.pos.y;
  let z = block.pos.z + 0.5;

  let lvl = randInt(10, 50);
  server.runCommandSilent(
    'execute as @a[name="' +
      player.username +
      '"] positioned ' +
      x +
      " " +
      y +
      " " +
      z +
      " run pokespawn random level=" +
      lvl
  );

  block.set("minecraft:air");
});

function randInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
