// priority: 0

ServerEvents.recipes((event) => {
	//removals
	removeRecipeByOutput(event, [
		AA("solar_panel"),
		AA("energizer"),
		AA("steel_cable"),
		AA("desh_cable"),
		AA("desh_fluid_pipe"),
		AA("ostrum_fluid_pipe"),
		AA("cable_duct"),
		AA("fluid_pipe_duct"),
		AA("coal_generator"),
		AA("nasa_workbench"),
		AA("fuel_refinery"),
		AA("oxygen_loader"),
		AA("water_pump"),
		AA("cryo_freezer"),
		AA("photovoltaic_etrium_cell"),
		AA("photovoltaic_vesnium_cell"),
		AA("wrench"),
		AA("etrionic_blast_furnace"),
	])
	removeRecipeByID(event, [
		AA("iron_rod"),
		AA("steel_rod"),
		AA_GA("crafting/enchanted_book_space_breathing"),
		AA_GA("crafting/enchanted_book_acid_rain_proof"),
		AA_GA("crafting/enchanted_book_gravity_normalizing"),
		AA_GA("crafting/enchanted_book_space_fire_proof"),
	])
	removeRecipeByType(event, [
		AA("compressing"),
		AA("alloying"),
	])
	
	colours.forEach(color => {
		//industrial lamps unify with projectred
		removeRecipeByOutput(event, [
			AA(`${color}_industrial_lamp`),
			AA(`small_${color}_industrial_lamp`),
		])
		event.stonecutting(AA(`${color}_industrial_lamp`, 4), PR_I(`${color}_illumar_lamp`)).id(KJ(`projectred/${color}_industrial_lamp`))
		event.stonecutting(AA(`small_${color}_industrial_lamp`, 4), PR_I(`${color}_illumar_lamp`)).id(KJ(`projectred/small_${color}_industrial_lamp`))
		
		//flags to iron tier
		removeRecipeByOutput(event, [
			AA(`${color}_flag`),
		])
		
		 event.shaped(AA(`${color}_flag`), [
			'ABB',
			'ABB',
			'A  '
		], {
			A: F('#rods/iron'),
			B: F('#wool'),
		})
	})
	
	//doors unify
	removeRecipeByOutput(event, [
		AA("reinforced_door"),
		AA("airlock"),
		AA("steel_sliding_door"),
		AA("iron_sliding_door"),
		AA("steel_door"),
	])
	event.stonecutting(AA("reinforced_door"), MI_D("#doors_big/iron"))
	event.stonecutting(AA("airlock"), MI_D("#doors_big/iron"))
	event.stonecutting(AA("steel_sliding_door"), MI_D("#doors_big/iron"))
	event.stonecutting(AA("iron_sliding_door"), MI_D("#doors_big/iron"))
	event.stonecutting(AA("steel_door"), MI_D("#doors_iron"))
	
	//sheets compat AA
	const sheets = ["steel", "ostrum", "calorite", "desh"]
	sheets.forEach(sheet => {
		customRecipes.ad_astra.compressing(event, AA(`${sheet}_plate`), F(`#ingots/${sheet}`))
	})
	
	//oxygen gear
	removeRecipeByOutput(event, [
		AA("oxygen_gear"),
	])
	event.recipes.extendedcrafting.shaped_table(AA('oxygen_gear'), [
		'  A  ',
		'BBBBB',
		'BCBCB',
		'BCBCB',
		'BBBBB',
	], {
		A: MC('end_rod'),
		B: F('#plates/steel'),
		C: M('electrolytic_core'),
	})

	//gas tank
	removeRecipeByOutput(event, [
		AA("gas_tank"),
	])
	event.recipes.extendedcrafting.shaped_table(AA('gas_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'),
	})

	//oil
	removeRecipeByID(event, [
		AA_GA("compat/industrialforegoing/laser_drill_fluid/oil"),
	])
	event.custom({
		type: M('centrifuging'),
		input: { amount: 4, gas: M('fissile_fuel') },
		output: { amount: 1, gas: KJ('gaseous_oil') }
	});
  
	event.custom({
		"type": M("rotary"),
		"fluidInput": {
			"amount": 1,
			"fluid": AA("oil")
		},
		"fluidOutput": {
			"amount": 1,
			"fluid": AA("oil")
		},
		"gasInput": {
			"amount": 1,
			"gas": KJ("gaseous_oil")
		},
		"gasOutput": {
			"amount": 1,
			"gas": KJ("gaseous_oil")
		}
	})

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

	event.custom({
		"type": M("reaction"),
		"duration": 10,
		"fluidInput": {
			"amount": 200,
			"fluid": AA("oil")
		},
		"gasInput": {
			"amount": 200,
			"gas": MG("fusion_fuel")
		},
		"gasOutput": {
			"amount": 400,
			"gas": KJ("gaseous_fuel")
		},
		"itemInput": {
			"amount": 1,
			"ingredient": {
				"item": M("reprocessed_fissile_fragment")
			}
		}
	})
	
	//engine frame
	removeRecipeByOutput(event, [
		AA("engine_frame"),
	])
	event.recipes.extendedcrafting.shaped_table(AA(`engine_frame`), [
		'  AAAAAAAAA',
		' BA      BA',
		'AAAAAAAAA A',
		'A A     A A',
		'A A     A A',
		'A A     A A',
		'A A     A A',
		'A A     A A',
		'A AAAAAAAAA',
		'AB      AB ',
		'AAAAAAAAA  ',
	], {
		A: CP("steel_3"),
		B: F("#rods/steel"),
	})

	//engine fan
	removeRecipeByOutput(event, [
		AA("fan"),
	])
	event.recipes.extendedcrafting.shaped_table(AA(`fan`), [
		'  BBB    ',
		'  BCCB   ',
		'   BCB BB',
		' BBBCBBCB',
		'BCCCACCCB',
		'BCBBCBBB ',
		'BB BCB   ',
		'   BCCB  ',
		'    BBB  ',
	], {
		A: MG("turbine_rotor"),
		B: MG("turbine_blade"),
		C: CR("propeller"),
	}).tier(5)

	//rocket fin
	removeRecipeByOutput(event, [
		AA("rocket_fin"),
	])
	event.recipes.extendedcrafting.shaped_table(AA(`rocket_fin`), [
		'     A     ',
		'    ABA    ',
		'   ABBBA   ',
		'  ABBCBBA  ',
		' ACCCACCCA ',
		'ACCCA ACCCA',
		'ACCA   ACCA',
		'ACA     ACA',
		'AA       AA',
	], {
		A: F("#plates/steel"),
		B: CP("steel_3"),
		C: CP("iron_4"),
	})

	//rocket nose cone
	removeRecipeByOutput(event, [
		AA("rocket_nose_cone"),
	])
	event.recipes.extendedcrafting.shaped_table(AA(`rocket_nose_cone`), [
		'     A     ',
		'     B     ',
		'     C     ',
		'    CDC    ',
		'   CDEDC   ',
		'  CDEEEDC  ',
		' CDEEEEEDC ',
		'CDDDDDDDDDC',
		' CCCCCCCCC ',
	], {
		A: PREXP("magnum_star_omega"),
		B: MC("end_rod"),
		C: F("#plates/steel"),
		D: CP("steel_3"),
		E: CP("iron_4"),
	})

	//oxygen loader
	removeRecipeByOutput(event, [
		AA("oxygen_distributor"),
	])
    event.recipes.extendedcrafting.shaped_table(AA("oxygen_distributor"), [
		'BGGGGGGGB',
		'GFFFFFFFG',
		'GFEDDDEFG',
		'GFCCACCFG',
		'GFEDDDEFG',
		'GFFFFFFFG',
		'BGGGGGGGB',
	], {
		A: M("rotary_condensentrator"),
		B: CP('steel_3'),
		C: AA('oxygen_gear'),
		D: AA('fan'),
		E: M('ultimate_control_circuit'),
		F: M('ultimate_tier_installer'),
		G: M('hdpe_rod'),
	})
	
	//tanks & engines
	const spaceMats = {
		steel: { A: CP("iron_4"), B: CP("steel_3"), C: PREXP("green_matter"), D: PREXP("red_power_flower") },
		desh: { A: CP("gold_4"), B: CP("desh_3"), C: PREXP("lime_matter"), D: PREXP("magenta_power_flower") },
		ostrum: { A: CP("diamond_4"), B: CP("ostrum_3"), C: PREXP("yellow_matter"), D: PREXP("pink_power_flower") },
		calorite: { A: CP("emerald_4"), B: CP("calorite_3"), C: PREXP("orange_matter"), D: PREXP("purple_power_flower") },
	}

	for (let mat in spaceMats) {
		//tanks
		removeRecipeByOutput(event, [
			AA(`${mat}_tank`),
		])
		event.recipes.extendedcrafting.shaped_table(AA(`${mat}_tank`), [
			'AAAAAAA  ',
			'ABBBBBA  ',
			'ABECEBA  ',
			'ABCDCBA  ',
			'ABCFCBAE ',
			'ABCDCBAEE',
			'ABECEBAE ',
			'ABBBBBA  ',
			'AAAAAAA  ',
		], {
			A: spaceMats[mat].A,
			B: spaceMats[mat].B,
			C: M("ultimate_chemical_tank"),
			D: M("electrolytic_core"),
			E: singularityId("reprocessed_fissile_fragment"),
			F: spaceMats[mat].C,
		})
		
		//engines
		removeRecipeByOutput(event, [
			AA(`${mat}_engine`),
		])
		event.recipes.extendedcrafting.shaped_table(AA(`${mat}_engine`), [
			' AAAAAAAAAA',
			'ABBBBBBBBBA',
			'ABEEEEEEEBA',
			'ABEEEIEEEBA',
			'ABBBBIBBBBA',
			'AAAAAIAAAAA',
			'    DHD    ',
			'   DFGFD   ',
			' DCCCCCCCD ',
			'AAAAAAAAAAA',
		], {
			A: spaceMats[mat].A,
			B: spaceMats[mat].B,
			C: AA("fan"),
			D: AA("engine_frame"),
			E: singularityId("reprocessed_fissile_fragment"),
			F: spaceMats[mat].D,
			G: spaceMats[mat].C,
			H: PREXP("infinite_fuel"),
			I: singularityId("antimatter"),
		})
	}
	
	//oxygen cans
	removeRecipeByOutput(event, [
		AA_GA("oxygen_can"),
		AA_GA("netherite_oxygen_can"),
	])
	event.smithing(AA_GA("oxygen_can"), AA("oxygen_gear"), M('canteen'), M('ultimate_chemical_tank'))
	event.smithing(AA_GA("netherite_oxygen_can"), AA_GA('oxygen_can'), F('#ingots/netherite'))
	
	//rocket recipes
	const astraTiers = ["steel", "desh", "ostrum", "calorite"]
	removeRecipeByType(event, [
		AA("nasa_workbench"),
	])
	astraTiers.forEach((tier, i) => {
		event.custom({
			type: AA("nasa_workbench"),
			ingredients: toRecipeJsonItem([
				AA("rocket_nose_cone"),
				CP(`${tier}_3`), CP(`${tier}_3`),
				X("controller"), X("controller"),
				CP(`${tier}_3`), CP(`${tier}_3`),
				AA("rocket_fin"), AA(`${tier}_tank`), AA(`${tier}_tank`), AA("rocket_fin"),
				AA("rocket_fin"), AA(`${tier}_engine`), AA("rocket_fin"),
			]),
			result: { count: 1, id: AA(`tier_${i + 1}_rocket`) }
		})
	})
	
	//cryo fuel
	event.custom({
		"type": M("rotary"),
		"fluidInput": {
			"amount": 1,
			"fluid": AA("cryo_fuel")
		},
		"fluidOutput": {
			"amount": 1,
			"fluid": AA("cryo_fuel")
		},
		"gasInput": {
			"amount": 1,
			"gas": KJ("gaseous_cryo_fuel")
		},
		"gasOutput": {
			"amount": 1,
			"gas": KJ("gaseous_cryo_fuel")
		}
	})
	
	event.custom({
		"type": M("reaction"),
		"duration": 10,
		"fluidInput": {
			"amount": 100,
			"fluid": MG("fusion_fuel")
		},
		"gasInput": {
			"amount": 100,
			"gas": KJ("gaseous_fuel")
		},
		"gasOutput": {
			"amount": 200,
			"gas": KJ("gaseous_cryo_fuel")
		},
		"itemInput": {
			"amount": 1,
			"ingredient": {
				"item": P("charged_snowball")
			}
		}
	})

	//enrichment chamber
	removeRecipeByOutput(event, [
		AA_GA("automation_nasa_workbench"),
	])
	event.recipes.mekanism.nucleosynthesizing(FN('basic_flux_storage'), `100x ${M("antimatter")}`, AA_GA("automation_nasa_workbench"), 1000)
	//event.recipes.extendedcrafting.shaped_table(AA_GA("automation_nasa_workbench"), [
	//	'BCHHJHHCB',
	//	'CIMGGGMIC',
	//	'HMKFFFKMH',
	//	'HGFEDEFGH',
	//	'JGFDADFGJ',
	//	'HGFEDEFGH',
	//	'HMLFFFLMH',
	//	'CIMGGGMIC',
	//	'BCHHJHHCB',
	//], {
	//	B: CP('iron_4'),
	//	C: CP('steel_3'),
	//	D: M('steel_casing'),
	//	E: M('energy_tablet'),
	//	K: M('pellet_antimatter'),
	//	G: M('ultimate_control_circuit'),
	//	H: M('alloy_atomic'),
	//	I: CP('osmium_3'),
	//	J: CR('mechanical_arm'),
	//	A: FN('basic_flux_storage'),
	//	F: F('#storage_blocks/enhanced_redstone_ingot'),
	//	L: AV('infinity_catalyst'),
	//	M: M('ultimate_control_circuit'),
	//})
})