// Priority: 0

ServerEvents.recipes(event => {

    // ==========================================================================
    // 1. RECIPE REMOVALS
    // ==========================================================================
    const recipesToRemove = [
        // Naturalist & World
        'naturalist:leather_from_reptile_hide',
        'naturalist:shellstone_bricks',
        'incendium:upgrade_elytra',
        'minecraft:bread',
        
        // RPG & Combat
        'forcemaster_rpg:golden_knuckle',
        
        // Early Stage & Utility
        'explorerscompass:explorers_compass',
        'explorerscompass:explorers_compass_alternate',

        // No Tree Punching (Sticks/Processing)
        'notreepunching:sticks_from_logs_with_saw',
        'notreepunching:sticks_from_logs_with_flint_axe',
        'notreepunching:sticks_from_planks_with_saw',
        'notreepunching:sticks_from_planks_with_flint_axe',
        'notreepunching:clay_brick_from_blocks',
        'notreepunching:clay_brick_from_balls',
        'notreepunching:leather_from_boots_with_knife',
        'notreepunching:leather_from_chestplate_with_knife',
        'notreepunching:leather_from_helmet_with_knife',
        'notreepunching:leather_from_leggings_with_knife',
        'notreepunching:melon_slices_with_knife',
        'notreepunching:plant_fiber_from_wheat_with_knife',
        'notreepunching:plant_fiber_from_cactus_with_knife',
        'notreepunching:plant_fiber_from_leaves_with_knife',
        'notreepunching:plant_fiber_from_saplings_with_knife',
        'notreepunching:plant_fiber_from_small_flowers_with_knife',
        'notreepunching:plant_fiber_from_sugarcane_with_knife'
    ];

    recipesToRemove.forEach(id => {
        event.remove({ id: id });
    });

    // Explicit Output Removals
    event.remove({ output: 'explorerscompass:explorerscompass' });
    event.remove({ output: 'naturalist:reptile_hide' });
    event.remove({ output: 'earlystage:heating_stones' });

    // ==========================================================================
    // 2. INPUT REPLACEMENTS
    // ==========================================================================
    event.replaceInput({ input: 'naturalist:reptile_hide' }, 'naturalist:reptile_hide', 'minecraft:leather');

    // ==========================================================================
    // 3. SHAPED & SHAPELESS RECIPES
    // ==========================================================================

    // Horse Armor Fixes
    event.shaped('minecraft:iron_horse_armor', ['  H', 'IBI', 'I I'], { H: 'minecraft:iron_helmet', I: 'minecraft:iron_ingot', B: 'minecraft:iron_block' });
    event.shaped('minecraft:golden_horse_armor', ['  H', 'IBI', 'I I'], { H: 'minecraft:golden_helmet', I: 'minecraft:gold_ingot', B: 'minecraft:gold_block' });
    event.shaped('minecraft:diamond_horse_armor', ['  H', 'IBI', 'I I'], { H: 'minecraft:diamond_helmet', I: 'minecraft:diamond', B: 'minecraft:diamond_block' });

    // Naturalist Fixes
    event.shaped(Item.of('naturalist:shellstone_bricks', 4), ['AA', 'AA'], { A: 'naturalist:shellstone' });

    // The World-Stitcher (Explorer's Compass)
    event.shaped('explorerscompass:explorerscompass', [
        'G E',
        'NCS',
        'DMI'
    ], {
        G: 'minecraft:gold_block',
        C: 'minecraft:compass',
        E: 'minecraft:emerald_block',
        N: 'minecraft:nether_bricks',
        S: 'minecraft:stone_bricks',
        D: 'minecraft:diamond_block',
        M: 'minecraft:crying_obsidian',
        I: 'minecraft:iron_block',
	B: 'minecraft:blackstone_bricks',
    });

    // No Tree Punching: Survival Basics
    event.shapeless('4x minecraft:string', ['#minecraft:wool']);
    event.shaped('minecraft:campfire', [' S ', 'SCS', 'LLL'], { S: 'minecraft:stick', C: '#minecraft:coals', L: '#minecraft:logs_that_burn' });
    event.shaped('minecraft:soul_campfire', [' S ', 'SCS', 'LLL'], { S: 'minecraft:stick', C: 'minecraft:soul_sand', L: '#minecraft:logs_that_burn' });

    // No Tree Punching: Stone Tools
    const stoneMaterials = '#minecraft:stone_tool_materials';
    event.shaped('minecraft:stone_sword', [' M ', ' M ', ' S '], { M: stoneMaterials, S: 'minecraft:stick' });
    event.shaped('minecraft:stone_pickaxe', ['MMM', ' S ', ' S '], { M: stoneMaterials, S: 'minecraft:stick' });
    event.shaped('minecraft:stone_axe', ['MM ', 'MS ', ' S '], { M: stoneMaterials, S: 'minecraft:stick' });
    event.shaped('minecraft:stone_shovel', [' M ', ' S ', ' S '], { M: stoneMaterials, S: 'minecraft:stick' });
    event.shaped('minecraft:stone_hoe', ['MM ', ' S ', ' S '], { M: stoneMaterials, S: 'minecraft:stick' });

    // No Tree Punching: Misc
    event.shaped('notreepunching:clay_small_vessel', ['B B', 'B B', 'BBB'], { B: 'notreepunching:clay_brick' });
    event.shaped('2x notreepunching:clay_brick', ['CC'], { C: 'minecraft:clay_ball' });

    // ==========================================================================
    // 4. SMITHING RECIPES (Knight Sets)
    // ==========================================================================
    const knightSets = [
        { stone: 'death_knights:blood_stone', output: 'death_knights:crimson_guard_armor' },
        { stone: 'death_knights:unholy_stone', output: 'death_knights:plaguebringer_armor' },
        { stone: 'runes:frost_stone', output: 'death_knights:frozen_champion_armor' }
    ];
    
    knightSets.forEach(set => {
        ['head', 'chest', 'legs', 'feet'].forEach(piece => {
            let res = `${set.output}_${piece}`;
            let base = `death_knights:initiate_armor_${piece}`;
            event.smithing(res, 'minecraft:iron_block', base, set.stone);
        });
    });
});