events.listen('recipes', function (event) {
    event.replaceInput({}, 'refinedstorage:silicon', '#forge:silicon');
    event.replaceInput({}, 'refinedstorage:crafter', '#refinedstorage:crafter');
    event.replaceInput({}, 'thermal:cinnabar', '#forge:gems/cinnabar');
    event.replaceInput({}, 'thermal:sulfur', '#forge:gems/sulfur');
    event.replaceInput({}, 'thermal:apatite', '#forge:gems/apatite');
    event.replaceInput({}, 'thermal:niter', '#forge:gems/niter');
    event.replaceInput({}, 'thermal:bitumen', '#forge:gems/bitumen');
    event.replaceInput({}, 'thermal:coal_coke', '#forge:gems/coal_coke');
    event.replaceInput({}, 'mapperbase:raw_bitumen', '#forge:gems/bitumen');
    event.replaceInput({}, 'rftoolsbase:dimensionalshard', '#forge:gems/dimensional');
    event.replaceInput({}, '#forge:fillet_knife', '#forge:tools/knife');
    event.replaceInput({}, '#farmersdelight:tools/knife', '#forge:tools/knife');
    event.replaceInput({}, 'immersivepetroleum:bitumen', '#forge:gems/bitumen');
    event.replaceInput({}, 'ars_nouveau:mana_gem', '#forge:gems/mana');
    event.replaceInput({}, 'immersiveengineering:slag', '#forge:slag');
    event.replaceInput({}, 'thermal:slag', '#forge:slag');
    event.replaceInput({}, 'simplefarming:cooked_egg', '#forge:cooked_eggs');
    event.replaceInput({}, 'farmersdelight:fried_egg', '#forge:cooked_eggs');
    event.replaceInput({ type: 'minecraft:crafting_shaped' }, 'powah:uraninite', '#forge:ingots/radioactive');
    event.replaceInput({ id: 'tetra:hammer/stone' }, 'minecraft:cobblestone', '#quark:stone_tool_materials');
    event.replaceInput({ id: 'dustrial_decor:sheet_metal' }, '#forge:ingots/iron', '#forge:plates/iron');
    event.replaceInput({ id: 'mcwbridges:iron_platform' }, '#forge:ingots/iron', 'additionalbars:horizontal_iron_bars');
    event.replaceInput({ mod: 'buildinggadgets' }, '#forge:ingots/iron', '#forge:ingots/iron_aluminum');
    event.replaceInput({ mod: 'powah' }, '#forge:ingots/iron', '#forge:ingots/iron_copper');
    event.replaceInput({ mod: 'powah' }, '#forge:nuggets/iron', '#forge:nuggets/iron_copper');
    event.replaceInput({ mod: 'astralsorcery' }, 'astralsorcery:marble_raw', '#forge:stones/marble');

    event.replaceInput(
        { type: 'minecraft:crafting_shaped', output: 'minecraft:piston' },
        '#forge:cobblestone',
        '#quark:stone_tool_materials'
    );

    ['quark:tallow', 'eidolon:tallow', 'occultism:tallow'].forEach((tallow) => {
        event.replaceInput({}, tallow, '#forge:tallow');
    });

    event.replaceInput(
        { id: 'dustrial_decor:iron_bar_trapdoor' },
        'minecraft:iron_bars',
        'dustrial_decor:barbed_iron_bars'
    );

    event.replaceInput(
        { id: 'bloodmagic:alchemytable/basic_cutting_fluid' },
        'minecraft:potion',
        item.of('minecraft:potion', { Potion: 'minecraft:water' })
    );

    event.replaceInput(
        { id: 'create:mixing/chromatic_compound' },
        'create:powdered_obsidian',
        ingredient.of('#forge:dusts/obsidian')
    );

    colors.forEach((color) => {
        var dyeTag = `#forge:dyes/${color}`;

        // Replaces recipes not using forge:dyes tag for inputs
        event.replaceInput({}, `minecraft:${color}_dye`, dyeTag);

        event.remove({
            id: `minecraft:${color}_carpet_from_white_carpet`
        });
        event.shaped(Item.of(`minecraft:${color}_carpet`, 3), ['WW'], {
            W: `minecraft:${color}_wool`
        });

        event.shaped(Item.of(`minecraft:${color}_stained_glass_pane`, 8), ['GGG', 'GDG', 'GGG'], {
            G: 'minecraft:glass_pane',
            D: dyeTag
        });

        event.shaped(Item.of(`minecraft:${color}_stained_glass`, 8), ['GGG', 'GDG', 'GGG'], {
            G: 'minecraft:glass',
            D: dyeTag
        });

        ['stained_glass', 'stained_glass_pane', 'terracotta', 'concrete_powder', 'wool', 'carpet'].forEach(
            (blockName) => {
                var itemTag = `#forge:${blockName}`;
                var block = `minecraft:${color}_${blockName}`;

                if (blockName === 'stained_glass_pane') {
                    event.remove({ id: `${block}_from_glass_pane` });
                } else {
                    event.remove({ id: block });
                }

                event.shaped(Item.of(block, 8), ['SSS', 'SDS', 'SSS'], {
                    S: itemTag,
                    D: dyeTag
                });
                event.shapeless(Item.of(block, 1), [dyeTag, itemTag]);
            }
        );
        event.shapeless(Item.of(`minecraft:${color}_concrete_powder`, 8), [
            dyeTag,
            '#forge:sand',
            '#forge:sand',
            '#forge:sand',
            '#forge:sand',
            '#forge:gravel',
            '#forge:gravel',
            '#forge:gravel',
            '#forge:gravel'
        ]);
    });
    var data = {
        recipes: [
            {
                type: 'storage_blocks',
                replace: 'iron',
                replaceWith: 'aluminum',
                items: [
                    'bloodmagic:soulforge',
                    'mininggadgets:upgrade_fortune_1',
                    'resourcefulbees:centrifuge_casing',
                    'xnet:antenna_base'
                ]
            },
            {
                type: 'storage_blocks',
                replace: 'iron',
                replaceWith: 'brass',
                items: ['ars_nouveau:glyph_press']
            },
            {
                type: 'storage_blocks',
                replace: 'iron',
                replaceWith: 'invar',
                items: ['resourcefulbees:centrifuge_controller']
            },
            {
                type: 'storage_blocks',
                replace: 'iron',
                replaceWith: 'lead',
                items: ['travel_anchors:travel_anchor', 'thermal:machine_press', 'bloodmagic:alchemicalreactionchamber']
            },
            {
                type: 'storage_blocks',
                replace: 'iron',
                replaceWith: 'tin',
                items: ['aquaculture:tackle_box']
            },
            {
                type: 'dusts',
                replace: 'gold',
                replaceWith: 'copper',
                items: ['mekanism:upgrade_energy']
            },
            {
                type: 'gears',
                replace: 'gold',
                replaceWith: 'bronze',
                items: ['thermal:upgrade_augment_1']
            },
            {
                type: 'gears',
                replace: 'gold',
                replaceWith: 'copper',
                items: ['thermal:flux_drill', 'thermal:flux_saw']
            },
            {
                type: 'gears',
                replace: 'gold',
                replaceWith: 'silver',
                items: ['thermal:dynamo_lapidary']
            },
            {
                type: 'ingots',
                replace: 'gold',
                replaceWith: 'brass',
                items: [
                    'ars_nouveau:arcane_core',
                    'ars_nouveau:crystallizer',
                    'ars_nouveau:volcanic_accumulator',
                    'pneumaticcraft:gun_ammo',
                    'ars_nouveau:marvelous_clay'
                ]
            },
            {
                type: 'ingots',
                replace: 'gold',
                replaceWith: 'bronze',
                items: [
                    'bloodmagic:alchemytable',
                    'bloodmagic:altar',
                    'bloodmagic:sacrificialdagger',
                    'bloodmagic:experiencebook',
                    'bloodmagic:soulforge',
                    'pneumaticcraft:medium_tank',
                    'pneumaticcraft:minigun',
                    'pneumaticcraft:pressure_gauge',
                    'thermal:diving_helmet',
                    'thermal:diving_chestplate',
                    'thermal:diving_leggings',
                    'thermal:diving_boots',
                    'minecraft:clock'
                ]
            },
            {
                type: 'ingots',
                replace: 'gold',
                replaceWith: 'copper',
                items: [
                    'mekanismgenerators:electromagnetic_coil',
                    'mekanism:energy_tablet',
                    'mininggadgets:upgrade_magnet',
                    'xnet:controller',
                    'thermal:rf_coil_xfer_augment',
                    'thermal:rf_coil_storage_augment',
                    'thermal:rf_coil_augment',
                    'thermal:rf_coil',
                    'rftoolsstorage:storage_scanner',
                    'rftoolsbuilder:shield_block1',
                    'pneumaticcraft:vortex_tube',
                    'pneumaticcraft:heat_sink',
                    'modularrouters:speed_upgrade',
                    'xnet:connector_blue',
                    'xnet:connector_red',
                    'xnet:connector_green'
                ]
            },
            {
                type: 'ingots',
                replace: 'gold',
                replaceWith: 'silver',
                items: ['torchmaster:feral_flare_lantern', 'mekanism:teleportation_core', 'botania:mana_spreader']
            },
            {
                type: 'ingots',
                replace: 'gold',
                replaceWith: 'tin',
                items: ['pneumaticcraft:memory_stick']
            },
            {
                type: 'ingots',
                replace: 'iron',
                replaceWith: 'aluminum',
                items: [
                    'immersiveengineering:conveyor_splitter',
                    'immersiveengineering:conveyor_vertical',
                    'immersiveengineering:conveyor_basic',
                    'immersiveengineering:current_transformer',
                    'immersiveengineering:transformer_hv',
                    'immersiveengineering:transformer',
                    'immersiveengineering:dynamo',
                    'immersiveengineering:furnace_heater',
                    'immersiveengineering:toolupgrade_drill_lube',
                    'endermail:locker',
                    'endermail:package_controller',
                    'cookingforblockheads:preservation_chamber',
                    'buildersaddition:arcade',
                    'minecraft:compass',
                    'minecraft:piston',
                    'xnet:antenna_dish',
                    'xnet:antenna_base',
                    'xnet:antenna',
                    'transport:fluid_loader',
                    'resourcefulbees:centrifuge_casing',
                    'engineersdecor:metal_bar'
                ]
            },
            {
                type: 'ingots',
                replace: 'iron',
                replaceWith: 'brass',
                items: ['ars_nouveau:mana_condenser', 'ars_nouveau:enchanting_apparatus']
            },
            {
                type: 'ingots',
                replace: 'iron',
                replaceWith: 'copper',
                items: [
                    'shrink:shrinking_device',
                    'immersiveengineering:charging_station',
                    'cookingforblockheads:heating_unit',
                    'aquaculture:tackle_box'
                ]
            },
            {
                type: 'ingots',
                replace: 'iron',
                replaceWith: 'lead',
                items: ['travel_anchors:travel_anchor', 'travel_anchors:travel_staff']
            },
            {
                type: 'ingots',
                replace: 'iron',
                replaceWith: 'tin',
                items: ['bloodmagic:soulsnare', 'modularrouters:bulk_item_filter']
            },
            {
                type: 'nuggets',
                replace: 'gold',
                replaceWith: 'bronze',
                items: ['rftoolsstorage:storage_module0']
            },
            {
                type: 'nuggets',
                replace: 'gold',
                replaceWith: 'copper',
                items: [
                    'xnet:connector_routing',
                    'xnet:netcable_routing',
                    'xnet:netcable_yellow',
                    'xnet:netcable_blue',
                    'xnet:netcable_green',
                    'xnet:netcable_red',
                    'rftoolsbase:machine_base',
                    'rftoolsbase:machine_frame',
                    'rftoolscontrol:card_base',
                    'modularrouters:speed_upgrade',
                    'modularrouters:blank_upgrade',
                    'modularrouters:blank_module'
                ]
            },
            {
                type: 'nuggets',
                replace: 'gold',
                replaceWith: 'silver',
                items: ['botania:spark']
            }
        ]
    };

    data.recipes.forEach((recipe) => {
        recipe.items.forEach((item) => {
            event.replaceInput(
                { output: item },
                '#forge:' + recipe.type + '/' + recipe.replace,
                '#forge:' + recipe.type + '/' + recipe.replace + '_' + recipe.replaceWith
            );
        });
    });

    //TODO: Remove in 0.4.0
    event.replaceInput({ id: 'quantumstorage:chestgold' }, 'quantumstorage:chestiron', '#forge:storage_blocks/iron');
    event.replaceInput({ id: 'quantumstorage:chestdiamond' }, 'quantumstorage:chestgold', '#forge:storage_blocks/gold');
});
