PlayerEvents.tick((event) => {
  const { player } = event;

  // Fires event once a second
  if (!(player.age % 20 === 0)) return;
  if (player.chestArmorItem?.nbt?.Beelytra) {
    // Apply Royal Jelly potion effects
    let potion = event.player.potionEffects;
    potion.add("the_bumblezone:beenergized", 200, 2, false, false);
    potion.add("minecraft:jump_boost", 200, 3, false, false);
    potion.add("minecraft:slow_falling", 200, 0, false, false);
    potion.add("minecraft:speed", 200, 1, false, false);
  }
});

ServerEvents.recipes((event) => {
  let beeChestplateTypes = [
    "the_bumblezone:bumble_bee_chestplate_1",
    "the_bumblezone:bumble_bee_chestplate_2",
    "the_bumblezone:bumble_bee_chestplate_trans_1",
    "the_bumblezone:bumble_bee_chestplate_trans_2",
  ];

  beeChestplateTypes.forEach((chest) => {
    event.recipes.kubejs
      .shapeless(`${chest} {Beelytra:"1b"}`, [
        "the_bumblezone:royal_jelly_bottle",
        `${chest}`,
        "the_bumblezone:windy_air",
      ])
      .modifyResult((grid, result) => {
        let chestplate = grid.find(`${chest}`);
        result.nbt.merge(chestplate?.nbt);
        return result;
      });
  });

  // Essence of Bees
  event.recipes.create
    .mixing("the_bumblezone:essence_of_the_bees", [
      Fluid.of("the_bumblezone:royal_jelly_fluid_still", 1000),
      "rats:plague_essence",
      "starmetal:star_fragment",
    ])
    .superheated()
    .id("the_bumblezone:essence_of_the_bees");
});
