ItemEvents.foodEaten(event => {
    if (event.level.clientSide) return;

    let player = event.player;
    if (!player) return;

    let foodId = String(event.item.id);

    // Target raw meats or woodland foraging items
    if (foodId.includes('raw') || foodId.includes('berry') || foodId.includes('berries')) {
        
        // 8% chance to experience a sudden supernatural food contamination panic
        if (Math.random() < 0.08) {
            let username = player.username ? String(player.username) : String(player.getName().getString());
            
            // Flash standard pitch black darkness onto their client UI layout for 2 seconds
            event.server.runCommandSilent(`effect give ${username} minecraft:darkness 2 0 true`);
            
            // Blast a corrupted witch or phantom whisper at maximum volume (2.0) and distorted pitch (0.4)
            event.server.runCommandSilent(`playsound minecraft:entity.witch.ambient ambient ${username} ~ ~ ~ 2.0 0.4`);
            
            player.setStatusMessage(Text.darkRed("It tasted like ash. Something is contaminating the local wildlife."));
        }
    }
});