// Priority: 0

ServerEvents.recipes(event => {

    // ==========================================================================
    // 1. RECIPE REMOVALS
    // ==========================================================================
    
    // Removals by ID (Specific strings)
    const recipesByID = [
        // 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:explorerscompass',
        'explorerscompass:explorerscompass_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',
        
        // NTP Fiber Removals (Surgical IDs)
        '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_tall_flowers_with_knife',
        'notreepunching:plant_fiber_from_sugarcane_with_knife',

        // Path of the Ascended 3.0: Conflict Resolution
        'minecraft:kjs/notreepunching_plant_fiber_3',
        'minecraft:kjs/notreepunching_plant_fiber_4',
        'notreepunching:crafting/plant_fiber_from_cactus',
        'minecraft:cake',                             // Remove vanilla cake to keep Farmer's Delight
        'naturalist:cake',                            // Remove Naturalist cake
        'chas:leather_horse_armor'                    // Remove redundant CHAS horse armor
    ];

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

    // Removals by Filter (Safety nets for Knife processing)
    event.remove({ output: 'notreepunching:plant_fiber', input: 'notreepunching:flint_knife', ingredients: ['minecraft:sugar_cane', 'minecraft:cactus', '#minecraft:flowers'] });
    event.remove({ output: 'minecraft:string', input: 'notreepunching:flint_knife' });
    event.remove({ output: 'minecraft:leather', input: 'notreepunching:flint_knife' });
    event.remove({ output: 'minecraft:melon_slice', input: 'notreepunching:flint_knife' });

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

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

    // ==========================================================================
    // 3. SHAPED & SHAPELESS RECIPES (NO TOOL OVERRIDES)
    // ==========================================================================

    // ADDED: Standard Stick Recipes
    event.shaped('4x minecraft:stick', ['P', 'P'], { P: '#minecraft:planks' });
    event.shaped('16x minecraft:stick', ['L', 'L'], { L: '#minecraft:logs' });

    // --- NO TOOL PROCESSING (By Hand) ---
    
    // Plant Fiber from environment (Cane, Cactus, and Flowers REMOVED from here)
    const fiberSources = [
        '#minecraft:saplings', 
        '#minecraft:leaves', 
        'minecraft:wheat'
    ];
    fiberSources.forEach(source => {
        event.shapeless('notreepunching:plant_fiber', [source]);
    });

    // Braiding string by hand (3 Fiber = 1 String)
    event.shapeless('minecraft:string', ['3x notreepunching:plant_fiber']);

    // Leather Recycling
    event.shapeless('minecraft:leather', ['minecraft:leather_helmet']);
    event.shapeless('2x minecraft:leather', ['minecraft:leather_leggings']);
    event.shapeless('3x minecraft:leather', ['minecraft:leather_chestplate']);
    event.shapeless('minecraft:leather', ['minecraft:leather_boots']);

    // Food Processing
    event.shapeless('9x minecraft:melon_slice', ['minecraft:melon']);

    // --- END NO TOOL PROCESSING ---

    // 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', [
        'GBE',
        'NCS',
        'DMI'
    ], {
        G: 'minecraft:gold_block',
        B: 'minecraft:polished_blackstone_bricks',
        E: 'minecraft:emerald_block',
        N: 'minecraft:nether_bricks',
        C: 'minecraft:compass',
        S: 'minecraft:stone_bricks',
        D: 'minecraft:diamond_block',
        M: 'minecraft:crying_obsidian',
        I: 'minecraft:iron_block'
    });

    // 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);
        });
    });
});