// Visit the wiki for more info - https://kubejs.com/
console.info('Hello, World! (Loaded server example script)')

ServerEvents.recipes(event =>{
  // Helper Function

  const essence_tier_1 = "mysticalagriculture:inferium_essence"
  const essence_tier_2 = "mysticalagriculture:prudentium_essence"
  const essence_tier_3 = "mysticalagriculture:tertium_essence"
  const essence_tier_4 = "mysticalagriculture:imperium_essence"
  const essence_tier_5 = "mysticalagriculture:supremium_essence"
  const essence_tier_6 = "mysticalagradditions:insanium_essence"

  const farmland_tier_1 = "mysticalagriculture:inferium_farmland"
  const farmland_tier_2 = "mysticalagriculture:prudentium_farmland"
  const farmland_tier_3 = "mysticalagriculture:tertium_farmland"
  const farmland_tier_4 = "mysticalagriculture:imperium_farmland"
  const farmland_tier_5 = "mysticalagriculture:supremium_farmland"
  const farmland_tier_6 = "mysticalagradditions:insanium_farmland"

  function infusion_resource(essence, material, output) {
    event.custom({
      'type': 'mysticalagriculture:infusion',
      'input': {
        'item': 'mysticalagriculture:prosperity_seed_base'
      },
      'ingredients': [
        { "tag": material },
        { "item": essence },
        { "tag": material },
        { "item": essence },
        { "tag": material },
        { "item": essence },
        { "tag": material },
        { "item": essence },
      ],
      'result': {
        'id': output
      }  
    })
  }

  infusion_resource(essence_tier_2, 'c:dusts/sulfur', 'mysticalagriculture:sulfur_seeds')
  infusion_resource(essence_tier_4, 'c:ingots/osmium', 'mysticalagriculture:osmium_seeds')
  infusion_resource(essence_tier_4, 'c:ingots/steel', 'mysticalagriculture:steel_seeds')
  infusion_resource(essence_tier_5, 'c:ingots/iridium', 'mysticalagriculture:iridium_seeds')
  infusion_resource(essence_tier_5, 'c:ingots/platinum', 'mysticalagriculture:platinum_seeds')
  infusion_resource(essence_tier_4, 'c:gems/fluorite', 'mysticalagriculture:fluorite_seeds')
  infusion_resource(essence_tier_4, 'c:ingots/uranium', 'mysticalagriculture:uranium_seeds')
  infusion_resource(essence_tier_4, 'c:ingots/invar', 'mysticalagriculture:invar_seeds')
  infusion_resource(essence_tier_4, 'c:ingots/electrum', 'mysticalagriculture:electrum_seeds')
  infusion_resource(essence_tier_4, 'c:ingots/constantan', 'mysticalagriculture:constantan_seeds')
  infusion_resource(essence_tier_4, 'c:ingots/nickel', 'mysticalagriculture:nickel_seeds')
  infusion_resource(essence_tier_3, 'c:ingots/lead', 'mysticalagriculture:lead_seeds')
  infusion_resource(essence_tier_3, 'c:ingots/silver', 'mysticalagriculture:silver_seeds')
  infusion_resource(essence_tier_3, 'c:ingots/bronze', 'mysticalagriculture:bronze_seeds')
  infusion_resource(essence_tier_3, 'c:ingots/tin', 'mysticalagriculture:tin_seeds')
  infusion_resource(essence_tier_2, 'c:dusts/saltpeter', 'mysticalagriculture:saltpeter_seeds')
  infusion_resource(essence_tier_2, 'c:ingots/aluminum', 'mysticalagriculture:aluminum_seeds')



  
  function cloche(seed, crop, farmland, output) {
    event.custom({
      "type": "immersiveengineering:cloche",
      "input": {
        "item": seed
      },
      "render": {
        "type": "immersiveengineering:crop",
        "block": crop
      },
      "results": [
        {
          "basePredicate": {
            "item": output
          },
          "count": 2
        }
      ],
      "soil": {
        "item": farmland
      },
      "time": 1200
    })
  }

  cloche("mysticalagriculture:azure_silver_seeds", "mysticalagriculture:azure_silver_crop", farmland_tier_3, "mysticalagriculture:azure_silver_essence")
  cloche("mysticalagriculture:crimson_iron_seeds", "mysticalagriculture:crimson_iron_crop", farmland_tier_3, "mysticalagriculture:crimson_iron_essence")
  cloche("mysticalagriculture:darkstone_seeds", "mysticalagriculture:darkstone_crop", farmland_tier_3, "mysticalagriculture:darkstone_essence")
  cloche("mysticalagriculture:entro_seeds", "mysticalagriculture:entro_crop", farmland_tier_4, "mysticalagriculture:entro_essence")
  cloche("mysticalagriculture:allthemodium_seeds", "mysticalagriculture:allthemodium_crop", farmland_tier_6, "mysticalagriculture:allthemodium_essence")
  cloche("mysticalagriculture:unobtainium_seeds", "mysticalagriculture:unobtainium_crop", farmland_tier_6, "mysticalagriculture:unobtainium_essence")
  cloche("mysticalagriculture:vibranium_seeds", "mysticalagriculture:vibranium_crop", farmland_tier_6, "mysticalagriculture:vibranium_essence")
  

  // Silent Gear Repair Kits
  event.shapeless(
    Item.of ('silentgear:crude_repair_kit'),
    [
      'silentgear:template_board',
      'silentgear:template_board',
      'silentgear:template_board',
      'silentgear:template_board',
      'silentgear:template_board',
      '#c:rods/wooden',
      'minecraft:iron_ingot'
    ]
  )

  event.shapeless(
    Item.of ('silentgear:very_crude_repair_kit'),
    [
      'silentgear:template_board',
      'silentgear:template_board',
      'silentgear:template_board',
      'silentgear:template_board',
      'silentgear:template_board',
      '#c:rods/wooden',
      '#c:stones'
    ]
  )

  event.shapeless(
    Item.of ('silentgear:sturdy_repair_kit'),
    [
      'minecraft:iron_ingot',
      'minecraft:iron_ingot',
      'minecraft:iron_ingot',
      'minecraft:iron_ingot',
      'minecraft:iron_ingot',
      '#c:rods/iron',
      'minecraft:diamond'
    ]
  )

  event.shapeless(
    Item.of ('silentgear:crimson_repair_kit'),
    [
      'silentgear:crimson_steel_ingot',
      'silentgear:crimson_steel_ingot',
      'silentgear:crimson_steel_ingot',
      'silentgear:crimson_steel_ingot',
      'silentgear:crimson_steel_ingot',
      'silentgear:blaze_gold_ingot',
      'minecraft:blaze_rod'
    ]
  )

  event.shapeless(
    Item.of ('silentgear:azure_repair_kit'),
    [
      'silentgear:azure_electrum_ingot',
      'silentgear:azure_electrum_ingot',
      'silentgear:azure_electrum_ingot',
      'silentgear:azure_electrum_ingot',
      'silentgear:azure_electrum_ingot',
      'minecraft:emerald',
      'minecraft:end_rod'
    ]
  )

  function essence_ingot(material, output, amount) {
    event.shaped(
      Item.of(output, amount), // arg 1: output
      [
        'AAA',
        'A A', // arg 2: the shape (array of strings)
        'AAA'
      ],
      {
        A: material
      }
    )
  
  }

  function essence_dust(material, output, amount) {
    event.shaped(
      Item.of(output, amount), // arg 1: output
      [
        'AAA'
      ],
      {
        A: material
      }
    )
  
  }

  essence_ingot('minecraft:dried_kelp', 'sushigocrafting:nori_sheets', 6)

  essence_ingot('mysticalagriculture:darkstone_essence', 'forbidden_arcanus:darkstone', 6)

  essence_ingot('mysticalagriculture:entro_essence', 'extendedae:entro_crystal', 6)
  essence_dust('mysticalagriculture:entro_essence', 'extendedae:entro_dust', 3)

  essence_ingot('mysticalagriculture:allthemodium_essence', 'allthemodium:allthemodium_ingot', 2)
  essence_ingot('mysticalagriculture:allthemodium_essence', 'allthemodium:allthemodium_dust', 1)

  essence_ingot('mysticalagriculture:unobtainium_essence', 'allthemodium:unobtainium_ingot', 2)
  essence_ingot('mysticalagriculture:unobtainium_essence', 'allthemodium:unobtainium_dust', 1)

  essence_ingot('mysticalagriculture:vibranium_essence', 'allthemodium:vibranium_ingot', 2)
  essence_ingot('mysticalagriculture:vibranium_essence', 'allthemodium:vibranium_dust', 1)

  essence_ingot('mysticalagriculture:azure_silver_essence', 'silentgear:azure_silver_ingot', 6)
  essence_ingot('mysticalagriculture:azure_silver_essence', 'silentgear:azure_silver_dust', 3)

  essence_ingot('mysticalagriculture:crimson_iron_essence', 'silentgear:crimson_iron_ingot', 6)
  essence_ingot('mysticalagriculture:crimson_iron_essence', 'silentgear:crimson_iron_dust', 3)
  
  console.log('Hello, the recipe event has fired!')
})