// Kubejs scripts for items that don't quite fit anywhere else
ServerEvents.tags('block', event => {
	
// Tags for raw crystal catalyst
event.remove('minecraft:needs_iron_tool', 'minecraft:gold_block')
event.add('minecraft:needs_diamond_tool', 'minecraft:gold_block')
	
})


ServerEvents.recipes(event => {

// Met. Infusion helper function
function metallurgic_infusing(output, input, enrichType, enrichQuant) {
	event.custom({
		"type":"mekanism:metallurgic_infusing",
		"chemicalInput":{
			"amount": enrichQuant,
			"tag": enrichType
			},
		"itemInput":{
			"ingredient":{
				"item" : input
			}
		},
		"output":{
			"item": output
		}
	})
}

event.remove({output: '#forge:gears', not: [{type: 'thermal:press'}, {type: 'immersiveengineering:metal_press'}, {type: 'embers:stamping'}]})
event.remove({output: 'hammerlib:gears/iron'})
event.remove({output: 'hammerlib:gears/gold'})

// No handcrafting alloys
event.remove({ output: '#forge:ingots', input: 'minecraft:fire_charge'})
event.remove({ output: '#forge:dusts', input: 'thermal:earth_charge'})
event.remove({ output: '#forge:dusts', input: '#forge:dusts'})

// EnderIO gears
event.recipes.thermal.press('enderio:stone_gear', ['4x minecraft:cobblestone', 'thermal:press_gear_die'])
event.recipes.thermal.smelter('enderio:iron_gear', ['thermal:iron_gear', '4x #forge:dusts/grains_of_infinity']).energy(3200)
event.recipes.thermal.smelter('enderio:energized_gear', ['enderio:iron_gear', '4x #forge:ingots/energetic_alloy']).energy(4800)
event.recipes.thermal.smelter('enderio:dark_bimetal_gear', ['enderio:iron_gear', '4x #forge:ingots/dark_steel']).energy(4800)
event.recipes.thermal.smelter('enderio:vibrant_gear', ['enderio:energized_gear', '4x enderio:vibrant_alloy_ingot']).energy(5400)

// Comp iron gear
event.recipes.thermal.press('pneumaticcraft:compressed_iron_gear', ['4x #forge:ingots/compressed_iron', 'thermal:press_gear_die'])

// Remove non angelic rings
event.remove({output: 'angelring:diamond_ring'})
event.remove({output: 'angelring:energetic_angel_ring'})
event.remove({output: 'angelring:leadstone_angel_ring'})
event.remove({output: 'angelring:hardened_angel_ring'})
event.remove({output: 'angelring:reinforced_angel_ring'})
event.remove({output: 'angelring:resonant_angel_ring'})

// Energet Angel Ring
event.shaped(
  Item.of('angelring:energetic_angel_ring'),
  [
    'aba',
    'cdc',
    'aea'
  ],
  {
    a: 'minecraft:feather',
    b: 'ars_nouveau:ring_of_potential',
	c: 'thermal:rf_coil',
	d: 'create:copper_backtank',
	e: 'thermal:energy_cell'
  }
)

// Angel Ring
event.replaceInput(
  { output: 'angelring:angel_ring' },
  'angelring:diamond_ring',
  'angelring:energetic_angel_ring'
)

event.replaceInput(
  { output: 'angelring:angel_ring' },
  'minecraft:blaze_rod',
  '#kubejs:prismatter'
)

// Swiftwolf move
event.remove({output: 'projecte:swiftwolf_rending_gale'})

event.shapeless(
  Item.of('projecte:swiftwolf_rending_gale'),
  [
    'angelring:angel_ring',
	'#kubejs:red_matter'
  ]
)

// Well, well, well..
event.remove({output: 'well:well'})

// TIAB
event.remove({output: 'tiab:time_in_a_bottle'})

event.shaped(
  Item.of('tiab:time_in_a_bottle'),
  [
    'bih',
    'cAg',
    'def'
  ],
  {
    A: 'minecraft:glass_bottle',
    b: 'pneumaticcraft:speed_upgrade',
	c: 'thermal:machine_speed_augment',
	d: 'bloodmagic:speedrune',
	e: 'ae2:speed_card',
	f: 'enderio:extraction_speed_upgrade_4',
	g: 'mekanism:upgrade_speed',
	h: 'create:rotation_speed_controller',
	i: '#kubejs:prismatter'
  }
)

// Fuel Reprocessor collector doesn't use netherite
event.replaceInput(
  { output: 'bigreactors:reprocessorcollector' },
  'minecraft:netherite_ingot',
  'minecraft:netherite_scrap'
)

event.replaceInput(
  { output: 'bigreactors:fluidizerfluidinjector' },
  'minecraft:netherite_ingot',
  'minecraft:netherite_scrap'
)

// Echo shard from sculk catalyst
metallurgic_infusing('minecraft:echo_shard', 'minecraft:sculk_catalyst', 'mekanism_extras:radiance', 80)

// DM armor changes
event.remove({output: 'projecte:dm_helmet'})
event.remove({output: 'projecte:dm_chestplate'})
event.remove({output: 'projecte:dm_leggings'})
event.remove({output: 'projecte:dm_boots'})

// Remove red matter
event.remove({output: 'projecte:rm_helmet'})
event.remove({output: 'projecte:rm_chestplate'})
event.remove({output: 'projecte:rm_leggings'})
event.remove({output: 'projecte:rm_boots'})

// Fool's Gold compressing
// Black iron compressing
event.shapeless(
  Item.of('kubejs:fool_gold_ingot'),
  [
    'kubejs:fool_gold_nugget',
    'kubejs:fool_gold_nugget',
    'kubejs:fool_gold_nugget',
	'kubejs:fool_gold_nugget',
	'kubejs:fool_gold_nugget',
	'kubejs:fool_gold_nugget',
	'kubejs:fool_gold_nugget',
	'kubejs:fool_gold_nugget',
	'kubejs:fool_gold_nugget'
  ]
)

event.shapeless(
  Item.of('9x kubejs:fool_gold_nugget'),
  [
    'kubejs:fool_gold_ingot'
  ]
)

// Earlier Alchemical Bags
event.replaceInput(
  { output: '#projecte:alchemical_bags' },
  'projecte:high_covalence_dust',
  'projecte:medium_covalence_dust'
)

event.replaceInput(
  { output: '#projecte:alchemical_bags' },
  'projecte:alchemical_chest',
  'minecraft:ender_chest'
)

// Obsinite
event.recipes.create.mixing(['kubejs:obsinite_alloy'], ['minecraft:obsidian', 'minecraft:gold_ingot', 'minecraft:iron_ingot', Fluid.of(('minecraft:lava'), 1000)]).heated()

event.shaped(
  Item.of('kubejs:obsinite_pickaxe'),
  [
    'aaa',
    ' b ',
    ' b '
  ],
  {
    a: 'kubejs:obsinite_alloy',
    b: 'minecraft:stick'
  }
)

// Alch catalyst swap between pris crystals <=> ghast tears
event.recipes.botania.mana_infusion("minecraft:ghast_tear", "minecraft:prismarine_crystals", 8000, 'botania:alchemy_catalyst')
event.recipes.botania.mana_infusion("minecraft:prismarine_crystals", "minecraft:ghast_tear", 8000, 'botania:alchemy_catalyst')

// Disable horse armor crunching
event.remove({input: 'minecraft:iron_horse_armor'})
event.remove({input: 'minecraft:golden_horse_armor'})
event.remove({input: 'minecraft:diamond_horse_armor'})

// Earlier klein star
event.replaceInput(
  { output: 'projecte:klein_star_ein' },
  'minecraft:diamond',
  'minecraft:gold_block'
)

// Comp assembly parts
// Circuits
event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 5000,
  "ingredients": [
    {
      "count": 32,
      "tag": "forge:ingots/osmium"
    },
    {
      "amount": 1000,
      "fluid": "thermal:redstone"
    }
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "mekanism:basic_control_circuit"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 32,
      "tag": "forge:circuits/basic"
    },
    {
      "count": 64,
      "tag": "mekanism:alloys/infused"
    },
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "mekanism:advanced_control_circuit"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 7000,
  "ingredients": [
    {
      "count": 32,
      "item": "mekanism:advanced_control_circuit"
    },
    {
      "count": 64,
      "tag": "mekanism:alloys/reinforced"
    },
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "mekanism:elite_control_circuit"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 8000,
  "ingredients": [
    {
      "count": 32,
      "item": "mekanism:elite_control_circuit"
    },
    {
      "count": 64,
      "tag": "mekanism:alloys/atomic"
    },
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "mekanism:ultimate_control_circuit"
}]})

