//ABOE scripts | All Rights Reserved unless otherwise explicitly stated.
//
//Information.
//Credit to orignal author benbenlaw who developed this script for the Techopolis pack.
//Scripted by Predundant
//Last edited by predundant 01.08.2022 (EU date format) (Added branding, added license, added quartz tags to byg quartz).
//Last edited by predundant 04.08.2022 (EU date format) (Fixed casts and dies being consumed by the thermal press).
//Last edited by <name> <date> (EU date format) (Changelog).


//priority: 1000

//if (name !== 'iron' && name !== 'gold' && name !== 'azure_silver' && name !== 'crimson_iron') 

const ingots = {};
const plates = {};
const nuggets = {};
const blocks = {};
const dusts = {};
const gears = {};



//Modify Tags
onEvent('tags.items', event => {
//add each of the Create dusts to corresponding forge dust tags so the script effects them	
  event.add('forge:dusts/iron', 'create:crushed_iron_ore')
  event.add('forge:dusts/gold', 'create:crushed_gold_ore')  
  event.add('forge:dusts/copper', 'create:crushed_copper_ore')
  event.add('forge:dusts/zinc', 'create:crushed_zinc_ore')  
  event.add('forge:dusts/brass', 'create:crushed_brass')
  event.add('forge:dusts/osmium', 'create:crushed_osmium_ore')  
  event.add('forge:dusts/platinum', 'create:crushed_platinum_ore')    
  event.add('forge:dusts/silver', 'create:crushed_silver_ore')    
  event.add('forge:dusts/tin', 'create:crushed_tin_ore')    
  event.add('forge:dusts/lead', 'create:crushed_lead_ore')  
  event.add('forge:dusts/aluminum', 'create:crushed_aluminum_ore')  
  event.add('forge:dusts/uranium', 'create:crushed_uranium_ore')  
  event.add('forge:dusts/nickel', 'create:crushed_nickel_ore')  
  event.add('forge:gems/quartz', 'byg:quartz_crystal') 
  
//add various casts and dyes to the proper tags
	event.add('thermal:crafting/dies', 'immersiveengineering:mold_gear')  
	event.add('thermal:crafting/dies', 'immersiveengineering:mold_rod')  
	event.add('thermal:crafting/dies', '#tconstruct:casts')  
	
    
})



