// --- ENCHANTMENT SETTINGS ---
const ENCHANT_BLACKLIST = [
    "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"
];

// --- LOOT REMOVAL CATEGORIES ---

const VANILLA_GEAR = [
    '/minecraft:(iron|golden|diamond|netherite|chainmail)_(helmet|chestplate|leggings|boots)/',
    '/minecraft:(wooden|golden)_(sword|shovel|pickaxe|hoe|axe)/'
];

const FARMERS_DELIGHT_REMOVALS = [
    '/farmersdelight:(flint|golden|diamond|netherite)_knife/'
];

const RPG_SERIES_GOLDEN = [
    "archers:golden_spear",
    "forcemaster_rpg:golden_knuckle",
    "paladins:golden_claymore",
    "paladins:golden_great_hammer"
];

const SOULS_WEAPONS_REMOVALS = [
    '/soulsweapons:(arkenplate|enhanced_arkenplate|withered_chest|enhanced_withered_chest|chaos_helmet|soul_ingot|soul_robes|forlorn).*/'
];

const ARTIFACTS_AND_RELICS = [
    '/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) => {

    // 1. GLOBAL REMOVALS
    // We use .concat() here to merge arrays because Rhino (KubeJS engine) 
    // is more stable with it than the [...] spread operator.
    let allRemovals = VANILLA_GEAR.concat(
        FARMERS_DELIGHT_REMOVALS,
        RPG_SERIES_GOLDEN,
        SOULS_WEAPONS_REMOVALS,
        ARTIFACTS_AND_RELICS
    );

    event.addLootTypeModifier([LootType.CHEST, LootType.ENTITY])
        .removeLoot(allRemovals);

    // 2. ENCHANTMENT STRIPPING
    // Target only items that typically hold enchantments to save server TPS
    const enchantableTags = [
        '#c:tools', 
        '#c:armor', 
        '#c:weapons', 
        '#c:bows', 
        '#c:shields', 
        'minecraft:enchanted_book'
    ];

    event.addLootTypeModifier([LootType.CHEST, LootType.ENTITY])
        .modifyLoot(enchantableTags, (itemStack) => {
            if (!itemStack.enchanted) return itemStack;

            ENCHANT_BLACKLIST.forEach((enchantId) => {
                itemStack.removeEnchantment(enchantId);
            });

            if (itemStack.id === 'minecraft:enchanted_book') {
                if (itemStack.enchantments.size() === 0) {
                    return 'minecraft:air';
                }
            }

            return itemStack;
        });
});