//priority: 6

//This script adds recipes. Go figure.
ServerEvents.recipes(event => {

    //Epic Knights additions.
    event.recipes.kubejs.shaped('magistuarmory:blacksmith_hammer',
        [
         'H',
         'S'],
         {
          S: 'magistuarmory:hilt',
          H: 'tfc:metal/hammer_head/steel'  
         }
    )
    
    //barrel
    function rusting(input, output) {
    event.recipes.tfc.barrel_sealed(12000)
    .outputItem(output)
    .inputs(input, TFC.fluidStackIngredient('minecraft:water', 4000))  
} 
    rusting('magistuarmory:iron_bastardsword', 'magistuarmory:rusted_bastardsword')
    rusting('magistuarmory:iron_heavymace', 'magistuarmory:rusted_heavymace')
    rusting('magistuarmory:barbute','magistuarmory:rustedbarbute')
    rusting('magistuarmory:halfarmor_chestplate','magistuarmory:rustedhalfarmor_chestplate')
    rusting('magistuarmory:greathelm','magistuarmory:rustedgreathelm')
    rusting('magistuarmory:crusader_chestplate','magistuarmory:rustedcrusader_chestplate')
    rusting('magistuarmory:crusader_boots','magistuarmory:rustedcrusader_boots')
    rusting('magistuarmory:norman_helmet','magistuarmory:rustednorman_helmet')
    rusting('magistuarmory:chainmail_helmet','magistuarmory:rustedchainmail_helmet')
    rusting('magistuarmory:chainmail_chestplate','magistuarmory:rustedchainmail_chestplate')
    rusting('magistuarmory:chainmail_leggings','magistuarmory:rustedchainmail_leggings')
    rusting('magistuarmory:chainmail_boots','magistuarmory:rustedchainmail_boots')
    rusting('magistuarmory:kettlehat','magistuarmory:rustedkettlehat')   
    rusting('magistuarmory:iron_roundshield', 'magistuarmory:corruptedroundshield')

    //IronChests
     //smithing
    event.recipes.tfc.anvil('ironchests:iron_dolly', 
        'tfc:metal/double_sheet/wrought_iron', 
        ['bend_any', 'hit_any', 'hit_any'])
    event.recipes.tfc.anvil('ironchests:key', 
        'tfc:metal/rod/wrought_iron', 
        ['shrink_any', 'bend_any', 'punch_last'])
    event.recipes.tfc.anvil('ironchests:key_ring', 
        'tfc:metal/rod/wrought_iron', 
        ['bend_any', "bend_any", "bend_any"])
    event.recipes.tfc.anvil('ironchests:lock', 
        'tfc:metal/ingot/gold', 
        ["shrink_not_last", "hit_any", "punch_last"])

    //heating
    event.recipes.tfc.heating('ironchests:key', 1535)
        .resultFluid(Fluid.of('tfc:metal/cast_iron', 50))
    event.recipes.tfc.heating('ironchests:key_ring', 1535)
        .resultFluid(Fluid.of('tfc:metal/cast_iron', 50))
    event.recipes.tfc.heating('ironchests:lock', 1060)
        .resultFluid(Fluid.of('tfc:metal/gold', 100))   
    event.recipes.tfc.heating('ironchests:iron_dolly', 1535)
        .resultFluid(Fluid.of('tfc:metal/cast_iron', 400)).useDurability(true)           
    //shaped
    event.recipes.kubejs.shaped('ironchests:diamond_dolly', [
        ' X ',
        'XDX',
        ' X '
    ], {
      X: '#forge:gems/diamond',
      D: 'ironchests:iron_dolly' 
    } 
    
)
    //musket
    event.recipes.kubejs.shapeless('musketmod:musket_upgrade_smithing_template', 
        ['antiquelegacy:small_bronze_plate', 'tfc:metal/ingot/bronze']
    )
    //simpleradio
    event.recipes.kubejs.shaped('simpleradio:speaker',
        [
            ' S ',
            ' M ',
            ' S '
        ],
        {
            S: 'tfc:metal/sheet/wrought_iron',
            M: 'simpleradio:speaker_module'
        }
    )
    event.recipes.tfc.anvil(Item.of('simpleradio:copper_wire', 2), 
        'tfc:metal/ingot/copper', 
        ["shrink_not_last", "bend_any", "punch_last"])

    //TWT Tweaks
    event.recipes.kubejs.shaped('minecraft:anvil',
        [
            'DDD',
            ' C ',
            'CCC'
        ],
        {
            D: 'tfc:metal/double_ingot/cast_iron',
            C: 'tfc:metal/ingot/cast_iron'
        }
    )
    //shapeless
    event.recipes.kubejs.shapeless('antiquelegacy:fur_cloak_decoration', ['tfc:large_raw_hide', '#forge:string'])

    //welding
    event.recipes.tfc.welding('minecraft:anvil', 'minecraft:chipped_anvil', 'tfc:metal/ingot/cast_iron')
    event.recipes.tfc.welding('minecraft:chipped_anvil', 'minecraft:damaged_anvil', 'tfc:metal/ingot/cast_iron')
    event.recipes.tfc.welding('minecraft:anvil', 'minecraft:damaged_anvil', 'tfc:metal/double_ingot/cast_iron')
    event.recipes.tfc.welding('minecraft:bucket', 'tfc:metal/bucket/blue_steel', 'tfc:metal/bucket/red_steel')

    event.recipes.tfc.heating('minecraft:anvil', 1535)
        .resultFluid(Fluid.of('tfc:metal/cast_iron', 1000)) 
    event.recipes.tfc.heating('minecraft:chipped_anvil', 1535)
        .resultFluid(Fluid.of('tfc:metal/cast_iron', 900))
    event.recipes.tfc.heating('minecraft:damaged_anvil', 1535)
        .resultFluid(Fluid.of('tfc:metal/cast_iron', 800))
    event.recipes.tfc.heating('minecraft:bricks', 600)
        .resultItem('immersiveengineering:clinker_brick')

    //Nugget Smithing and heating
    function nuggetheating(input, temperature, output) {
        event.custom({
            type: 'tfc:heating',
            ingredient: {
                item: input
            },
            result_fluid: {
                fluid: output,
                amount: 5
            },
            temperature: temperature
        })
    }
    nuggetheating('minecraft:gold_nugget', 1060, 'tfc:metal/gold')
    nuggetheating('immersiveengineering:nugget_lead', 500, 'tfc_ie_addon:metal/lead')
    nuggetheating('immersiveengineering:nugget_silver', 961, 'tfc:metal/silver')
    nuggetheating('immersiveengineering:nugget_electrum', 900, 'tfc_ie_addon:metal/electrum')
    nuggetheating('immersiveengineering:nugget_constantan', 750, 'tfc_ie_addon:metal/constantan')
    nuggetheating('immersiveengineering:nugget_copper', 1080, 'tfc:metal/copper')
    nuggetheating('immersiveengineering:nugget_nickel', 1453, 'tfc:metal/nickel')
    nuggetheating('immersiveengineering:nugget_uranium', 1250, 'tfc_ie_addon:metal/uranium')
    nuggetheating('immersiveengineering:nugget_aluminum', 650, 'tfc_ie_addon:metal/aluminum')
    nuggetheating('antiquelegacy:tin_nugget', 230, 'tfc:metal/tin')

    function nuggetsmithing(input, output) {
    event.custom({
        type: 'tfc:anvil',
        input: {
            item: input
        },
        result: {
            item: output
        },
        tier: 1,
        rules: ['punch_any', 'punch_any', 'punch_any'],
        apply_forging_bonus: false
    })
}
       
    nuggetsmithing('tfc:metal/ingot/gold', '20x minecraft:gold_nugget')
    nuggetsmithing('immersiveengineering:ingot_lead', '20x immersiveengineering:nugget_lead')
    nuggetsmithing('tfc:metal/ingot/silver', '20x immersiveengineering:nugget_silver')
    nuggetsmithing('immersiveengineering:ingot_electrum', '20x immersiveengineering:nugget_electrum')
    nuggetsmithing('immersiveengineering:ingot_constantan', '20x immersiveengineering:nugget_constantan')
    nuggetsmithing('tfc:metal/ingot/copper', '20x immersiveengineering:nugget_copper')
    nuggetsmithing('tfc:metal/ingot/nickel', '20x immersiveengineering:nugget_nickel')
    nuggetsmithing('immersiveengineering:ingot_uranium', '20x immersiveengineering:nugget_uranium')
    nuggetsmithing('immersiveengineering:ingot_aluminum', '20x immersiveengineering:nugget_aluminum')
    nuggetsmithing('tfc:metal/ingot/tin', '20x antiquelegacy:tin_nugget')

    event.stonecutting('8x dfc:metal/smooth/aluminum', 'dfc:metal/sheet/aluminum')
    event.stonecutting('8x dfc:metal/pillar/aluminum', 'dfc:metal/sheet/aluminum')
    event.stonecutting('8x dfc:metal/block/aluminum', 'dfc:metal/sheet/aluminum')
    event.stonecutting('8x dfc:metal/cut/aluminum', 'dfc:metal/sheet/aluminum')
    event.stonecutting('8x dfc:metal/bricks/aluminum', 'dfc:metal/sheet/aluminum')
    event.stonecutting('8x dfc:metal/smooth/lead', 'dfc:metal/sheet/lead')
    event.stonecutting('8x dfc:metal/pillar/lead', 'dfc:metal/sheet/lead')
    event.stonecutting('8x dfc:metal/block/lead', 'dfc:metal/sheet/lead')
    event.stonecutting('8x dfc:metal/cut/lead', 'dfc:metal/sheet/lead')
    event.stonecutting('8x dfc:metal/bricks/lead', 'dfc:metal/sheet/lead')

    //Ore dust shenanigans
    
        function oredustsmelting(input, temperature, output) {
            event.recipes.tfc.heating(input, temperature)
                .resultFluid(Fluid.of(output, 5))
        }
        oredustsmelting('tfc:powder/hematite', 1535, 'tfc:metal/cast_iron')
        oredustsmelting('tfc:powder/magnetite', 1535, 'tfc:metal/cast_iron')
        oredustsmelting('tfc:powder/limonite', 1535, 'tfc:metal/cast_iron')
        oredustsmelting('tfc:powder/sphalerite', 420, 'tfc:metal/zinc')
        oredustsmelting('tfc:powder/tetrahedrite', 1080, 'tfc:metal/copper')
        oredustsmelting('tfc:powder/cassiterite', 230, 'tfc:metal/tin')
        oredustsmelting('tfc:powder/bismuthinite', 270, 'tfc:metal/bismuth')
        oredustsmelting('tfc:powder/garnierite', 1453, 'tfc:metal/nickel')
        oredustsmelting('tfc:powder/malachite', 1080, 'tfc:metal/copper')
        oredustsmelting('tfc:powder/native_copper', 1080, 'tfc:metal/copper')
        oredustsmelting('tfc:powder/native_gold', 1060, 'tfc:metal/gold')
        oredustsmelting('tfc:powder/native_silver', 961, 'tfc:metal/silver')
        oredustsmelting('tfc_ie_addon:powder/bauxite', 650, 'tfc_ie_addon:metal/aluminum')
        oredustsmelting('tfc_ie_addon:powder/galena', 500, 'tfc_ie_addon:metal/lead')
        oredustsmelting('tfc_ie_addon:powder/uraninite', 1250, 'tfc_ie_addon:metal/uranium')
        oredustsmelting('dfc:metal/powder/bismuth', 270, 'tfc:metal/bismuth')
        oredustsmelting('dfc:metal/powder/bismuth_bronze', 985, 'tfc:metal/bismuth_bronze')
        oredustsmelting('dfc:metal/powder/black_bronze', 1070, 'tfc:metal/black_bronze')
        oredustsmelting('dfc:metal/powder/bronze', 950, 'tfc:metal/bronze')
        oredustsmelting('dfc:metal/powder/brass', 930, 'tfc:metal/brass')
        oredustsmelting('dfc:metal/powder/copper', 1080, 'tfc:metal/copper')
        oredustsmelting('dfc:metal/powder/gold', 1060, 'tfc:metal/gold')
        oredustsmelting('dfc:metal/powder/nickel', 1453, 'tfc:metal/nickel')
        oredustsmelting('dfc:metal/powder/rose_gold', 960, 'tfc:metal/rose_gold')
        oredustsmelting('dfc:metal/powder/silver', 961, 'tfc:metal/silver')
        oredustsmelting('dfc:metal/powder/tin', 230, 'tfc:metal/tin')
        oredustsmelting('dfc:metal/powder/zinc', 420, 'tfc:metal/zinc')
        oredustsmelting('dfc:metal/powder/sterling_silver', 950, 'tfc:metal/sterling_silver')
        oredustsmelting('dfc:metal/powder/wrought_iron', 1535, 'tfc:metal/wrought_iron')
        oredustsmelting('dfc:metal/powder/cast_iron', 1535, 'tfc:metal/cast_iron')
        oredustsmelting('dfc:metal/powder/steel', 1540, 'tfc:metal/steel')
        oredustsmelting('dfc:metal/powder/black_steel', 1485, 'tfc:metal/black_steel')
        oredustsmelting('dfc:metal/powder/blue_steel', 1540, 'tfc:metal/blue_steel')
        oredustsmelting('dfc:metal/powder/red_steel', 1540, 'tfc:metal/red_steel')
        oredustsmelting('dfc:metal/powder/aluminum', 650, 'tfc_ie_addon:metal/aluminum')
        oredustsmelting('dfc:metal/powder/alumina', 650, 'tfc_ie_addon:metal/aluminum')
        oredustsmelting('dfc:metal/powder/lead', 500, 'tfc_ie_addon:metal/lead')
        oredustsmelting('dfc:metal/powder/pewter', 340, 'dfc:metal/dfc_pewter')
        oredustsmelting('dfc:metal/powder/platinum', 1540, 'dfc:metal/dfc_platinum')
    
        event.recipes.tfc.quern(Item.of('immersiveengineering:dust_coke'), 'immersiveengineering:coal_coke')
    
        event.recipes.kubejs.shaped('minecraft:obsidian',
        [
         'OO ',
         'OO '],
         {
          O: 'bsa:obsidian',  
         }
    )

        //Nightmare code that works somehow. Don't touch it, you'll probably upset the machine gods.
        $metals.forEach((metal) => {
            event.recipes.tfc.quern(Item.of(`dfc:metal/powder/${metal}`, 20), `/^(dfc|tfc):metal\/ingot\/${metal}$/`)
        })
        //A patch for two of the recipes not working as intended.
        event.recipes.tfc.quern(Item.of('dfc:metal/powder/lead', 20), 'immersiveengineering:ingot_lead')
        event.recipes.tfc.quern(Item.of('dfc:metal/powder/aluminum', 20), 'immersiveengineering:ingot_aluminum')

        $ores.forEach((ore) => {
          event.recipes.tfc.extra_products_shapeless_crafting(
            [{ item: `tfc:ore/small_${ore}`, count: 1 }],
            event.recipes.tfc.damage_inputs_shapeless_crafting(
              event.recipes.minecraft.crafting_shapeless(
                `tfc:ore/normal_${ore}`,
                ['#tfc:hammers', `tfc:ore/rich_${ore}`]
              )
            )
          )
        }
    )
        $dfcOres.forEach((ore) => {
          event.recipes.tfc.extra_products_shapeless_crafting(
            [{ item: `dfc:ore/small_${ore}`, count: 1 }],
            event.recipes.tfc.damage_inputs_shapeless_crafting(
              event.recipes.minecraft.crafting_shapeless(
                `dfc:ore/normal_${ore}`,
                ['#tfc:hammers', `dfc:ore/rich_${ore}`]
              )
            )
          )
        }
    )
        $IEores.forEach((ore) => {
          event.recipes.tfc.extra_products_shapeless_crafting(
            [{ item: `tfc_ie_addon:ore/small_${ore}`, count: 1 }],
            event.recipes.tfc.damage_inputs_shapeless_crafting(
              event.recipes.minecraft.crafting_shapeless(
                `tfc_ie_addon:ore/normal_${ore}`,
                ['#tfc:hammers', `tfc_ie_addon:ore/rich_${ore}`]
              )
            )
          )
        }
    )
          event.recipes.tfc.extra_products_shapeless_crafting(
            [{ item: `firmalife:ore/small_chromite`, count: 1 }],
            event.recipes.tfc.damage_inputs_shapeless_crafting(
              event.recipes.minecraft.crafting_shapeless(
                `firmalife:ore/normal_chromite`,
                ['#tfc:hammers', `firmalife:ore/rich_chromite`]
              )
            )
          )

})


                





