/*onEvent(`recipes`, event => {
	event.custom({
    	type: 'tconstruct:casting_basin',
    	ingredients: [
      		Fluid.of('tconstruct:molten_lead', `1296mb`).toJson()
    	],
    	results: [
      		Item.of('emendatusenigmatica:lead_block').toResultJson(),
    	],
    	//processingTime: 100
  	})//.id(`tconstruct:smeltery/casting/metal/lead/block`)
}) */

events.listen('recipes', (event) => {

	/*

	 * Allows us to provide parameters for block casting recipes.

	 */

	const blockCast = (fluid, amount, result, time) =>

	{

		event.custom(

		{

			"type": 'tconstruct:casting_basin',

			"fluid":

			{

				"tag": fluid,

				"amount": amount

			},

			"result": result,

			"cooling_time": time

		})

	}

	/*

	 * Allows us to provide parameters for the casting table so we can nest functions and change multiple recipes with a single set of parameters fed in.

	 * Should work for at LEAST any of the nugget/ingot/plate casting recipes. YMMV on any others.

	 */

	const tableCast = (castType, castUse, fluid, amount, result, time) =>

	{

		event.custom(

		{

			"type": 'tconstruct:casting_table',

			"cast":

			{

				"tag": `tconstruct:casts/${castUse}/${castType}`

			},

			"fluid":

			{

				"tag": fluid,

				"amount": amount

			},

			"result": result,

			"cooling_time": time

		})

	}

	const itemMelt = (itemType, itemName, fluidResult, amount, temperature, time) =>

	{

		event.custom(

		{

			"type": "tconstruct:melting",

			"ingredient":

			{

				"tag": `forge:${itemType}/${itemName}`

			},

			"result":

			{

				"fluid": `${fluidResult}`,

				"amount": amount

			},

			"temperature": temperature,

			"time": time

		})

	}

	// Fun fact - all ores have SOME sort of byproduct when melted in the foundry. Probably makes this sillier than it needs to be.

	const oreMelt = (oreType, fluidResult1, amount1, fluidResult2, amount2, temperature, time) =>

	{

		event.custom(

		{

			"type": "tconstruct:ore_melting",

			"ingredient":

			{

				"tag": `forge:ores/${oreType}`

			},

			"result":

			{

				"fluid": `${fluidResult1}`,

				"amount": amount1

			},

			"temperature": temperature,

			"time": time,

			"byproducts":

			[

				{

					"fluid": fluidResult2,

					"amount": amount2

				}

			]

		})

	}

	const registerLiquidFuel = (fuelName, duration, temperature) =>

	{

		event.custom(

		{

			"type": "tconstruct:melting_fuel",

			"fluid":

			{

				"name": fuelName,

				"amount": 100

			},

			"duration": duration,

			"temperature": temperature

		})

	}

	const register2Alloy = (input1, amount1, input2, amount2, outputFluid, outputAmount, temperature) =>

	{

		event.custom(

		{

			"type": "tconstruct:alloy",

			"inputs":

			[

				{

					"tag": input1,

					"amount": amount1

				},

				{

					"tag": input2,

					"amount": amount2

				}

			],

			"result":

			{

				"fluid": outputFluid,

				"amount": outputAmount

			},

			"temperature": temperature

		})

	}

	const register3Alloy = (input1, amount1, input2, amount2, input3, amount3, outputFluid, outputAmount, temperature) =>

	{

		event.custom(

		{

			"type": "tconstruct:alloy",

			"inputs":

			[

				{

					"tag": input1,

					"amount": amount1

				},

				{

					"tag": input2,

					"amount": amount2

				},

				{

					"tag": input3,

					"amount": amount3

				}

	

			],

			"result":

			{

				"fluid": outputFluid,

				"amount": outputAmount

			},

			"temperature": temperature

		})

	}

	/*

	 * Creates all the necessary recipes for a particular metal. Assumes that casting nuggets is 8x as fast, casting ingots/plates is 4x as fast.

	 * Also assumes that this is only for blocks that contain 9 ingots, ingots that contain 9 nuggets.

	 */

	const unifyMetal = (metalName, blockTime) =>

	{

		// Clean out recipes we'll be replacing.

		event.remove({id: `tconstruct:smeltery/casting/metal/${metalName}/block`})

		event.remove({id: `tconstruct:smeltery/casting/metal/${metalName}/ingot_sand_cast`})

		event.remove({id: `tconstruct:smeltery/casting/metal/${metalName}/ingot_gold_cast`})

		event.remove({id: `tconstruct:smeltery/casting/metal/${metalName}/nugget_sand_cast`})

		event.remove({id: `tconstruct:smeltery/casting/metal/${metalName}/nugget_gold_cast`})

		event.remove({id: `tconstruct:smeltery/casting/metal/${metalName}/plate_sand_cast`})

		event.remove({id: `tconstruct:smeltery/casting/metal/${metalName}/plate_gold_cast`})

		// Replace recipes.

		//			castType,		castUse,		fluid,								amount,	result,										time

		tableCast(	'ingot', 		'multi_use',	`tconstruct:molten_${metalName}`,	144,	`emendatusenigmatica:${metalName}_ingot`,	blockTime / 4)

		tableCast(	'ingot', 		'single_use',	`tconstruct:molten_${metalName}`,	144,	`emendatusenigmatica:${metalName}_ingot`,	blockTime / 4)

		tableCast(	'plate', 		'single_use',	`tconstruct:molten_${metalName}`,	144,	`emendatusenigmatica:${metalName}_plate`,	blockTime / 4)

		tableCast(	'plate', 		'multi_use',	`tconstruct:molten_${metalName}`,	144,	`emendatusenigmatica:${metalName}_plate`,	blockTime / 4)

		tableCast(	'nugget',		'multi_use',	`tconstruct:molten_${metalName}`,	16,		`emendatusenigmatica:${metalName}_nugget`,	blockTime / 8)

		tableCast(	'nugget',		'single_use',	`tconstruct:molten_${metalName}`,	16,		`emendatusenigmatica:${metalName}_nugget`,	blockTime / 8)

		//			fluid,								amount,	result,										time

		blockCast(	`tconstruct:molten_${metalName}`,	1296,	`emendatusenigmatica:${metalName}_block`,	blockTime)

	}		

	const unifyGem = (gemName, blockTime, liquidName, liquidTag) =>

	{

		// Clean out recipes being replaced. Note that non-stock gem recipes are provided by Tinkers' Better Compatibility.

		// Diamond/emerald are special cases, and will be built separately if needed.

		// It's assumed that the byproduct of all gemstone types will be quartz. I could probably make this take an extra parameter if I *really* wanted to, but it'll make things messier.

		event.remove({id: `bettercompat:smeltery/casting/${gemName}`})

		event.remove({id: `bettercompat:smeltery/casting/${gemName}_bn`})		// wtf bettercompat

		event.remove({id: `bettercompat:smeltery/casting/${gemName}_sand`})

		event.remove({id: `bettercompat:smeltery/casting/${gemName}_block`})

		// Replace recipes.

		// tableCast()

		//			castType,		castUse,		fluid,			amount,		result,									time

		tableCast(	'gem',			'multi_use',	liquidTag,		144,		`emendatusenigmatica:${gemName}_gem`,	blockTime / 8)

		tableCast(	'gem',			'single_use',	liquidTag,		144,		`emendatusenigmatica:${gemName}_gem`,	blockTime / 8)

		// blockCast()

		//			fluid,			amount,		result,										time

		blockCast(	liquidTag,		1296,		`emendatusenigmatica:${gemName}_block`,		blockTime)

		// itemMelt()

		//			itemType,	itemName,		fluidResult,	amount,		temperature,	time

		itemMelt(	`gems`,		`${gemName}`,	liquidName,		144,		1000,			blockTime / 8)

		// oreMelt()

		//			oreType,			fluidResult1,		amount1,	fluidResult2,						amount2,		temperature,	time

		oreMelt(	`${gemName}`,		liquidName,			144,		'tconstruct:molten_quartz',			16,				1000,			blockTime / 4)

	}

	

	// Unify metals

	unifyMetal(`aluminum`, 200)

	unifyMetal(`brass`, 200)

	unifyMetal('bronze', 200)

	unifyMetal('cobalt', 200)

	unifyMetal('constantan', 200)

	unifyMetal('copper', 200)

	unifyMetal('electrum', 200)

	unifyMetal('enderium', 200)

	unifyMetal('invar', 200)

	unifyMetal('lead', 200)

	unifyMetal('lumium', 200)

	unifyMetal('nickel', 200)

	unifyMetal('signalum', 200)

	unifyMetal('silver', 200)

	unifyMetal('tin', 200)

	unifyMetal(`uranium`, 200)

	unifyMetal(`zinc`, 200)

	// Unify gems

	unifyGem('sapphire', 200, 'bettercompat:molten_sapphire', 'bettercompat:molten_sapphire')

	unifyGem('ruby', 200, 'bettercompat:molten_ruby', 'bettercompat:molten_ruby')

	unifyGem('peridot', 200, 'emendatusenigmatica:molten_peridot', 'forge:molten_peridot')

	// Special case: Redstone

	// Thermal defines redstone as 100mb/dust, 900mb/block. TODO: Do work to unify redstone.

	oreMelt( 'redstone', 'emendatusenigmatica:molten_redstone', 144, 'tconstruct:molten_quartz', 16, 1000, 200 / 4)

	itemMelt( 'dusts', 'redstone', 'emendatusenigmatica:molten_redstone', 144, 1000, 200 / 8)

	tableCast( 'gem', 'multi_use', 'forge:molten_redstone', 144, 'minecraft:redstone', 200 / 8)

	tableCast( 'gem', 'single_use', 'forge:molten_redstone', 144, 'minecraft:redstone', 200 / 8)

	blockCast( 'forge:molten_redstone', 1296, 'minecraft:redstone_block', 200)

	// ugh need to do this the REALLY hard way

	event.remove( {id: 'tconstruct:smeltery/alloys/molten_signalum'} )

	event.remove( {id: 'thermal:machine/chiller/chiller_redstone_to_redstone_block'} )

	event.remove( {id: 'thermal:machine/crucible/crucible_redstone_block'} )

	event.remove( {id: 'thermal:machine/crucible/crucible_redstone_dust'} )

	// Rebuilt recipes for thermal + alloying

	// Note: Might as well unify this to 144mb/gem since I'm rebuilding them all anyway. :V

		// tcon alloy: 3 ingots copper, 1 ingot silver, 4 ingots redstone = 4 ingots signalum

	

	event.recipes.thermal.crucible(Fluid.of('emendatusenigmatica:molten_redstone', 1296), 'minecraft:redstone_block').energy(72000)

	event.recipes.thermal.crucible(Fluid.of('emendatusenigmatica:molten_redstone', 144), 'minecraft:redstone').energy(8000)

	event.recipes.thermal.chiller('minecraft:redstone_block', Fluid.of('emendatusenigmatica:molten_redstone', 1296)).energy(72000)

	// welp. It works at least...

	register3Alloy('forge:molten_copper', 432, 'forge:molten_silver', 144, 'forge:molten_redstone', 576, 'tconstruct:molten_signalum', 576, 1000)


	//remove osmium
	event.remove( {id: 'tconstruct:smeltery/melting/metal/osmium/ore'} )


	//IE Steel Block
	blockCast(	`tconstruct:molten_steel`,	1296,	`immersiveengineering:storage_steel`,	200)

})

onEvent('tags.fluids', event => {

// Just in case. Going to do this the hard way for now. :(

});