// 1. Blacklist and Helper
const ENCHANT_BLACKLIST = new Set([
    "minecraft:binding_curse", "minecraft:loyalty", "minecraft:mending",
    "minecraft:unbreaking", "minecraft:vanishing_curse", "minecraft:smite",
    "minecraft:bane_of_arthropods", "minecraft:aqua_affinity", "minecraft:depth_strider",
    "minecraft:respiration", "minecraft:sweeping", "enchancement:slide",
    "enchancement:perception", "enchancement:buoy", "enchancement:berserk",
    "enchancement:molten", "enchancement:lumberjack", "enchancement:bury",
    "enchancement:scooping", "enchancement:grapple", "enchancement:extracting",
    "enchancement:assimilation", "enchancement:frostbite", "majruszsenchantments:breaking_curse",
    "majruszsenchantments:corrosion_curse", "majruszsenchantments:fatigue_curse",
    "majruszsenchantments:incompatibility_curse", "majruszsenchantments:slippery_curse",
    "majruszsenchantments:gold_fuelled", "majruszsenchantments:fuse_cutter",
    "majruszsenchantments:harvester", "majruszsenchantments:immortality",
    "majruszsenchantments:leech", "majruszsenchantments:misanthropy",
    "majruszsenchantments:smelter", "majruszsenchantments:telekinesis",
    "majruszsenchantments:magic_protection", "grapplemod:doublejumpenchantment",
    "grapplemod:wallrunenchantment", "grapplemod:slidingenchantment",
    "spectrum:indestructible", "spectrum:autosmelt", "minecraft:feather_falling"
]);

function cleanItem(itemStack) {
    if (!itemStack || itemStack.isEmpty() || !itemStack.enchanted) return itemStack;

    if (itemStack.id === 'minecraft:enchanted_book') {
        let shouldDelete = false;
        itemStack.enchantments.forEach((id) => {
            if (ENCHANT_BLACKLIST.has(id)) shouldDelete = true;
        });
        return shouldDelete ? Item.empty : itemStack;
    }

    itemStack.enchantments.forEach((id) => {
        if (ENCHANT_BLACKLIST.has(id)) {
            itemStack.removeEnchantment(id);
        }
    });

    return itemStack;
}

// 2. THE WORKING LOOTJS MODIFIER
LootJS.modifiers((event) => {
    event.addLootTableModifier(/.*/)
        .modifyLoot(Ingredient.all, (itemStack) => {
            return cleanItem(itemStack);
        });
});