ServerEvents.recipes(event => {
    // Helper function to safely remove recipes only if the item or mod exists
    function safeRemove(filter) {
        try {
            // Check if it's an output/input check
            if (filter.output && !Item.exists(filter.output)) return
            if (filter.input && !Item.exists(filter.input)) return
            
            event.remove(filter)
        } catch (e) {
            // Silently skip if something goes wrong to avoid log spam
        }
    }

    // 1 & 2. SAFE OUTPUT/INPUT REMOVAL
    // Only attempts removal if the naturalist/earlystage items exist
    safeRemove({ output: 'naturalist:reptile_hide' })
    safeRemove({ input: 'naturalist:reptile_hide' })
    safeRemove({ output: 'earlystage:heating_stones' })
    safeRemove({ input: 'earlystage:heating_stones' })

    // 3. SAFE DIRECT ID REMOVAL
    // We use a different approach here: filtering the removal by the mod presence
    const faultyIDs = [
        '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'
    ]

    faultyIDs.forEach(id => {
        // Only attempt to remove the recipe ID if the mod is actually loaded
        let modId = id.split(':')[0]
        if (Platform.isLoaded(modId)) {
            event.remove({ id: id })
        }
    })

    console.info('Kaelen has scrubbed the phantom recipes without leaving a trace in the logs.')
})