//priority 10

const $nuggetcompat = ['immersiveengineering:nugget_lead', 'immersiveengineering:nugget_silver', 'antiquelegacy:copper_nugget', 'immersiveengineering:nugget_nickel', 'antiquelegacy:bronze_nugget', 'minecraft:iron_nugget', 'knightsofterrafirma:black_bronze_nugget', 'knightsofterrafirma:bismuth_bronze_nugget', 'magistuarmory:steel_nugget', 'immersiveengineering:nugget_uranium', 'antiquelegacy:tin_nugget', 'immersiveengineering:nugget_electrum', 'immersiveengineering:nugget_constantan', 'minecraft:gold_nugget', 'immersiveengineering:nugget_copper', 'immersiveengineering:nugget_aluminum']
const $functionalnugs = ['lead', 'silver', 'electrum', 'constantan', 'copper']

ServerEvents.recipes(event => {
//replace input
event.replaceInput(
    { id: "minecraft:grindstone"},
    'minecraft:stone_slab',
    'tfc:handstone'
)    
event.replaceInput(
    {input: 'minecraft:amethyst_shard'},
    'minecraft:amethyst_shard',
    '#forge:gems/amethyst'
)
event.replaceInput(
    { id: 'waystones:warp_stone'},
    'minecraft:emerald',
    '#forge:gems/emerald'
)
event.replaceInput({id: 'toolbelt:belt'},
    'minecraft:iron_ingot',
    'tfc:metal/ingot/wrought_iron'
)
event.replaceInput({id: 'toolbelt:pouch'},
    'minecraft:gold_ingot',
    'tfc:metal/ingot/gold'
)
//shaped
    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.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))
    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')

    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')
          
            
 
   //Fix IE Nuggets
   event.remove({mod: 'epic_knights_ores_and_alloys'})    
   event.remove({output: 'magistuarmory:steel_ingot'})
   event.remove({output: 'immersiveengineering:nugget_steel'})
   event.remove({output: 'antiquelegacy:bronze_mixture'})
   event.remove({id: 'antiquelegacy:iron_ring'}) 
   event.remove({id: 'antiquelegacy:iron_chainmail'})
   event.remove({id: 'knightsofterrafirma:crafting/bronze_lamellar_rows'})
   event.remove({id: 'antiquelegacy:small_bronze_plate'})
   event.remove({id: 'antiquelegacy:bronze_plate'})
   event.remove({id: 'antiquelegacy:small_iron_plate'})
   event.remove({id: 'minecraft:iron_ingot_from_nuggets'})
   event.remove({id: 'minecraft:gold_ingot_from_nuggets'})
   event.remove({id: 'immersiveengineering:crafting/nugget_copper_to_copper_ingot'})
   event.remove({id: 'immersiveengineering:crafting/nugget_lead_to_ingot_lead'})
   event.remove({id: 'immersiveengineering:crafting/nugget_silver_to_ingot_silver'})
   event.remove({id: 'immersiveengineering:crafting/nugget_constantan_to_ingot_constantan'})
   event.remove({id: 'immersiveengineering:crafting/nugget_electrum_to_ingot_electrum'})
   event.remove({id: 'antiquelegacy:bronze_ingot'})
   
   $nuggetcompat.forEach((nugget) => {

    event.remove({not: {type: 'tfc:anvil'}, output: `${nugget}`})   
   })
    
 });  
