events.listen('recipes', function (e) {

    var mekcrush = e.recipes.mekanism.crushing
    var mekenrich = e.recipes.mekanism.enriching
    var pedcrush = e.recipes.pedestals.pedestal_crushing
    function silentsCrushTag(tag, result, rCount, duration) {
      e.recipes.silents_mechanisms.crushing({
        process_time: duration,
        ingredient: {
          tag: tag
        },
        results: [
          {
            item: result,
            count: rCount
          }
        ]
      })
    }
    function silentsCrushItem(item, result, rCount, duration) {
      e.recipes.silents_mechanisms.crushing({
        process_time: duration,
        ingredient: {
          item: item
        },
        results: [
          {
            item: result,
            count: rCount
          }
        ]
      })
    }
    function energize(ingredient, result, rCount, power) {
      e.recipes.powah.energizing({
        ingredients: ingredient,
        energy: power,
        result: {
          item: result,
          count: rCount
        }
      })
    }
    function pressure(inputs, result, rCount, pressure) {
      e.recipes.pneumaticcraft.pressure_chamber(
        {
          inputs: inputs,
          pressure: pressure,
          results: [
            {
              item: result,
              count: rCount
            }
          ]
        }
      )
    }
    function shapedC(result, count, patternP1, patternP2, patternP3, items) {
        e.shaped(item.of(result, count), [
            patternP1,
            patternP2,
            patternP3
        ], items
        )
    }
    function shaped(result, patternP1, patternP2, patternP3, items) {
        e.shaped(item.of(result), [
            patternP1,
            patternP2,
            patternP3
        ], items
        )
    }
  
    //Make bio fuel use tags instead of invidual items
    e.remove({output: 'mekanism:bio_fuel'})
    mekcrush(item.of('mekanism:bio_fuel', 2), '#misctags:biofuel2')
    mekcrush(item.of('mekanism:bio_fuel', 4), '#misctags:biofuel4')
    mekcrush(item.of('mekanism:bio_fuel', 5), '#misctags:biofuel5')
    mekcrush(item.of('mekanism:bio_fuel', 7), '#misctags:biofuel7')
    mekcrush(item.of('mekanism:bio_fuel', 8), '#misctags:biofuel8')
  
    //Recipes for AE2 stuff
    mekcrush(item.of('appliedenergistics2:certus_quartz_dust'), '#forge:gems/certus_quartz')
    mekcrush(item.of('appliedenergistics2:ender_dust'), '#forge:ender_pearls')
    mekcrush(item.of('appliedenergistics2:fluix_dust'), '#appliedenergistics2:crystals/fluix')
    silentsCrushTag('forge:ender_pearls', 'appliedenergistics2:ender_dust', 1, 180)
    silentsCrushTag('forge:gems/certus_quartz', 'appliedenergistics2:certus_quartz_dust', 1, 180)
    silentsCrushItem('appliedenergistics2:fluix_crystal', 'appliedenergistics2:fluix_dust', 1, 180)
    mekenrich(item.of('appliedenergistics2:purified_certus_quartz_crystal'), '#forge:gems/certus_quartz')
    mekenrich(item.of('appliedenergistics2:purified_nether_quartz_crystal'), '#forge:gems/quartz')
    mekenrich(item.of('appliedenergistics2:purified_fluix_crystal'), 'appliedenergistics2:fluix_crystal')
    mekenrich(item.of('appliedenergistics2:purified_certus_quartz_crystal'), 'appliedenergistics2:certus_crystal_seed')
    mekenrich(item.of('appliedenergistics2:purified_fluix_crystal'), 'appliedenergistics2:fluix_crystal_seed')
    mekenrich(item.of('appliedenergistics2:purified_nether_quartz_crystal'), 'appliedenergistics2:nether_quartz_seed')
    
    //Powah recipes
    energize([{tag: 'forge:ingots/allthemodium'},{tag: 'forge:ingots/unobtainium'}], 'allthemodium:unobtainium_allthemodium_alloy_ingot', 1, 50000)
    energize([{tag: 'forge:ingots/vibranium'},{tag: 'forge:ingots/allthemodium'}], 'allthemodium:vibranium_allthemodium_alloy_ingot', 1, 50000)
    energize([{tag: 'forge:ingots/vibranium'},{tag: 'forge:ingots/unobtainium'}], 'allthemodium:vibranium_unobtainium_alloy_ingot', 1, 50000)
    energize([{tag: 'forge:storage_blocks/iron'},{tag: 'forge:storage_blocks/gold'}], 'powah:energized_steel_block', 2, 90000)
    energize([{item: 'botania:blaze_block'}], 'powah:blazing_crystal_block', 1, 810000)
    energize([{tag: 'forge:storage_blocks/diamond'}], 'powah:niotic_crystal_block', 1, 2700000)
    energize([{tag: 'forge:storage_blocks/emerald'}], 'powah:spirited_crystal_block', 1, 9000000)

    //Misc recipes
    e.remove({id: 'byg:black_glass_from_sand'})
    e.remove({id: 'byg:purple_glass_from_sand'})
    e.remove({id: 'byg:blue_glass_from_sand'})
    e.remove({id: 'byg:white_glass_from_sand'})
    e.remove({id: 'minecraft:glass'})
    //e.smelting(item.of('appliedenergistics2:certus_quartz_crystal'), '#forge:ores/certus_quartz').xp(1)
    e.smelting(item.of('minecraft:glass'), '#forge:sand').xp(.1)
    e.shapeless(item.of('minecraft:clay_ball', 4), 'minecraft:clay')
    e.shapeless(item.of('minecraft:quartz', 4), 'minecraft:quartz_block')
    shaped('appliedenergistics2:silicon_press',
    'EEE',
    'EAE',
    'EEE',
    {
      'E': 'mysticalagriculture:iron_essence',
      'A': 'mysticalagriculture:silicon_essence'
    })
    shaped('appliedenergistics2:calculation_processor_press',
    'EEE',
    'EAE',
    'EEE',
    {
      'E': 'mysticalagriculture:iron_essence',
      'A': 'mysticalagriculture:certus_quartz_essence'
    })
    shaped('appliedenergistics2:engineering_processor_press',
    'EEE',
    'EAE',
    'EEE',
    {
      'E': 'mysticalagriculture:iron_essence',
      'A': 'mysticalagriculture:diamond_essence'
    })
    shaped('appliedenergistics2:logic_processor_press',
    'EEE',
    'EAE',
    'EEE',
    {
      'E': 'mysticalagriculture:iron_essence',
      'A': 'mysticalagriculture:gold_essence'
    })
    shaped('minecraft:hopper',
    'ILI',
    'ILI',
    ' I ',
    {
        'L': '#minecraft:logs',
        'I': '#forge:ingots/iron'
    })
    shaped('uppers:upper',
    ' I ',
    'ILI',
    'ILI',
    {
        'L': '#minecraft:logs',
        'I': '#forge:ingots/iron'
    })
    shapedC('minecraft:stick', 16,
    '   ',
    ' L ',
    ' L ',
    {
        'L': '#minecraft:logs'
    })
    shaped('minecraft:water_bucket',
    ' C ',
    'CBC',
    ' C ',
    {
        'C': item.of('resourcefulbees:resourceful_honeycomb', {ResourcefulBees:{Beename:"water",Color:"#0F3653"}}),
        'B': 'minecraft:bucket'
    })
    shaped('minecraft:lava_bucket',
    ' C ',
    'CBC',
    ' C ',
    {
        'C': item.of('resourcefulbees:resourceful_honeycomb', {ResourcefulBees:{Beename:"lava",Color:"#DB4819"}}),
        'B': 'minecraft:bucket'
    })
    shapedC('minecraft:chest', 4,
    'LLL',
    'L L',
    'LLL',
    {
        'L': '#minecraft:logs'
    })
    shapedC('appliedenergistics2:sky_stone_block', 4,
    'BSB',
    'SBS',
    'BSB',
    {
      'S': 'minecraft:stone',
      'B': 'minecraft:blackstone'
    })
/*     e.recipes.industrialforegoing.dissolution_chamber({
      input: [
        {
          tag: 'minecraft:planks'
        }
      ],
      inputFluid: '{FluidName:\'immersiveengineering:creosote\',Amount:125}',
      processingTime: 1,
      output: {
        item: 'immersiveengineering:treated_wood_horizontal',
        count: 1
      }
    }) */

    mekcrush(item.of('minecraft:blaze_powder', 4), '#forge:rods/blaze')
    mekcrush(item.of('minecraft:quartz',4), '#forge:storage_blocks/quartz')
    mekenrich(item.of('minecraft:blaze_rod'), [item.of('minecraft:blaze_powder', 4)])
    mekenrich(item.of('powah:uraninite', 2), 'powah:uraninite_ore_poor')
    mekenrich(item.of('powah:uraninite', 4), 'powah:uraninite_ore')
    mekenrich(item.of('powah:uraninite', 8), 'powah:uraninite_ore_dense')

    //Creative recipes
    energize([{item: 'appliedenergistics2:dense_energy_cell'}], 'appliedenergistics2:creative_energy_cell', 1, 420000000)
    energize([{item: 'refinedstorage:controller'}], 'refinedstorage:creative_controller', 1, 420000000)
    energize([{item: 'refinedstorageaddons:wireless_crafting_grid'}], 'refinedstorageaddons:creative_wireless_crafting_grid', 1, 420000000)
    energize([{item: 'refinedstorage:wireless_crafting_monitor'}], 'refinedstorage:creative_wireless_crafting_monitor', 1, 420000000)
    energize([{item: 'refinedstorage:wireless_fluid_grid'}], 'refinedstorage:creative_wireless_fluid_grid', 1, 420000000)
    energize([{item: 'refinedstorage:wireless_grid'}], 'refinedstorage:creative_wireless_grid', 1, 420000000)
    e.shapeless(item.of('botania:mana_tablet', {mana:500000,creative:1}), ['botania:creative_pool'])
    e.shapeless('botania:creative_pool', [item.of('botania:mana_tablet', {mana:500000,creative:1})])
    pressure([
      {
        name: 'pneumaticcraft:stacked_item',
        item: 'mysticalagradditions:insanium_block',
        count: 2
      },
      {
        name: 'pneumaticcraft:stacked_item',
        tag: 'forge:pellets/antimatter',
        count: 4
      },
      {
        name: 'pneumaticcraft:stacked_item',
        item: 'botania:gaia_ingot',
        count: 2
      },
      {
        name: 'pneumaticcraft:stacked_item',
        tag: 'forge:storage_blocks/allthemodium',
        count: 1
      },
      {
        name: 'pneumaticcraft:stacked_item',
        tag: 'forge:storage_blocks/vibranium',
        count: 1
      },
      {
        name: 'pneumaticcraft:stacked_item',
        tag: 'forge:storage_blocks/unobtainium',
        count: 1
      }
    ], 'mysticalagradditions:creative_essence', 1, 4.9)
    e.shaped(item.of('botania:creative_pool'), [
      'CSC',
      'CPC',
      'CWC'
      ], {
          'C': 'mysticalagradditions:creative_essence' ,
          'P': 'botania:fabulous_pool',
          'S': 'kubejs:rune_of_sins',
          'W': 'kubejs:mass_of_wills'
          
    })
    e.shaped(item.of('pneumaticcraft:creative_compressor'), [
      'CLC',
      'FCA',
      'CEC'
      ], {
          'C': 'mysticalagradditions:creative_essence',
          'L': 'pneumaticcraft:advanced_liquid_compressor',
          'A': 'pneumaticcraft:advanced_air_compressor',
          'E': 'pneumaticcraft:electrostatic_compressor',
          'F': 'pneumaticcraft:flux_compressor'
    })
    e.shaped(item.of('rats:rat_upgrade_creative'), [
      'HUH',
      'CCC',
      'HUH'
      ], {
          'C': 'mysticalagradditions:creative_essence',
          'H': 'rats:creative_cheese',
          'U': 'rats:rat_upgrade_nonbeliever'
    })

    //SGear salvaging
    function salvage(item, results) {
      e.recipes.silentgear.salvaging(
        {
          ingredient: {
            item: item
          },
          results: results
        }
      )
    }
    salvage('minecraft:netherite_sword', [
      {
        'item': 'minecraft:netherite_ingot',
        'count': 1
      },
      {
          'item': 'minecraft:stick',
          'count': 1
      },
      {
          'item': 'minecraft:diamond',
          'count': 2
      }
    ])
    salvage('minecraft:netherite_shovel', [
      {
        'item': 'minecraft:netherite_ingot',
        'count': 1
      },
      {
          'item': 'minecraft:stick',
          'count': 2
      },
      {
          'item': 'minecraft:diamond',
          'count': 1
      }
    ])
    salvage('minecraft:netherite_pickaxe', [
      {
        'item': 'minecraft:netherite_ingot',
        'count': 1
      },
      {
          'item': 'minecraft:stick',
          'count': 2
      },
      {
          'item': 'minecraft:diamond',
          'count': 3
      }
    ])
    salvage('minecraft:netherite_hoe', [
      {
        'item': 'minecraft:netherite_ingot',
        'count': 1
      },
      {
          'item': 'minecraft:stick',
          'count': 2
      },
      {
          'item': 'minecraft:diamond',
          'count': 2
      }
    ])
    salvage('minecraft:netherite_axe', [
      {
        'item': 'minecraft:netherite_ingot',
        'count': 1
      },
      {
          'item': 'minecraft:stick',
          'count': 2
      },
      {
          'item': 'minecraft:diamond',
          'count': 3
      }
    ])
    salvage('minecraft:netherite_boots', [
      {
        'item': 'minecraft:netherite_ingot',
        'count': 1
      },
      {
          'item': 'minecraft:diamond',
          'count': 4
      }
    ])
    salvage('minecraft:netherite_leggings', [
      {
        'item': 'minecraft:netherite_ingot',
        'count': 1
      },
      {
          'item': 'minecraft:diamond',
          'count': 7
      }
    ])
    salvage('minecraft:netherite_chestplate', [
      {
        'item': 'minecraft:netherite_ingot',
        'count': 1
      },
      {
          'item': 'minecraft:diamond',
          'count': 8
      }
    ])
    salvage('minecraft:netherite_helmet', [
      {
        'item': 'minecraft:netherite_ingot',
        'count': 1
      },
      {
          'item': 'minecraft:diamond',
          'count': 5
      }
    ])
    salvage('minecraft:anvil', [
      {
        'item': 'minecraft:iron_ingot',
        'count': 31
      }
    ])
    salvage('minecraft:diamond_horse_armor', [
      {
          'item': 'minecraft:diamond',
          'count': 7
      }
    ])
    salvage('minecraft:golden_horse_armor', [
      {
        'item': 'minecraft:gold_ingot',
        'count': 7
      }
    ])
    salvage('minecraft:iron_horse_armor', [
      {
        'item': 'minecraft:iron_ingot',
        'count': 7
      }
    ])
    salvage('minecraft:leather_horse_armor', [
      {
        'item': 'minecraft:leather',
        'count': 7
      }
    ])
    salvage('minecraft:minecart', [
      {
        'item': 'minecraft:iron_ingot',
        'count': 5
      }
    ])
    salvage('minecraft:saddle', [
      {
        'item': 'minecraft:leather',
        'count': 5
      },
      {
          'item': 'minecraft:iron_nugget',
          'count': 2
      }
    ])

  //Pedestal stuff
  function coinUpgrade(name, type){
    if (type == 'rf') {
      e.recipes.allthemodium.atmshapeless_crafting({
        ingredients: [
          {
            item: 'pedestals:coin/'+name
          },
          {
            tag: 'forge:storage_blocks/redstone'
          }
        ],
        result: {
          item: 'pedestals:coin/'+type+name
        }})
    } else {
      e.recipes.allthemodium.atmshapeless_crafting({
        ingredients: [
          {
            item: 'pedestals:coin/'+name
          },
          {
            item: 'minecraft:experience_bottle'
          }
        ],
        result: {
          item: 'pedestals:coin/'+type+name
        }})
    }
  }
  coinUpgrade('import','rf')
  coinUpgrade('export','rf')
  coinUpgrade('crusher','rf')
  coinUpgrade('smelter','rf')
  coinUpgrade('sawmill','rf')
  coinUpgrade('quarry','rf')
  coinUpgrade('quarryb','rf')
  coinUpgrade('dropper','xp')
  coinUpgrade('magnet','xp')

  
  
  e.remove({output: 'pedestals:dustflour'})
  function pedestalCrush(result, count, ingredient, type){
      if(type == 1){
        pedcrush({
          ingredient: 
          {
            tag: ingredient
          },
          result: 
          {
            item: result,
            count: count
          }
        })
      }else {
        pedcrush({
          ingredient: 
          {
            item: ingredient
          },
          result: 
          {
            item: result,
            count: count
          }
        })
      }
  }
  pedestalCrush('pamhc2foodcore:flouritem', 1, 'forge:flour_plants', 1)
  //pedestalCrush('appliedenergistics2:fluix_dust', 1, 'appliedenergistics2:fluix_crystal', 0)
  //pedestalCrush('appliedenergistics2:certus_quartz_dust', 1, 'forge:gems/certus_quartz', 1)
  //pedestalCrush('mekanism:dust_quartz', 1, 'forge:gems/quartz', 1)
  e.remove({id: 'appliedenergistics2:grinder/flour'})
  e.recipes.appliedenergistics2.grinder({
    input: {
      tag: 'forge:flour_plants'
    },
    result: {
      primary: {
        item: 'pamhc2foodcore:flouritem',
        count: 1
      }
    },
    turns: 8
  })
  
  e.recipes.allthemodium.atmshaped_crafting({
    pattern: [
      'AB'
    ],
    key: {
      A: {
        item: 'allthemodium:allthemodium_boots'
      },
      B: {
        item: 'allthemodium:allthemodium_leggings'
      }
    },
    result: {
      item: 'allthemodium:allthemodium_chestplate'
    }
})
})