// priority: 0

settings.logAddedRecipes = true
settings.logRemovedRecipes = true
settings.logSkippedRecipes = false
settings.logErroringRecipes = true

console.info('Server Startup Scripts - Copper Tweaks - Cinnamon Buns')

onEvent('recipes', event => {
	// Removing all variations of Ice and Fire Copper Ingots, Blocks, and Nuggets
	event.remove({output: 'iceandfire:copper_ingot', type: 'minecraft:smelting'})
	event.remove({output: 'iceandfire:copper_ingot', type: 'minecraft:blasting'})
	event.remove({output: 'iceandfire:copper_ingot'})
	event.remove({output: 'iceandfire:copper_nugget'})
	event.remove({output: 'iceandfire:copper_block'})

	// Removing all variations of Caves and Cliffs Backport Copper Ingots
	event.remove({output: 'cavesandcliffs:copper_ingot', type: 'minecraft:smelting'})
	event.remove({output: 'cavesandcliffs:copper_ingot', type: 'minecraft:blasting'})
	event.remove({output: 'cavesandcliffs:copper_ingot'})

	// Removing all variations of Mekanism Copper Ingots, Blocks, and Nuggets
	event.remove({output: 'mekanism:ingot_copper', type: 'minecraft:smelting'})
	event.remove({output: 'mekanism:ingot_copper', type: 'minecraft:blasting'})
	event.remove({output: 'mekanism:ingot_copper'})
	event.remove({output: 'mekanism:block_copper'})
	event.remove({output: 'mekanism:nugget_copper'})

	// Removing all variations of Create Copper Blocks
	event.remove({output: 'create:copper_block'})

	// Removing all variations of Ice and Fire Copper Armor and Tools
	event.remove({output: 'iceandfire:armor_copper_metal_boots'})
	event.remove({output: 'iceandfire:armor_copper_metal_chestplate'})
	event.remove({output: 'iceandfire:armor_copper_metal_helmet'})
	event.remove({output: 'iceandfire:armor_copper_metal_leggings'})
	event.remove({output: 'iceandfire:copper_sword'})
	event.remove({output: 'iceandfire:copper_shovel'})
	event.remove({output: 'iceandfire:copper_pickaxe'})
	event.remove({output: 'iceandfire:copper_axe'})
	event.remove({output: 'iceandfire:copper_hoe'})

	// Adding correct Copper Block recipe
	event.shapeless('cavesandcliffs:copper_block', [
		'create:copper_ingot', 'create:copper_ingot', 'create:copper_ingot',
		'create:copper_ingot', 'create:copper_ingot', 'create:copper_ingot',
		'create:copper_ingot', 'create:copper_ingot', 'create:copper_ingot'
	])

	// Conversion Recipes
	// Ingots
	event.shapeless('create:copper_ingot', ['iceandfire:copper_ingot'])
	event.shapeless('create:copper_ingot', ['cavesandcliffs:copper_ingot'])
	event.shapeless('create:copper_ingot', ['mekanism:ingot_copper'])

	// Nuggets
	event.shapeless('create:copper_nugget', ['iceandfire:copper_nugget'])
	event.shapeless('create:copper_nugget', ['mekanism:nugget_copper'])

	// Blocks
	event.shapeless('cavesandcliffs:copper_block', ['create:copper_block'])
	event.shapeless('cavesandcliffs:copper_block', ['mekanism:block_copper'])
})

onEvent('entity.loot_tables', event => {
	// Reconstruct Drowned loot table with correct Copper Ingot
	event.addEntity('minecraft:drowned', table => {
		table.addPool(pool => {
			pool.addItem('minecraft:rotten_flesh', 1, [0, 2])
			pool.addItem('create:copper_ingot').randomChance(0.05)
		})
	})

	// Reconstruct Stymphalian Bird loot tables with correct Copper Ingot/Nugget
	event.addEntity('iceandfire:stymphalian_bird', table => {
		table.addPool(pool => {
			pool.addItem('iceandfire:stymphalian_skull').randomChance(0.025)
			pool.addItem('iceandfire:stymphalian_bird_feather', 1, [2, 6]).randomChance(0.25)
			pool.addItem('create:copper_ingot', 1, [1, 3]).randomChance(0.25)
			pool.addItem('create:copper_nugget', 1, [0, 4]).randomChance(0.25)
			pool.addItem('minecraft:iron_ingot', 1, [0, 4]).randomChance(0.25)
		})
	})
})