// Frames
event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 16,
      "tag": "forge:ingots/iron"
    },
    {
      "count": 16,
      "tag": "forge:glass"
    },
	{
      "count": 4,
      "tag": "forge:gears/tin"
    },
  ],
  "result": [
    {
	  "amount": 4,
      "chance": 1.0,
      "item": "thermal:machine_frame"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 16,
      "tag": "forge:ingots/steel"
    },
    {
      "count": 16,
      "tag": "forge:glass"
    },
	{
      "count": 4,
      "tag": "forge:ingots/osmium"
    },
  ],
  "result": [
    {
	  "amount": 4,
      "chance": 1.0,
      "item": "mekanism:steel_casing"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 4,
      "tag": "mekanism:alloys/infused"
    },
    {
      "count": 8,
      "item": "minecraft:gold_ingot"
    },
	{
      "count": 1,
      "item": "mekanism:steel_casing"
    },
	{
      "amount": 1000,
      "fluid": "thermal:redstone"
    },
  ],
  "result": [
    {
	  "amount": 1,
      "chance": 1.0,
      "item": "mekanism:basic_energy_cube"
}]})

// Solar flux photo cells
event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 4000,
  "ingredients": [
    {
      "count": 32,
      "tag": "forge:glass"
    },
    {
      "count": 12,
      "tag": "forge:ingots/iron"
    }
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "solarflux:mirror"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 4000,
  "ingredients": [
    {
      "count": 32,
      "tag": "forge:glass"
    },
    {
      "count": 32,
      "tag": "forge:gems/lapis"
    },
	{
      "count": 32,
      "item": "solarflux:mirror"
    }
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "solarflux:photovoltaic_cell_1"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 5000,
  "ingredients": [
    {
      "count": 64,
      "tag": "forge:clay"
    },
    {
      "count": 64,
      "tag": "forge:gems/lapis"
    },
	{
      "count": 64,
      "item": "solarflux:mirror"
    },
	{
      "count": 32,
      "item": "solarflux:photovoltaic_cell_1"
    }
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "solarflux:photovoltaic_cell_2"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 5000,
  "ingredients": [
    {
      "count": 64,
      "tag": "forge:glass"
    },
    {
      "count": 64,
      "tag": "forge:dusts/glowstone"
    },
	{
      "count": 64,
      "item": "minecraft:obsidian"
    },
	{
      "count": 32,
      "item": "solarflux:photovoltaic_cell_2"
    }
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "solarflux:photovoltaic_cell_3"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 64,
      "item": "solarflux:blazing_coating"
    },
	{
      "count": 32,
      "item": "minecraft:diamond"
    },
    {
      "count": 64,
      "tag": "forge:dusts/glowstone"
    },
	{
      "count": 64,
      "tag": "forge:storage_blocks/quartz"
    },
	{
      "count": 32,
      "item": "solarflux:photovoltaic_cell_3"
    }
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "solarflux:photovoltaic_cell_4"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 64,
      "item": "solarflux:emerald_glass"
    },
	{
      "count": 16,
      "item": "minecraft:diamond_block"
    },
    {
      "count": 32,
      "tag": "forge:storage_blocks/glowstone"
    },
	{
      "count": 16,
      "tag": "forge:storage_blocks/quartz"
    },
	{
      "count": 32,
      "item": "solarflux:photovoltaic_cell_4"
    }
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "solarflux:photovoltaic_cell_5"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 7000,
  "ingredients": [
    {
      "count": 64,
      "item": "solarflux:ender_glass"
    },
	{
      "count": 16,
      "item": "minecraft:emerald_block"
    },
    {
      "count": 32,
      "tag": "forge:storage_blocks/glowstone"
    },
	{
      "count": 16,
      "tag": "forge:storage_blocks/quartz"
    },
	{
      "count": 32,
      "item": "solarflux:photovoltaic_cell_5"
    }
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "solarflux:photovoltaic_cell_6"
}]})

