// priority: 0

const materials = ["bronze", "cast_iron", "steel"]

onEvent('recipes', event => {
	materials.forEach(mat => {
		removeRecipeByOutput(event, [
			SP(`${mat}_cogwheel`),
			SP(`${mat}_large_cogwheel`),
			SP(`${mat}_boiler`),
			SP(`${mat}_burner`),
			SP(`${mat}_flywheel`),
			SP(`${mat}_steam_engine`),
		])
	})



	//cogwheels
	donutCraft(event, Item.of(SP("bronze_cogwheel"), 8), F("#cogwheels"), F("#nuggets/bronze"))
	donutCraft(event, Item.of(SP("cast_iron_cogwheel"), 8), SP("bronze_cogwheel"), F("#nuggets/cast_iron"))
	donutCraft(event, Item.of(SP("steel_cogwheel"), 8), SP("cast_iron_cogwheel"), F("#nuggets/steel"))

	event.shaped(Item.of(SP("bronze_large_cogwheel"), 2), [
		'CBC',
		'BAB',
		'CBC',
	], {
		A: F("#large_cogwheels"),
		B: F("#plates/bronze"),
		C: F("#nuggets/bronze"),
	})
	event.shaped(Item.of(SP("cast_iron_large_cogwheel"), 2), [
		'CBC',
		'BAB',
		'CBC',
	], {
		A: SP("bronze_large_cogwheel"),
		B: F("#plates/cast_iron"),
		C: F("#nuggets/cast_iron"),
	})
	event.shaped(Item.of(SP("steel_large_cogwheel"), 2), [
		'CBC',
		'BAB',
		'CBC',
	], {
		A: SP("cast_iron_large_cogwheel"),
		B: F("#plates/steel"),
		C: F("#nuggets/steel"),
	})



	//boilers
	donutCraft(event, SP("bronze_boiler"), CR("fluid_tank"), F("#plates/bronze"))
	donutCraft(event, SP("cast_iron_boiler"), SP("bronze_boiler"), F("#plates/cast_iron"))
	donutCraft(event, SP("steel_boiler"), SP("cast_iron_boiler"), F("#plates/steel"))



	//burners
	event.shaped(SP("bronze_burner"), [
		'CCC',
		'CAC',
		'BBB',
	], {
		A: CRAD("crude_burner"),
		B: MC("bricks"),
		C: F("#plates/bronze"),
	})
	event.shaped(SP("cast_iron_burner"), [
		'CCC',
		'CAC',
		'BBB',
	], {
		A: SP("bronze_burner"),
		B: MC("bricks"),
		C: F("#plates/cast_iron"),
	})
	event.shaped(SP("steel_burner"), [
		'CCC',
		'CAC',
		'BBB',
	], {
		A: SP("cast_iron_burner"),
		B: MC("bricks"),
		C: F("#plates/steel"),
	})



	//flywheels
	event.remove({ output: CR("flywheel") })
	event.recipes.create.mechanical_crafting(CR("flywheel"), [
		' DDD ',
		'DCBCD',
		'DBABD',
		'DCBCD',
		' DDD ',
	], {
		A: CR("shaft"),
		B: MC("#planks"),
		C: F("#cogwheels"),
		D: F("#ingots/brass"),
	})
	event.recipes.extendedcrafting.shaped_table(CR("flywheel"), [
		' DDD ',
		'DCBCD',
		'DBABD',
		'DCBCD',
		' DDD ',
	], {
		A: CR("shaft"),
		B: MC("#planks"),
		C: F("#cogwheels"),
		D: F("#ingots/brass"),
	})
	event.recipes.create.mechanical_crafting(SP("bronze_flywheel"), [
		' DDD ',
		'DCBCD',
		'DBABD',
		'DCBCD',
		' DDD ',
	], {
		A: CR("flywheel"),
		B: MC("#planks"),
		C: SP("bronze_cogwheel"),
		D: F("#ingots/bronze"),
	})
	event.recipes.extendedcrafting.shaped_table(SP("bronze_flywheel"), [
		' DDD ',
		'DCBCD',
		'DBABD',
		'DCBCD',
		' DDD ',
	], {
		A: CR("flywheel"),
		B: MC("#planks"),
		C: SP("bronze_cogwheel"),
		D: F("#ingots/bronze"),
	})
	event.recipes.create.mechanical_crafting(SP("cast_iron_flywheel"), [
		' DDD ',
		'DCBCD',
		'DBABD',
		'DCBCD',
		' DDD ',
	], {
		A: SP("bronze_flywheel"),
		B: MC("#planks"),
		C: SP("cast_iron_cogwheel"),
		D: F("#ingots/cast_iron"),
	})
	event.recipes.extendedcrafting.shaped_table(SP("cast_iron_flywheel"), [
		' DDD ',
		'DCBCD',
		'DBABD',
		'DCBCD',
		' DDD ',
	], {
		A: SP("bronze_flywheel"),
		B: MC("#planks"),
		C: SP("cast_iron_cogwheel"),
		D: F("#ingots/cast_iron"),
	})
	event.recipes.create.mechanical_crafting(SP("steel_flywheel"), [
		' DDD ',
		'DCBCD',
		'DBABD',
		'DCBCD',
		' DDD ',
	], {
		A: SP("cast_iron_flywheel"),
		B: MC("#planks"),
		C: SP("steel_cogwheel"),
		D: F("#ingots/steel"),
	})
	event.recipes.extendedcrafting.shaped_table(SP("steel_flywheel"), [
		' DDD ',
		'DCBCD',
		'DBABD',
		'DCBCD',
		' DDD ',
	], {
		A: SP("cast_iron_flywheel"),
		B: MC("#planks"),
		C: SP("steel_cogwheel"),
		D: F("#ingots/steel"),
	})



	//steam engines
	event.remove({ output: CR("furnace_engine") })
	event.recipes.create.mechanical_crafting(CR("furnace_engine"), [
		'AAAAA',
		'A CBB',
		'AAAAA',
	], {
		A: F("#ingots/brass"),
		B: CR("fluid_pipe"),
		C: MC("sticky_piston"),
	})
	event.recipes.extendedcrafting.shaped_table(CR("furnace_engine"), [
		'AAAAA',
		'A CBB',
		'AAAAA',
	], {
		A: F("#ingots/brass"),
		B: CR("fluid_pipe"),
		C: MC("sticky_piston"),
	})
	event.recipes.create.mechanical_crafting(SP("bronze_steam_engine"), [
		'AAAAA',
		'A CBB',
		'AAAAA',
	], {
		A: F("#ingots/bronze"),
		B: CR("fluid_pipe"),
		C: CR("furnace_engine"),
	})
	event.recipes.extendedcrafting.shaped_table(SP("bronze_steam_engine"), [
		'AAAAA',
		'A CBB',
		'AAAAA',
	], {
		A: F("#ingots/bronze"),
		B: CR("fluid_pipe"),
		C: CR("furnace_engine"),
	})
	event.recipes.create.mechanical_crafting(SP("cast_iron_steam_engine"), [
		'AAAAA',
		'A CBB',
		'AAAAA',
	], {
		A: F("#ingots/cast_iron"),
		B: CR("fluid_pipe"),
		C: SP("bronze_steam_engine"),
	})
	event.recipes.extendedcrafting.shaped_table(SP("cast_iron_steam_engine"), [
		'AAAAA',
		'A CBB',
		'AAAAA',
	], {
		A: F("#ingots/cast_iron"),
		B: CR("fluid_pipe"),
		C: SP("bronze_steam_engine"),
	})
	event.recipes.create.mechanical_crafting(SP("steel_steam_engine"), [
		'AAAAA',
		'A CBB',
		'AAAAA',
	], {
		A: F("#ingots/steel"),
		B: CR("fluid_pipe"),
		C: SP("cast_iron_steam_engine"),
	})
	event.recipes.extendedcrafting.shaped_table(SP("steel_steam_engine"), [
		'AAAAA',
		'A CBB',
		'AAAAA',
	], {
		A: F("#ingots/steel"),
		B: CR("fluid_pipe"),
		C: SP("cast_iron_steam_engine"),
	})
	
	//extended crafting recipes for only mech crafted stuff
	event.recipes.extendedcrafting.shaped_table(SP('alternator'), [
		' ABA ',
		'ACDCA',
		'BCECB',
		'ACDCA',
		' ABA ',
	], {
		A: F('#ingots/cast_iron'),
		B: MC("redstone"),
		C: F("#plates/copper"),
		D: F("#ingots/iron"),
		E: CR("shaft"),
	})
})