onEvent('recipes', e => {

//(unifiedname, ingot, dust, block, nugget, tinkers_ingot_cool_time, plate, ore)
function unifyTheWorld(name, ingot, dust, block, nugget, coolTime, plate, gear, ore){
    
    e.replaceOutput(`#forge:ingots/${name}`, ingot)
    e.replaceOutput(`#forge:dusts/${name}`, dust)
    e.replaceOutput(`#forge:nuggets/${name}`, nugget)
    e.replaceOutput(`#forge:storage_blocks/${name}`, block)
    e.replaceOutput(`#forge:plates/${name}`, plate)

    e.replaceInput(`#forge:nuggets/${name}`, nugget)
    e.replaceInput(`#forge:dusts/${name}`, dust)
    e.replaceInput(`#forge:ingots/${name}`, ingot)
    e.replaceInput(`#forge:storage_blocks/${name}`, block)
	e.replaceInput(`#forge:plates/${name}`, plate)

//Blocks-Ingots-Nuggets

if (!Ingredient.of(block).empty && name !== 'quartz') {
e.shaped(block, ['III','III','III'], {I: ingot})
e.shapeless(`9x ${ingot}`, block)
}

if (!Ingredient.of(nugget).empty) {
e.shaped(ingot, ['III','III','III'], {I: nugget})
e.shapeless(`9x ${nugget}`, ingot)
}

e.remove({type: 'minecraft:crafting_shaped', output: block})
e.remove({type: 'minecraft:crafting_shaped', output: ingot})
e.remove({type: 'minecraft:crafting_shaped', output: nugget})
e.remove({type: 'minecraft:crafting_shapeless', output: block})
e.remove({type: 'minecraft:crafting_shapeless', output: ingot})
e.remove({type: 'minecraft:crafting_shapeless', output: nugget})

//Crusher Fix

if (!Ingredient.of(dust).empty) {
e.remove({input: `#forge:ores/${name}`, type: 'immersiveengineering:crusher'})
e.remove({input: `#forge:ingots/${name}`, type: 'immersiveengineering:crusher'})
e.recipes.immersiveengineering.crusher(dust, ingot) 
}
if (!Ingredient.of(dust).empty && !Ingredient.of(ore).empty) {
e.recipes.immersiveengineering.crusher(`2x ${dust}`, `#forge:ores/${name}`)
}

//Tinkers Fix (Blocks, Ingots, Nuggets)

if (name !== 'sulfur' && name !== 'coal' && name !== 'lapis' && name !== 'ruby' && name !== 'sapphire' && name !== 'tungsten'&& name !== 'draconium' && name !== 'iridium' && name !== 'quartz') {
e.custom({type: 'tconstruct:casting_basin', fluid : { name : `tconstruct:molten_${name}`, amount : 1296}, result : block, cooling_time : coolTime*3}).id(`tconstruct:smeltery/casting/metal/${name}/block`)
}
if (name !== 'ruby' && name !== 'sulfur' && name !== 'coal' && name !== 'iridium' && name !== 'sapphire'&& name !== 'draconium' && name !== 'quartz' && name !== 'lapis') { 
e.custom({type: 'tconstruct:casting_table',"cast": {tag: 'tconstruct:casts/single_use/ingot'}, cast_consumed : true, fluid: {name : `tconstruct:molten_${name}`, amount : 144}, result: ingot ,cooling_time: coolTime}).id(`tconstruct:smeltery/casting/metal/${name}/ingot_sand_cast`)
e.custom({type: 'tconstruct:casting_table',"cast": {tag: 'tconstruct:casts/multi_use/ingot'}, fluid: {name : `tconstruct:molten_${name}`, amount : 144}, result: ingot ,cooling_time: coolTime}).id(`tconstruct:smeltery/casting/metal/${name}/ingot_gold_cast`)
}
if (!Ingredient.of(nugget).empty && name !== 'draconium' && name !== 'iridium') {
e.custom({type: 'tconstruct:casting_table',"cast": {tag: 'tconstruct:casts/single_use/nugget'}, cast_consumed : true, fluid: {name : `tconstruct:molten_${name}`, amount : 16}, result: nugget ,cooling_time: coolTime/3}).id(`tconstruct:smeltery/casting/metal/${name}/nugget_sand_cast`)
e.custom({type: 'tconstruct:casting_table',"cast": {tag: 'tconstruct:casts/multi_use/nugget'}, fluid: {name : `tconstruct:molten_${name}`, amount : 16}, result: nugget ,cooling_time: coolTime/3}).id(`tconstruct:smeltery/casting/metal/${name}/nugget_gold_cast`)
}
e.remove({id: `tconstruct:smeltery/casting/metal/${name}/plate_gold_cast`})
e.remove({id: `tconstruct:smeltery/casting/metal/${name}/plate_sand_cast`})


//Thermal Fix

if (!Ingredient.of(block).empty) {
e.remove({id: `thermal:machine/centrifuge/centrifuge_${name}_dust`})
e.remove({id: `thermal:machine/smelter/smelter_${name}_dust`})
e.remove({id: `thermal:machine/smelter/smelter_${name}_ore`})
e.remove({id: `thermal:machine/pulverizer/pulverizer_${name}_ore`})
e.recipes.thermal.pulverizer(dust, ingot).id(`thermal:machine/pulverizer/pulverizer_${name}_ingot_to_dust`)

if (name !== 'quartz') {
e.recipes.thermal.press(`9x ${ingot}`, [block, 'thermal:press_unpacking_die']).id(`thermal:machine/press/unpacking/press_${name}_unpacking`)
}
if (name !== 'quartz') {
e.recipes.thermal.press(block, [`9x ${ingot}`, 'thermal:press_packing_3x3_die']).id(`thermal:machine/press/packing3x3/press_${name}_packing`)
}
if (name !== 'quartz' && name !== 'coal' && name !== 'sulfur' && name !== 'sapphire' && name !== 'lapis' && name !== 'ruby') {
e.recipes.thermal.chiller(ingot, [Fluid.of(`tconstruct:molten_${name}`, 144), '#tconstruct:casts/multi_use/ingot']).energy(5000).id(`thermal:compat/tconstruct/chiller_tconstruct_${name}_ingot`)
}
}

//Remove create sheet recipes
e.remove({output: '#forge:plates', type: 'create:pressing'})


//Plate Unification
if (!Ingredient.of(plate).empty) {
e.recipes.immersiveengineeringMetalPress(plate, ingot, 'immersiveengineering:mold_plate').id(`immersiveengineering:metalpress/plate_${name}`)
e.recipes.thermal.press(plate, ingot).id(`thermal:machine/press/press_${name}_ingot_to_plate`)
e.recipes.createPressing(plate, ingot).id(`thermal:machine/press/press_${name}_ingot_to_plate`)

}

//Gear Unification

if (!Ingredient.of(gear).empty) {
//e.remove({id: `thermal:parts/${name}_gear`})
e.recipes.immersiveengineeringMetalPress(gear, `4x ${ingot}`, ['#tconstruct:casts/multi_use/gear', 'immersiveengineering:mold_gear']).id(`immersiveengineering:metalpress/gear_${name}`)
e.recipes.thermal.press(gear, [`4x ${ingot}`, ['#tconstruct:casts/multi_use/gear', 'immersiveengineering:mold_gear']]).id(`thermal:machine/press/press_${name}_ingot_to_gear`)
}

//Dusts to Ingots

if (!Ingredient.of(dust).empty) {
e.recipes.mekanism.smelting(ingot, dust).id(`mekanism:smelting_${name}_mekanism`)
e.recipes.thermal.furnace(ingot, dust).id(`mekanism:smelting_${name}_mekanism`)
}

//Ores

if (!Ingredient.of(ore).empty) {
e.recipes.thermal.pulverizer(`2x ${dust}`, ore).id(`mekanism:crushing_${name}_mekansim`)
}

//Mek Crusher dusts

if (!Ingredient.of(dust).empty) {
e.recipes.mekanism.crushing(dust, ingot) 
}





//

e.remove({id: `mekanism:processing/${name}/ore/from_dust`})
e.remove({id: `mekanism:processing/${name}/ore/nether_from_dust`})
e.remove({id: `mekanism:processing/lapis_lazuli/to_ore`})
e.remove({id: `mekanism:processing/diamond/to_ore`})
e.remove({id: `mekanism:processing/emerald/to_ore`})
e.remove({id: `mekanism:processing/quartz/to_ore`})
e.remove({id: `mekanism:processing/fluorite/to_ore`})
e.remove({id: `mekanism:processing/redstone/to_ore`})
e.remove({id: `mekanism:processing/netherite/dust_to_ancient_debris`})
e.remove({id: `thermal:compat/mekanism/pulverizer_mek_osmium_ore`})

//Input Unify

ingots[`${name}`] = ingot
plates[`${name}`] = plate
nuggets[`${name}`] = nugget
dusts[`${name}`] = dust
blocks[`${name}`] = block
gears[`${name}`] = gear

}

//Has Ores

unifyTheWorld('gold', 'minecraft:gold_ingot', 'mekanism:dust_gold', 'minecraft:gold_block', 'minecraft:gold_nugget', 57, 'thermal:gold_plate', 'thermal:gold_gear', '#forge:ores/gold')
unifyTheWorld('iron', 'minecraft:iron_ingot', 'mekanism:dust_iron', 'minecraft:iron_block', 'minecraft:iron_nugget', 60, 'thermal:iron_plate', 'thermal:iron_gear', '#forge:ores/iron')
unifyTheWorld('tin', 'mekanism:ingot_tin', 'mekanism:dust_tin', 'mekanism:block_tin', 'mekanism:nugget_tin', 39,'thermal:tin_plate', 'thermal:tin_gear', '#forge:ores/tin')
unifyTheWorld('copper', 'mekanism:ingot_copper', 'mekanism:dust_copper', 'mekanism:block_copper', 'mekanism:nugget_copper', 50, 'thermal:copper_plate', 'thermal:copper_gear', '#forge:ores/copper')
unifyTheWorld('lead', 'mekanism:ingot_lead', 'mekanism:dust_lead', 'mekanism:block_lead', 'mekanism:nugget_lead', 50, 'thermal:lead_plate', 'thermal:lead_gear', '#forge:ores/lead')
unifyTheWorld('osmium', 'mekanism:ingot_osmium', 'mekanism:dust_osmium', 'mekanism:block_osmium', 'mekanism:nugget_osmium', 66, '', '', '#forge:ores/osmium') //missing plate and gear
unifyTheWorld('uranium', 'mekanism:ingot_uranium', 'mekanism:dust_uranium', 'mekanism:block_uranium', 'mekanism:nugget_uranium', 61, 'immersiveengineering:plate_uranium', '', '#forge:ores/uranium') //missing plate and gear

unifyTheWorld('silver', 'thermal:silver_ingot', 'thermal:silver_dust', 'thermal:silver_block', 'thermal:silver_nugget', 60, 'thermal:silver_plate', 'thermal:silver_gear', '#forge:ores/silver')

unifyTheWorld('nickel', 'thermal:nickel_ingot', 'thermal:nickel_dust', 'thermal:nickel_block', 'thermal:nickel_nugget', 65, 'thermal:nickel_plate', 'thermal:nickel_gear', '#forge:ores/nickel')

unifyTheWorld('aluminum', 'immersiveengineering:ingot_aluminum', 'immersiveengineering:dust_aluminum', 'immersiveengineering:storage_aluminum', 'immersiveengineering:nugget_aluminum', 43, 'immersiveengineering:plate_aluminum', '', '#forge:ores/aluminum')

unifyTheWorld('zinc', 'moremekanismprocessing:zinc_ingot', 'moremekanismprocessing:dust_zinc', 'create:zinc_block', 'moremekanismprocessing:zinc_nugget', 47, 'createaddition:zinc_sheet', '', '#forge:ores/zinc')
//unifyTheWorld('platinum', 'moremekanismprocessing:platinum_ingot', 'moremekanismprocessing:dust_platinum', '', 'moremekanismprocessing:platinum_nugget', 47, '', '', '#forge:ores/platinum') // missing block, gear, plate

unifyTheWorld('diamond', 'minecraft:diamond', 'mekanism:dust_diamond', 'minecraft:diamond_block', '', 67, '', 'thermal:diamond_gear', '#forge:ores/diamond') // missing plate
unifyTheWorld('emerald', 'minecraft:emerald', 'mekanism:dust_emerald', 'minecraft:emerald_block', '', 67, '', 'thermal:emerald_gear', '#forge:ores/emerald') // missing plate


unifyTheWorld('sulfur','thermal:sulfur', 'thermal:sulfur_dust', 'thermal:sulfur_block', '', '', '', 'thermal:sapphire_gear', '#forge:ores/sulfur')
unifyTheWorld('coal','minecraft:coal', 'mekanism:dust_coal', 'minecraft:coal_block', '', '', '', '', '#forge:ores/coal')
unifyTheWorld('lapis','minecraft:lapis_lazuli', 'mekanism:dust_lapis_lazuli', 'minecraft:lapis_block', '', '', '', 'thermal:lapis_gear', '#forge:ores/lapis')
unifyTheWorld('quartz','minecraft:quartz', 'mekanism:dust_quartz', 'minecraft:quartz_block', '55', '', '', 'thermal:quartz_gear', '#forge:ores/quartz')

unifyTheWorld('cobalt', 'tconstruct:cobalt_ingot', 'moremekanismprocessing:dust_cobalt', 'tconstruct:cobalt_block', 'tconstruct:cobalt_nugget', 65, '', '', '#forge:ores/cobalt')

//unifyTheWorld('tungsten', 'moremekanismprocessing:tungsten_ingot', 'moremekanismprocessing:dust_tungsten', '', 'moremekanismprocessing:tungsten_nugget', 65, '', '', '#forge:ores/tungsten')
unifyTheWorld('draconium', 'moremekanismprocessing:draconium_ingot', 'moremekanismprocessing:dust_draconium', 'draconicevolution:draconium_block', 'moremekanismprocessing:draconium_nugget', 65, '', '', '#forge:ores/draconium')
//unifyTheWorld('iridium', 'moremekanismprocessing:iridium_ingot', 'moremekanismprocessing:dust_iridium', '', 'moremekanismprocessing:iridium_nugget', 65, '', '', '#forge:ores/iridium')

//Alloys
unifyTheWorld('brass', 'create:brass_ingot', 'create:crushed_brass', 'create:brass_block', 'create:brass_nugget', 57, 'create:brass_sheet', '', '')
unifyTheWorld('bronze', 'mekanism:ingot_bronze', 'mekanism:dust_bronze', 'mekanism:block_bronze', 'mekanism:nugget_bronze', 57, 'thermal:bronze_plate', 'thermal:bronze_gear', '')
unifyTheWorld('steel', 'mekanism:ingot_steel', 'mekanism:dust_steel', 'mekanism:block_steel', 'mekanism:nugget_steel', 65, 'immersiveengineering:plate_steel', '')

unifyTheWorld('invar', 'thermal:invar_ingot', 'thermal:invar_dust', 'thermal:invar_block', 'thermal:invar_nugget', 63, 'thermal:invar_plate', 'thermal:invar_gear', '')
unifyTheWorld('constantan', 'thermal:constantan_ingot', 'thermal:constantan_dust', 'thermal:constantan_block', 'thermal:constantan_nugget', 64, 'thermal:constantan_plate', 'thermal:constantan_gear', '')
unifyTheWorld('electrum', 'thermal:electrum_ingot', 'thermal:electrum_dust', 'thermal:electrum_block', 'thermal:electrum_nugget', 59, 'thermal:electrum_plate', 'thermal:electrum_gear', '')
unifyTheWorld('signalum', 'thermal:signalum_ingot', 'thermal:signalum_dust', 'thermal:signalum_block', 'thermal:signalum_nugget', 70, 'thermal:signalum_plate', 'thermal:signalum_gear', '')
unifyTheWorld('lumium', 'thermal:lumium_ingot', 'thermal:lumium_dust', 'thermal:lumium_block', 'thermal:lumium_nugget', 68, 'thermal:lumium_plate', 'thermal:lumium_gear', '')
unifyTheWorld('enderium', 'thermal:enderium_ingot', 'thermal:enderium_dust', 'thermal:enderium_block', 'thermal:enderium_nugget', 76, 'thermal:enderium_plate', 'thermal:enderium_gear', '')



unifyTheWorld('ruby','thermal:ruby', 'thermal:ruby_dust', 'thermal:ruby_block', '', '', '', 'thermal:ruby_gear', '')
unifyTheWorld('sapphire','thermal:sapphire', 'thermal:sapphire_dust', 'thermal:sapphire_block', '', '', '', 'thermal:sapphire_gear', '')
//unifyTheWorld('biotite','quark:biotite', '', 'quark:biotite_block', '', '', '', '', 'forge:ores/biotite')



//Misc

//e.recipes.immersiveengineering.crusher('2x immersiveengineering:dust_coke', '#forge:coke_coal') 
//e.recipes.immersiveengineering.crusher('appliedenergistics2:fluix_dust', 'appliedenergistics2:fluix_crystal') 
//e.recipes.immersiveengineering.crusher('appliedenergistics2:certus_quartz_dust', 'appliedenergistics2:certus_quartz_crystal')
//e.recipes.immersiveengineering.crusher('2x quark:biotite', '#forge:ores/biotite')
 
//e.recipes.immersiveengineering.crusher('appliedenergistics2:flour', 'minecraft:wheat') 
//e.recipes.thermal.pulverizer('appliedenergistics2:flour', 'minecraft:wheat') 


//e.recipes.mekanism.enriching('appliedenergistics2:flour', 'minecraft:wheat') 

//e.recipes.immersiveengineering.crusher('2x fluxnetworks:flux_dust','mekanism:teleportation_core') 
//e.recipes.thermal.pulverizer('2x fluxnetworks:flux_dust', 'mekanism:teleportation_core') 
//e.recipes.mekanism.enriching('2x fluxnetworks:flux_dust', 'mekanism:teleportation_core') 
//e.recipes.mekanism.enriching('2x quark:biotite', '#forge:ores/biotite') 

//e.recipes.mekanism.crushing('2x immersiveengineering:dust_coke', '#forge:coal_coke') 
//e.recipes.mekanism.crushing('2x immersiveengineering:dust_coke', '#forge:coke_coal') 
//e.recipes.thermal.pulverizer('2x immersiveengineering:dust_coke', '#forge:coal_coke') 
//e.recipes.thermal.pulverizer('2x immersiveengineering:dust_coke', '#forge:coke_coal') 
//e.recipes.thermal.pulverizer('2x quark:biotite', '#forge:ores/biotite') 

e.recipes.immersiveengineeringAlloy('4x mekanism:block_bronze', '3x mekanism:block_copper', 'mekanism:block_tin')
e.recipes.immersiveengineeringAlloy('4x tconstruct:rose_gold_block', '3x mekanism:block_copper', 'minecraft:gold_block')
e.recipes.immersiveengineeringAlloy('3x thermal:invar_block', '2x minecraft:iron_block', 'thermal:nickel_block')
e.recipes.immersiveengineeringAlloy('2x thermal:electrum_block', 'minecraft:gold_block', 'thermal:silver_block')
e.recipes.immersiveengineeringAlloy('2x thermal:constantan_block', 'mekanism:block_copper', 'thermal:nickel_block')
e.recipes.immersiveengineeringAlloy('4x mekanism:ingot_bronze', 'mekanism:ingot_tin', '3x mekanism:ingot_copper').id('immersiveengineering:alloysmelter/bronze')

//alloy dusts
e.replaceOutput('#forge:dusts/bronze', 'mekanism:dust_bronze')
e.replaceOutput('#forge:dusts/constantan', 'thermal:constantan_dust')


//sawdust
e.replaceOutput('#forge:dusts/wood', 'thermal:sawdust')
e.replaceOutput('#forge:sawdust', 'thermal:sawdust')
e.replaceInput('#forge:dusts/wood', 'thermal:sawdust')
e.replaceInput('#forge:sawdust', 'thermal:sawdust')


//chests
e.replaceInput('minecraft:chest', '#forge:chests/wooden')

//ender pearl dusts
e.replaceInput('thermal:ender_pearl_dust', '#forge:dusts/ender_pearl')
e.replaceInput('appliedenergistics2:ender_dust', '#forge:dusts/ender_pearl')

//e.shapeless('2x refinedstorage:quartz_enriched_iron', 'refinedstorage:quartz_enriched_iron_block')

//Remove create bulk washing dust recipes (duplication loop)
e.remove({input: '#forge:dusts', type: 'create:splashing'})

//Rods
function rods(rods, rodIngots) {
    e.recipes.thermal.press(`2x ${rods}`, [rodIngots, 'immersiveengineering:mold_rod'])
    }
    
    rods ('immersiveengineering:stick_aluminum', '#forge:ingots/aluminum')
    rods ('immersiveengineering:stick_steel', '#forge:ingots/steel')
    rods ('immersiveengineering:stick_iron', '#forge:ingots/iron')

})


//silver (thermal alloyies)

/*JEI

onEvent('jei.add.items', e => {
	e.add([gear, block, dust, nugget, plate, ingot])
})

*/