// Photo cell coatings
event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 4000,
  "ingredients": [
    {
      "count": 32,
      "item": "solarflux:mirror"
    },
    {
      "count": 16,
      "item": "minecraft:blaze_powder"
    }
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "solarflux:blazing_coating"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 5000,
  "ingredients": [
    {
      "count": 32,
      "item": "solarflux:mirror"
    },
    {
      "count": 16,
      "item": "minecraft:emerald"
    }
  ],
  "result": [
    {
	  "amount": 32,
      "chance": 1.0,
      "item": "solarflux:emerald_glass"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 48,
      "item": "solarflux:emerald_glass"
    },
	{
      "count": 32,
      "item": "minecraft:ender_pearl"
    },
    {
      "count": 16,
      "item": "minecraft:ender_eye"
    }
  ],
  "result": [
    {
	  "amount": 48,
      "chance": 1.0,
      "item": "solarflux:ender_glass"
}]})

// Reactor, turbine and induction casing skips
event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 64,
      "tag": "forge:ingots/steel"
    },
    {
      "count": 64,
      "tag": "forge:ingots/graphite"
    },
	{
      "count": 16,
      "tag": "forge:storage_blocks/iron"
    },
  ],
  "result": [
    {
	  "amount": 16,
      "chance": 1.0,
      "item": "bigreactors:reinforced_reactorcasing"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 64,
      "tag": "forge:ingots/steel"
    },
    {
      "count": 64,
      "tag": "forge:ingots/cyanite"
    },
	{
      "count": 16,
      "tag": "forge:storage_blocks/iron"
    },
  ],
  "result": [
    {
	  "amount": 16,
      "chance": 1.0,
      "item": "bigreactors:reinforced_turbinecasing"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 32,
      "tag": "mekanism:alloys/infused"
    },
    {
      "count": 64,
      "item": "minecraft:gold_ingot"
    },
	{
      "count": 64,
      "item": "mekanism:ingot_steel"
    },
	{
      "amount": 8000,
      "fluid": "thermal:redstone"
    },
  ],
  "result": [
    {
	  "amount": 64,
      "chance": 1.0,
      "item": "mekanism:induction_casing"
}]})

