ServerEvents.recipes(event => {
    // 1. Direct ID Purge (Stops the "empty result" warnings)
    const toRemove = [
        'naturalist:leather_from_reptile_hide', 'tiered:limestone_create',
        'tiered:limestone_to_create_limestone', 'tierify_ores:limestone_create',
        'earlystage:heating_stones_from_rock', 'incendium:upgrade_elytra',
        'minecraft:netherite_scrap', 'minecraft:bread', 'forcemaster_rpg:golden_knuckle'
    ];
    toRemove.forEach(id => event.remove({ id: id }));

    // 2. Safe Item Removal
    const itemsToRemove = ['naturalist:reptile_hide', 'earlystage:heating_stones'];
    itemsToRemove.forEach(item => {
        if (Item.exists(item)) event.remove({ output: item });
    });

    // 3. Horse Armor Rework
    const horseTiers = [
        { id: 'minecraft:iron_horse_armor', mat: 'minecraft:iron_ingot' },
        { id: 'minecraft:golden_horse_armor', mat: 'minecraft:gold_ingot' },
        { id: 'minecraft:diamond_horse_armor', mat: 'minecraft:diamond' },
        { id: 'minecraft:leather_horse_armor', mat: 'minecraft:leather' }
    ];
    horseTiers.forEach(tier => {
        event.remove({ output: tier.id });
        event.shaped(tier.id, ['  M', 'MWM', 'M M'], { M: tier.mat, W: 'minecraft:white_wool' });
    });

    // 4. Death Knight Smithing
    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}`;
            if (Item.exists(res) && Item.exists(set.stone)) {
                event.remove({ output: res });
                event.smithing(res, set.stone, base, 'minecraft:iron_ingot');
            }
        });
    });

    // 5. Golden Knuckle Fix
    event.shaped('forcemaster_rpg:golden_knuckle', ['R  ', 'RE ', 'RR '], { E: 'minecraft:amethyst_shard', R: 'minecraft:gold_ingot' });
});