// Priority: 10

// 1. FAST LOOKUP SETS
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", "spectrum:indestructible", 
    "spectrum:autosmelt", "minecraft:feather_falling", "origins:water_protection"
]);

const FORBIDDEN_GEAR = [
    '/minecraft:(iron|golden|diamond|netherite|chainmail)_(helmet|chestplate|leggings|boots)/',
    '/minecraft:(wooden|golden)_(sword|shovel|pickaxe|hoe|axe)/',
    '/farmersdelight:(flint|golden|diamond|netherite)_knife/',
    "archers:golden_spear",
    "forcemaster_rpg:golden_knuckle",
    "paladins:golden_claymore",
    "paladins:golden_great_hammer",
    '/soulsweapons:(arkenplate|enhanced_arkenplate|withered_chest|enhanced_withered_chest|chaos_helmet|soul_ingot|soul_robes|forlorn).*/',
    '/artifacts:(everlasting_beef|eternal_steak|pickaxe_heater|rooted_boots|vampiric_glove)/',
    '/endrem:(witch_pupil|undead_soul|black_eye|old_eye|rogue_eye|witch_eye)/'
];

LootJS.modifiers((event) => {

    // 2. ENTITY DROPS (The "Combat" optimization)
    // Only runs when a mob is killed. We only care about gear removal here.
    event.addLootTypeModifier(LootType.ENTITY)
        .removeLoot(FORBIDDEN_GEAR);

    // 3. CHEST CONTENT (The "Exploration" optimization)
    // Only runs when a chest/container is generated.
    event.addLootTypeModifier(LootType.CHEST)
        .removeLoot(FORBIDDEN_GEAR) // Remove gear first
        .modifyLoot('*', (itemStack) => {
            // Then strip enchantments from the remaining items (like books/tools)
            if (!itemStack.enchanted) return itemStack;

            const enchantsMap = itemStack.enchantments;
            let changed = false;

            enchantsMap.keySet().forEach(enchantId => {
                if (ENCHANT_BLACKLIST.has(String(enchantId))) {
                    itemStack.removeEnchantment(enchantId);
                    changed = true;
                }
            });

            // Clean up empty books
            if (changed && itemStack.id === 'minecraft:enchanted_book' && itemStack.enchantments.isEmpty()) {
                return 'minecraft:air';
            }

            return itemStack;
        });
});