// 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', // Note: If this still warns, use output removal below
        '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',
        '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'
    ];

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

    // Removals by Filter (This stops the "Non [a-z0-9_.-]" crash)
    // This targets ANY recipe making these items that uses a Knife
    event.remove({ output: 'notreepunching:plant_fiber', input: 'notreepunching:flint_knife' });
    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
    const fiberSources = [
        '#minecraft:saplings', 
        '#minecraft:leaves', 
        'minecraft:sugar_cane', 
        'minecraft:wheat', 
        'minecraft:cactus', 
        '#minecraft:small_flowers'
    ];
    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 (Tearing apart armor)
    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 (Breaking melons)
    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);
        });
    });
});