onEvent('recipes', (event) =>{

    const id_prefix = 'tconstruct:smeltery/casting/metal';

    const parts = [
        {name: 'ingot', amount: 144, time: 60},
        {name: 'nugget', amount: 16, time: 15},
        {name: 'rod', amount: 72, time: 40},
        {name: 'wire', amount: 72, time: 40},
        {name: 'plate', amount: 144, time: 60},
        {name: 'dust', amount: 144, time: 60},
        {name: 'block', amount: 1296, time: 240}
    ];

    const temperatures = [500,425,790,330,950,830,975,225,420,950,700,605,920,760,950,900,1125,1050,1350,1090,800,700,1500,1250,-1,-1,-1];

    let i = 0;
    let tempMap = new Map();
    metals.forEach((metal) => {

        tempMap.set(metal,temperatures[i]);
        i++;

        parts.forEach((part) => {

            let item = part.name!="block"? itemOf(`#forge:${part.name}s/${metal}`) : itemOf(`#forge:storage_blocks/${metal}`);

            if(item!=null) {
                
                let tconstruct = Fluid.exists(`tconstruct:molten_${metal}`);
                let materialis = Fluid.exists(`materialis:molten_${metal}`);
                let ee = Fluid.exists(`emendatusenigmatica:molten_${metal}`);

                if(tconstruct || materialis || ee ) {

                    if(part.name!='block' && part.name!='dust'){
                        event.custom({
                            type: 'tconstruct:casting_table',
                            cast: Item.of(`tconstruct:${part.name}_cast`).toResultJson(),
                            cast_consumed: false,
                            fluid: {
                                tag: `forge:molten_${metal}`,
                                amount: part.amount
                            },
                            result: Item.of(item).toResultJson(),
                            cooling_time: part.time
                        })
                        .id(`${id_prefix}/${metal}/${part.name}_gold_cast`);
    
                        event.custom({
                            type: 'tconstruct:casting_table',
                            cast: { tag: `tconstruct:casts/single_use/${part.name}`},
                            cast_consumed: true,
                            fluid: {
                                tag: `forge:molten_${metal}`, 
                                amount: part.amount
                            },
                            result: Item.of(item).toResultJson(),
                            cooling_time: part.time
                        })
                        .id(`${id_prefix}/${metal}/${part.name}_sand_cast`)
                    }

                    if(part.name=='block'){
                        event.custom({
                            type: 'tconstruct:casting_basin',
                            fluid: {
                                tag: `forge:molten_${metal}`,
                                amount: part.amount
                            },
                            result: Item.of(item).toResultJson(),
                            cooling_time: part.time
                        })
                        .id(`${id_prefix}/${metal}/block`);
                    }

                    let fluid = tconstruct? `tconstruct:molten_${metal}` : (materialis? `materialis:molten_${metal}` : `emendatusenigmatica:molten_${metal}`);
                    let id = `tconstruct:smeltery/melting/metal/${metal}/${part.name}`;
                    if(part.name=='plate') id = id+'s';

                    event.custom({
                        type: 'tconstruct:melting',
                        result: {
                            fluid: fluid,
                            amount: part.amount
                        },
                        ingredient: Item.of(item).toResultJson(),
                        temperature: tempMap.get(metal),
                        time: part.time
                    })
                    .id(id);

                }
            }

        })


    });

})