/*
 * Adding veins
 * event.recipes.createoreexcavation.vein(name: Component, itemId: String)
 *   .placement(spacing: int, separation: int, salt: int)
 *   .id(id: String)
 *     Optionals: .alwaysFinite(), .veinSize(minBaseMultiplier: float, maxBaseMultiplier: float), .priority(priority: int), .biomeWhitelist(tag: String), .biomeBlacklist(tag: String)
 *
 * e.g. event.recipes.createoreexcavation.vein('{"text": "My redstone vein"}', 'minecraft:redstone')
 *        .placement(1024, 128, 64825185)
 *        .id("kubejs:my_redstone_vein")
 *
 * Item drilling
 * event.recipes.createoreexcavation.drilling(outputItemId: String, veinId: String, extractionTimeInTicksAt32RPM: int)
 *   .id(id: String)
 * event.recipes.createoreexcavation.drilling(outputItems: List[Item], veinId: String, extractionTimeInTicksAt32RPM: int)
 *   .id(id: String)
 * Optionals: .fluid(fluidId: String), .stress(stressRequirement: int), .priority(priority: int), .stress(xRPM: int)
 *
 * e.g. event.recipes.createoreexcavation.drilling(
 *        [
 *          Item.of('minecraft:coal_block'),
 *          Item.of('minecraft:diamond').withChance(0.05)
 *        ], 'kubejs:my_coal_vein', 500)
 *        .drill('createoreexcavation:diamond_drill').fluid('minecraft:lava').priority(1)
 *        .id("kubejs:my_coal2");
 *
 * Fluid drilling
 * event.recipes.createoreexcavation.extracting()
 *
 * !!! IMPORTANT !!!
 * Add any new drill items to #createoreexcavation:drills item tag
 * Place a drill texture under assets/<item mod id>/textures/entity/drill/<item name>.png
 * See assets/createoreexcavation/textures/entity/drill/drill.png
 */

ServerEvents.tags('item', event => {
  event.add('createoreexcavation:diamond_tier_drills', [
      'createoreexcavation:diamond_drill',
      'createoreexcavation:netherite_drill',
  ])
});

ServerEvents.recipes(event => {
  // Remove fluid extracting
  event.remove({ type: 'createoreexcavation:extracting' });
  event.remove({ id: 'createoreexcavation:ore_vein_type/water' });

  // Remove veins and drilling recipes for resources found in molten vents
  let removeDrilling = (id) => {
    event.remove({ id: 'createoreexcavation:drilling/' + id });
    event.remove({ id: 'createoreexcavation:ore_vein_type/' + id });
  };
  removeDrilling('zinc'); // asurine
  removeDrilling('copper'); // veridium
  removeDrilling('iron'); // crimsite
  removeDrilling('gold'); // ochrum
  removeDrilling('nether_gold'); // ochrum

  // Add new veins
  let drillRecipe = (id, itemId, name, spacing, separation, salt, extractionTimeInTicksAt32RPM, biomeWhitelist, drill, stress, fluid) => {
      let vein = event.recipes.createoreexcavation.vein(name, itemId)
          .placement(spacing, separation, salt)
      if (biomeWhitelist) {
          vein.biomeWhitelist(biomeWhitelist)
      }
      vein.id('createoreexcavation:ore_vein_type/' + id)

      let drilling = event.recipes.createoreexcavation.drilling(itemId, 'createoreexcavation:ore_vein_type/' + id, extractionTimeInTicksAt32RPM)
      if (drill) {
          drilling.drill(drill)
      }
      if (stress) {
          drilling.stress(stress)
      }
      if (fluid) {
          drilling.fluid(fluid)
      }
      drilling.id('createoreexcavation:drilling/' + id)
  };

  drillRecipe('cobalt', 'tconstruct:raw_cobalt', 'Raw Cobalt', 256, 64, 2032237643, 2000, 'minecraft:is_nether', '#createoreexcavation:diamond_tier_drills', 512, 'minecraft:lava 1000')
  drillRecipe('wolframite', 'createmetallurgy:raw_wolframite', 'Raw Wolframite', 128, 12, 316754112, 200, 'minecraft:is_nether', '#createoreexcavation:diamond_tier_drills', 64, null)
  drillRecipe('titanium', 'create_tank_defenses:raw_titanium', 'Raw Titanium', 196, 12, 765235842, 400, 'minecraft:is_overworld', null, 128, null)
  drillRecipe('aluminum', 'create_tank_defenses:raw_aluminum', 'Raw Aluminum', 196, 12, 546372856, 200, 'minecraft:is_overworld', null, 128, null)
  drillRecipe('amethyst', 'minecraft:amethyst_shard', 'Amethyst Shard', 128, 8, 563278368, 200, 'minecraft:is_overworld', null, 64, null)
  drillRecipe('lithium', 'tfmg:raw_lithium', 'Raw Lithium', 196, 12, 546372856, 400, 'minecraft:is_overworld', null, 128, null)
});