// priority: 0

onEvent('recipes', e => {
  //removals
  removeRecipeByID(e, [
    BT("wheel"),
    BT("water_pump"),
    BT("hammer"),
    BT("compressor"),
    BT("blast_furnace"),
    BT("solar_panel"),
    BT("coal_generator"),
    BT("fuel_refinery"),
    BT("oxygen_gear"),
    BT('oxygen_tank'),
    BT("nasa_workbench"), //recipe in synthesizing.zs
    BT(`engine_frame`),
    BT(`engine_fan`),
    BT(`rocket_fins`),
    BT(`rocket_nose_cone`),
    BT(`oxygen_loader`),
    BT('oxygen_bubble_distributor'),
  ])

  //energy acceptor
  e.replaceInput({ id: AE2("network/blocks/energy_energy_acceptor") }, AE2("#crystals/fluix"), AE2("#crystals/certus"))


  //wheel: wheel base
  e.recipes.extendedcrafting.shaped_table(BT("wheel"), [
    ' AAA ',
    'ABBBA',
    'ABCBA',
    'ABBBA',
    ' AAA ',
  ], {
      B: IF('dryrubber'),
      A: F('#dyes/black'),
      C: CR('shaft'),
  }).id(KJ(`wheel_base`))

  //compressed metals
  e.recipes.createPressing(BT("desh_plate"), F("#ingots/desh"))

  const metals = [
    { metal: "steel", ingot: EE("steel_plate") },
    { metal: "desh", ingot: BT("desh_plate") },
    { metal: "silicon", ingot: BT("silicon_ingot") },
  ]
  metals.forEach(metalObj => {
    const { metal, ingot } = metalObj
    e.remove({ output: BT(`compressed_${metal}`) })
  
    let tMetal = KJ(`incomplete_${metal}_plate`)
    e.recipes.createSequencedAssembly([
      BT(`compressed_${metal}`),
    ], ingot, [
      e.recipes.createPressing(tMetal, tMetal)
    ]).transitionalItem(tMetal)
      .loops(16)
      .id(KJ(`compressed_${metal}`))
  })

  //oxygen gear
  e.recipes.extendedcrafting.shaped_table(BT('oxygen_gear'), [
    '  A  ',
    'BBBBB',
    'BCBCB',
    'BCBCB',
    'BBBBB',
  ], {
    A: MC('end_rod'),
    B: F('#plates/steel'),
    C: M('electrolytic_core'),
  }).id(KJ(`${BT()}/extended_crafting/oxygen_gear`))

  //oxygen tank
  e.recipes.extendedcrafting.shaped_table(BT('oxygen_tank'), [
    '  C  ',
    ' ADA ',
    ' ABA ',
    ' AEA ',
    ' AAA ',
  ], {
    A: F('#plates/steel'),
    B: M('scuba_tank'),
    C: F('#gears/gold'),
    D: M('electrolytic_core'),
    E: M('ultimate_chemical_tank'),
  }).id(KJ(`${BT()}/extended_crafting/oxygen_tank`))

  //oil
	e.custom({
		type: M('centrifuging'),
		input: { amount: 4, gas: M('fissile_fuel') },
		output: { amount: 1, gas: KJ('gaseous_oil') }
	});
  
  e.custom({
		"type": M("rotary"),
		"fluidInput": {
			"amount": 1,
			"fluid": BT("oil")
		},
		"fluidOutput": {
			"amount": 1,
			"fluid": BT("oil")
		},
		"gasInput": {
			"amount": 1,
			"gas": KJ("gaseous_oil")
		},
		"gasOutput": {
			"amount": 1,
			"gas": KJ("gaseous_oil")
		}
	})

  //fuel
  e.custom({
		"type": M("rotary"),
		"fluidInput": {
			"amount": 1,
			"fluid": BT("fuel")
		},
		"fluidOutput": {
			"amount": 1,
			"fluid": BT("fuel")
		},
		"gasInput": {
			"amount": 1,
			"gas": KJ("gaseous_fuel")
		},
		"gasOutput": {
			"amount": 1,
			"gas": KJ("gaseous_fuel")
		}
	})

  e.custom({
		"type": M("reaction"),
		"duration": 40,
		"fluidInput": {
			"amount": 200,
			"fluid": BT("oil")
		},
		"gasInput": {
			"amount": 200,
			"gas": MG("fusion_fuel")
		},
		"gasOutput": {
			"amount": 200,
			"gas": KJ("gaseous_fuel")
		},
		"itemInput": {
			"amount": 1,
			"ingredient": {
				"item": M("reprocessed_fissile_fragment")
			}
		}
	})



  //engine frame
  e.recipes.extendedcrafting.shaped_table(BT(`engine_frame`), [
    '  AAAAAAA',
    ' BA    BA',
    'AAAAAAA A',
    'A A   A A',
    'A A   A A',
    'A A   A A',
    'A AAAAAAA',
    'AB    AB ',
    'AAAAAAA  ',
  ], {
    A: BT("compressed_steel"),
    B: F("#rods/steel"),
  }).id(KJ(`${BT()}/extended_crafting/engine_frame`))

  //engine fan
  e.recipes.extendedcrafting.shaped_table(BT(`engine_fan`), [
    '  BBB    ',
    '  BCCB   ',
    '   BCB BB',
    ' BBBCBBCB',
    'BCCCACCCB',
    'BCBBCBBB ',
    'BB BCB   ',
    '   BCCB  ',
    '    BBB  ',
  ], {
    A: MG("turbine_rotor"),
    B: MG("turbine_blade"),
    C: CR("propeller"),
  }).id(KJ(`${BT()}/extended_crafting/engine_fan`))

  //rocket fin
  e.recipes.extendedcrafting.shaped_table(BT(`rocket_fin`), [
    '    A    ',
    '   ABA   ',
    '   ABA   ',
    '  ABCBA  ',
    '  ABCBA  ',
    ' ABCCCBA ',
    ' ABCCCBA ',
    'ABBBBBBBA',
    'AAAAAAAAA',
  ], {
    A: BT("compressed_steel"),
    B: F("#storage_blocks/steel"),
    C: CP("iron_4"),
  }).id(KJ(`${BT()}/extended_crafting/rocket_fin`))

  //rocket nose cone
  e.recipes.extendedcrafting.shaped_table(BT(`rocket_nose_cone`), [
    '    A    ',
    '    B    ',
    '    C    ',
    '   CDC   ',
    '  CDEDC  ',
    ' CDEEEDC ',
    'CDEEEEEDC',
    'CDDDDDDDC',
    ' CCCCCCC ',
  ], {
    A: PREXP("magnum_star_omega"),
    B: MC("end_rod"),
    C: BT("compressed_steel"),
    D: F("#storage_blocks/steel"),
    E: CP("iron_4"),
  }).id(KJ(`${BT()}/extended_crafting/rocket_nose_cone`))

  //oxygen loader
  e.shaped(BT('oxygen_bubble_distributor'), [
    'DCD',
    'BAB',
    'DED',
  ], {
    A: M('rotary_condensentrator'),
    B: BT('engine_fan'),
    C: BT('oxygen_gear'),
    D: M('ultimate_control_circuit'),
    E: M('ultimate_tier_installer'),
  }).id(KJ(`${BT()}/oxygen_bubble_distributor`))


  //tanks & engines
  const spaceMats = {
    iron: { A: CP("iron_4"), B: BT("compressed_steel"), C: PREXP("green_matter"), D: PREXP("red_power_flower") },
    golden: { A: CP("gold_4"), B: BT("compressed_desh"), C: PREXP("lime_matter"), D: PREXP("magenta_power_flower") },
    diamond: { A: CP("diamond_4"), B: BT("compressed_silicon"), C: PREXP("yellow_matter"), D: PREXP("pink_power_flower") },
  }

  for (let mat in spaceMats) {
    //tanks
    e.remove({ id: BT(`${mat}_tank`) })
    e.recipes.extendedcrafting.shaped_table(BT(`${mat}_tank`), [
      ' AAAAAAA ',
      ' ABBBBBA ',
      ' ABECEBA ',
      ' ABCDCBA ',
      ' ABCFCBAE',
      ' ABCDCBAE',
      ' ABECEBAE',
      ' ABBBBBA ',
      ' AAAAAAA ',
    ], {
      A: spaceMats[mat].A,
      B: spaceMats[mat].B,
      C: M("ultimate_chemical_tank"),
      D: M("electrolytic_core"),
      E: M("reprocessed_fissile_fragment"),
      F: spaceMats[mat].C,
    }).id(KJ(`${BT()}/extended_crafting/${mat}_tank`))
    
    //engines
    e.remove({ id: BT(`${mat}_engine`) })
    e.recipes.extendedcrafting.shaped_table(BT(`${mat}_engine`), [
      ' AAAAAAAA',
      'ABBBBBBBA',
      'ABEEEEEBA',
      'ABEEIEEBA',
      'ABBBIBBBA',
      'AAAAIAAAA',
      '   DHD   ',
      '  DFGFD  ',
      ' DCCCCCD ',
    ], {
      A: spaceMats[mat].A,
      B: spaceMats[mat].B,
      C: BT("engine_fan"),
      D: BT("engine_frame"),
      E: M("reprocessed_fissile_fragment"),
      F: spaceMats[mat].D,
      G: spaceMats[mat].C,
      H: PREXP("infinite_fuel"),
      I: Item.of('extendedcrafting:singularity', {Id:"extendedcrafting:antimatter"}),
    }).id(KJ(`${BT()}/extended_crafting/${mat}_engine`))
  }
})