event.custom({ "type": "thermal_extra:component_assembly",
  "energy": 6000,
  "ingredients": [
    {
      "count": 32,
      "tag": "mekanism:alloys/infused"
    },
    {
      "count": 64,
      "item": "minecraft:gold_ingot"
    },
	{
      "count": 64,
      "item": "mekanism:ingot_steel"
    },
	{
      "count": 64,
      "item": "mekanism:induction_casing"
    },
	{
      "amount": 8000,
      "fluid": "thermal:redstone"
    },
  ],
  "result": [
    {
	  "amount": 64,
      "chance": 1.0,
      "item": "mekanism_extras:reinforced_induction_casing"
}]})

// Augment helper function
function compAssembleAugment(identifier, tier, pretier, augment) {

event.custom({ 
	"type": "thermal_extra:component_assembly",
	"energy": 6000,
	"ingredients": [
		{
			"count": 1,
			"item": "thermal_extra:augment_smithing_upgrade"
		},
		{
			"count": 1,
			"item": identifier+pretier+augment+"_augment"
		},
		{
			"count": 1,
			"item": "thermal_extra:"+tier+"gear"
		}
		],
	"result": [
		{
			"amount": 1,
			"chance": 1.0,
			"item": "thermal_extra:"+tier+augment+"_augment"
}]})

}

