// Kubejs scripts for extended crafting recipes

ServerEvents.recipes(event => {

// Helper Function for EnderIO alloy smelting
function eioAlloySmelt(output, in1, quant1, in2, quant2, in3, quant3, energy, exp) {
	event.custom({
	"type": "enderio:alloy_smelting",
	"energy": energy,
	"experience": exp,
	"inputs": [
		{
		"count": quant1,
		"ingredient": {
        "item": in1
		}
	  },
	  {
		"count": quant2,
		"ingredient": {
			"item": in2
		}
	  },
	  {
		"count": quant3,
		"ingredient": {
			"item": in3
		}
	  }
	],
	"result": {
		"item": output
	}
  })
}	

//Implement prismatter
event.recipes.extendedcrafting.combination("kubejs:prismatter", '#kubejs:red_matter',
['thermal:enderium_gear', 'ae2:cell_component_16k','pneumaticcraft:security_upgrade','enderio:octadic_capacitor','immersiveengineering:heavy_engineering','create:sturdy_sheet','create_new_age:copper_circuit','mekanism:hdpe_sheet','extendedcrafting:advanced_component','ars_nouveau:thread_magic_capacity','bloodmagic:sacrificerune','botania:rune_winter','malum:spirit_fabric','embers:dawnstone_aspectus'], 
 20000000).powerRate(50000);
 
 // Remove standard crafting for ext alloys
event.remove({ output: 'extendedcrafting:black_iron_ingot'})
event.remove({ output: 'extendedcrafting:redstone_ingot'})
event.remove({ output: 'extendedcrafting:ender_ingot'})

event.remove({ output: 'extendedcrafting:luminessence'})
event.remove({ output: 'extendedcrafting:black_iron_slate'})

// No Default part recipes
event.remove({ output: 'extendedcrafting:basic_component'})
event.remove({ output: 'extendedcrafting:advanced_component'})
event.remove({ output: 'extendedcrafting:elite_component'})
event.remove({ output: 'extendedcrafting:ultimate_component'})
event.remove({ output: 'extendedcrafting:redstone_component'})
event.remove({ output: 'extendedcrafting:enhanced_redstone_component'})
event.remove({ output: 'extendedcrafting:ender_component'})
event.remove({ output: 'extendedcrafting:enhanced_ender_component'})
event.remove({ output: 'extendedcrafting:crystaltine_component'})
event.remove({ output: 'extendedcrafting:the_ultimate_component'})

event.remove({ output: 'extendedcrafting:basic_catalyst'})
event.remove({ output: 'extendedcrafting:advanced_catalyst'})
event.remove({ output: 'extendedcrafting:elite_catalyst'})
event.remove({ output: 'extendedcrafting:ultimate_catalyst'})
event.remove({ output: 'extendedcrafting:redstone_catalyst'})
event.remove({ output: 'extendedcrafting:enhanced_redstone_catalyst'})
event.remove({ output: 'extendedcrafting:ender_catalyst'})
event.remove({ output: 'extendedcrafting:enhanced_ender_catalyst'})
event.remove({ output: 'extendedcrafting:crystaltine_catalyst'})
event.remove({ output: 'extendedcrafting:the_ultimate_catalyst'})

// No Tables
event.remove({ output: 'extendedcrafting:basic_table'})
event.remove({ output: 'extendedcrafting:advanced_table'})
event.remove({ output: 'extendedcrafting:elite_table'})
event.remove({ output: 'extendedcrafting:ultimate_table'})
event.remove({ output: 'extendedcrafting:crafting_core'})
event.remove({ output: 'extendedcrafting:pedestal'})
event.remove({ output: 'extendedcrafting:compressor'})

event.remove({ output: 'extendedcrafting:frame'})

// PackagedEX
event.remove({ output: 'packagedexcrafting:basic_crafter'})
event.remove({ output: 'packagedexcrafting:advanced_crafter'})
event.remove({ output: 'packagedexcrafting:elite_crafter'})
event.remove({ output: 'packagedexcrafting:ultimate_crafter'})
event.remove({ output: 'packagedexcrafting:combination_crafter'})
event.remove({ output: 'packagedexcrafting:ender_crafter'})
event.remove({ output: 'packagedexcrafting:flux_crafter'})

// Luminessence 
event.recipes.ars_nouveau.imbuement(
        'ars_nouveau:source_gem', // input item
        'extendedcrafting:luminessence', // output
        4000, // source cost
        ['botania:pixie_dust', 'bloodmagic:defaultcrystal', 'embers:glimmer_crystal', 'malum:iridescent_ether']
)

// Dark Matter Alloy
event.custom({
  "type": "enderio:alloy_smelting",
  "energy": 10000,
  "experience": 0.77,
  "inputs": [
    {
      "count": 1,
      "ingredient": {
        "tag": "kubejs:dark_matter"
      }
    },
    {
      "count": 1,
      "ingredient": {
        "tag": "forge:ingots/dark_steel"
      }
    },
    {
      "count": 1,
      "ingredient": {
        "item": "mekanism:ingot_refined_obsidian"
      }
    }
  ],
  "result": {
    "item": "extendedcrafting:black_iron_ingot"
  }
})

// Block decompressing
event.shapeless(
  Item.of('9x extendedcrafting:black_iron_ingot'),
  [
    'extendedcrafting:black_iron_block'
  ]
)

// Dark Alloy Plate
event.recipes.thermal.press('extendedcrafting:black_iron_slate', ['extendedcrafting:black_iron_ingot']).energy(48000)

// Basic and Advanced components
eioAlloySmelt('extendedcrafting:basic_component', 'extendedcrafting:black_iron_slate', 1, 'extendedcrafting:luminessence', 1, 'projecte:dark_matter', 1, 20000, 0.3)
eioAlloySmelt('extendedcrafting:basic_component', 'extendedcrafting:black_iron_slate', 1, 'extendedcrafting:luminessence', 1, 'kubejs:emc_dark_matter', 1, 20000, 0.3)
eioAlloySmelt('extendedcrafting:advanced_component', 'extendedcrafting:black_iron_slate', 1, 'extendedcrafting:luminessence', 1, 'projecte:red_matter', 1, 20000, 0.3)
eioAlloySmelt('extendedcrafting:advanced_component', 'extendedcrafting:black_iron_slate', 1, 'extendedcrafting:luminessence', 1, 'kubejs:emc_red_matter', 1, 20000, 0.3)

// Basic Table
event.shaped(
  Item.of('extendedcrafting:basic_table'),
  [
    'ABA',
    'CDC',
    'ABA'
  ],
  {
    A: 'extendedcrafting:black_iron_ingot',
    B: 'extendedcrafting:black_iron_slate',
	C: 'extendedcrafting:basic_component',
	D: 'minecraft:crafting_table'
  }
)

// Red Matter
event.recipes.extendedcrafting.shaped_table("projecte:red_matter", 
	['aaa', 
	 'aba', 
	 'aaa'
	 ], 
	{
		a: 'projecte:aeternalis_fuel_block',
		b: 'projecte:dark_matter_block'
	}
).tier(1);

// Advanced Table
event.shaped(
  Item.of('extendedcrafting:advanced_table'),
  [
    'ABA',
    'CDC',
    'ABA'
  ],
  {
    A: 'extendedcrafting:black_iron_ingot',
    B: 'extendedcrafting:black_iron_slate',
	C: 'extendedcrafting:advanced_component',
	D: 'minecraft:crafting_table'
  }
)

// Dark Alloy frame
event.recipes.extendedcrafting.shaped_table("extendedcrafting:frame", 
	['abcba', 
	 'bdfdb', 
	 'cgehc',
	 'bdidb',
	 'abcba'
	 ], 
	{
		a: 'extendedcrafting:black_iron_slate',
		b: 'mekanism:alloy_atomic',
		c: 'mekanism:ingot_uranium',
		d: 'thermal:obsidian_glass',
		e: 'extendedcrafting:advanced_component',
		f: 'create:brass_casing',
		g: 'mekanism:steel_casing',
		h: 'enderio:void_chassis',
		i: 'thermal:machine_frame'
	}
).tier(2);

// Crafting Core
event.recipes.extendedcrafting.shaped_table("extendedcrafting:crafting_core", 
	['abcba', 
	 'bdedb', 
	 'cghic',
	 'bdfdb',
	 'abcba'
	 ], 
	{
		a: 'enderio:dark_bimetal_gear',
		b: 'extendedcrafting:black_iron_ingot',
		c: 'extendedcrafting:advanced_component',
		d: 'create:mechanical_arm',
		e: 'embers:beam_cannon',
		f: 'botania:runic_altar',
		g: 'thermal:machine_smelter',
		h: 'extendedcrafting:frame',
		i: 'enderio:alloy_smelter'
	}
).tier(2);

// Pedestal
event.recipes.extendedcrafting.shaped_table("extendedcrafting:pedestal", 
	[' aaa ', 
	 ' bcb ', 
	 ' ded ',
	 ' fgf ',
	 'fhihf'
	 ], 
	{
		a: 'ars_nouveau:sourcestone',
		b: 'malum:twisted_rock',
		c: 'embers:alchemy_pedestal',
		d: 'malum:tainted_rock',
		e: 'ars_nouveau:arcane_pedestal',
		f: '#botania:manasteel_ingots',
		g: 'botania:rune_mana',
		h: 'bloodmagic:infusedslate',
		i: 'extendedcrafting:basic_component'
	}
).tier(2);

// Elite Comps
event.custom({
  "type": "enderio:alloy_smelting",
  "energy": 40000,
  "experience": 1.2,
  "inputs": [
    {
      "count": 1,
      "ingredient": {
        "item": "extendedcrafting:black_iron_slate"
      }
    },
    {
      "count": 1,
      "ingredient": {
        "item": "extendedcrafting:luminessence_block"
      }
    },
    {
      "count": 1,
      "ingredient": {
        "tag": "kubejs:prismatter"
      }
    }
  ],
  "result": {
    "item": "extendedcrafting:elite_component"
  }
})

// Elite Table

event.recipes.extendedcrafting.shaped_table("extendedcrafting:elite_table", 
	['abbba', 
	 'bcdcb', 
	 'bdedb',
	 'bcdcb',
	 'abbba'
	 ], 
	{
		a: 'extendedcrafting:black_iron_block',
		b: 'minecraft:crafting_table',
		c: 'extendedcrafting:elite_component',
		d: 'extendedcrafting:advanced_table',
		e: 'extendedcrafting:frame'
	}
).tier(2);

// Auto basic and advanced tables, also auto comb crafter
event.recipes.extendedcrafting.shaped_table("packagedexcrafting:basic_crafter", 
	['abcba', 
	 'bdedb', 
	 'cefec',
	 'bdedb',
	 'abcba'
	 ], 
	{
		a: 'thermal_extra:dragonsteel_gear',
		b: 'mekanism:ultimate_control_circuit',
		c: 'enderio:frank_n_zombie',
		d: 'create:precision_mechanism',
		e: 'extendedcrafting:basic_component',
		f: 'extendedcrafting:basic_table'
	}
).tier(2);

event.recipes.extendedcrafting.shaped_table("packagedexcrafting:advanced_crafter", 
	['abcba', 
	 'bdedb', 
	 'cefec',
	 'bdedb',
	 'abcba'
	 ], 
	{
		a: 'thermal_extra:dragonsteel_gear',
		b: 'mekanism:ultimate_control_circuit',
		c: 'enderio:frank_n_zombie',
		d: 'create:precision_mechanism',
		e: 'extendedcrafting:advanced_component',
		f: 'extendedcrafting:advanced_table'
	}
).tier(2);

event.recipes.extendedcrafting.shaped_table("packagedexcrafting:combination_crafter", 
	['abcba', 
	 'bdedb', 
	 'cefec',
	 'bdedb',
	 'abcba'
	 ], 
	{
		a: 'thermal_extra:dragonsteel_gear',
		b: 'mekanism:ultimate_control_circuit',
		c: 'enderio:frank_n_zombie',
		d: 'create:precision_mechanism',
		e: 'extendedcrafting:elite_component',
		f: 'extendedcrafting:crafting_core'
	}
).tier(2);

// No crystaltine
event.remove({output: 'extendedcrafting:crystaltine_ingot'})

// Black iron compressing
event.shapeless(
  Item.of('extendedcrafting:black_iron_ingot'),
  [
    'extendedcrafting:black_iron_nugget',
    'extendedcrafting:black_iron_nugget',
    'extendedcrafting:black_iron_nugget',
	'extendedcrafting:black_iron_nugget',
	'extendedcrafting:black_iron_nugget',
	'extendedcrafting:black_iron_nugget',
	'extendedcrafting:black_iron_nugget',
	'extendedcrafting:black_iron_nugget',
	'extendedcrafting:black_iron_nugget'
  ]
)

})