// Augments
const augmentList = ["rf_coil", "rf_coil_storage", "rf_coil_xfer", "fluid_tank", "machine_speed", "machine_efficiency", "machine_output", "machine_catalyst", "dynamo_output", "dynamo_fuel", "potion_amplifier", "potion_duration", "area_radius"]

const upgradeTiers = ["", "soul_infused_", "twinite_", "shellite_", "dragonsteel_", "abyssal_"]

for (var j = 0; j < 12; j++) {
	for (var i = 1; i < 6; i++) {
		if (i == 1) {
			compAssembleAugment("thermal:", upgradeTiers[i], upgradeTiers[i-1], augmentList[j])
		}
		else {
			compAssembleAugment("thermal_extra:", upgradeTiers[i], upgradeTiers[i-1], augmentList[j])
		}
	}
}

// Create casings in crafting table
event.shapeless(
  Item.of('create:andesite_casing'),
  [
    '#kubejs:andesite_alloys',
	'#forge:stripped_logs'
  ]
)

event.shapeless(
  Item.of('create:copper_casing'),
  [
    '#forge:ingots/copper',
	'#forge:stripped_logs'
  ]
)

event.shapeless(
  Item.of('create:brass_casing'),
  [
    '#forge:ingots/brass',
	'#forge:stripped_logs'
  ]
)

// Flux dust loop
event.recipes.thermal.smelter('32x fluxnetworks:flux_dust', ['fluxnetworks:flux_core', '4x minecraft:obsidian', '32x minecraft:redstone']).energy(8000)

// Charge Bench
event.shaped(
  Item.of('thermal:charge_bench'),
  [
    'aaa',
    'bcb',
    'bdb'
  ],
  {
    a: '#forge:ingots/constantan',
    b: 'minecraft:iron_ingot',
	c: 'thermal:rf_potato',
	d: 'minecraft:redstone_block'
  }
)

// Yellor to Uran
event.shapeless(
  Item.of('mekanism:block_uranium'),
  [
    'bigreactors:yellorium_block'
  ]
)

event.shapeless(
  Item.of('mekanism:nugget_uranium'),
  [
    'bigreactors:yellorium_nugget'
  ]
)

event.shapeless(
  Item.of('mekanism:ingot_uranium'),
  [
    'bigreactors:yellorium_ingot'
  ]
)

event.remove({output: 'bigreactors:yellorium_block'})
event.remove({output: 'bigreactors:yellorium_nugget'})

// Cakes
event.remove({output: 'telepastries:overworld_cake'})
event.remove({output: 'telepastries:nether_cake'})
event.remove({output: 'telepastries:end_cake'})

// Earlier building gadgets
event.replaceInput(
  { output: 'buildinggadgets2:gadget_building' },
  'minecraft:diamond',
  'projecte:medium_covalence_dust'
)

event.replaceInput(
  { output: 'buildinggadgets2:gadget_exchanging' },
  'minecraft:diamond',
  'projecte:medium_covalence_dust'
)

event.replaceInput(
  { output: 'buildinggadgets2:gadget_copy_paste' },
  'minecraft:emerald',
  'minecraft:gold_ingot'
)

// Rem Ench Sword netherite
event.replaceInput(
  { output: 'ars_nouveau:enchanters_sword' },
  'minecraft:diamond',
  'minecraft:netherite_ingot'
)

})