// Priority: 10
const FORBIDDEN_ITEMS = [
    "minecraft:iron_helmet", "minecraft:iron_chestplate", "minecraft:iron_leggings", "minecraft:iron_boots",
    "minecraft:golden_helmet", "minecraft:golden_chestplate", "minecraft:golden_leggings", "minecraft:golden_boots",
    "minecraft:chainmail_helmet", "minecraft:chainmail_chestplate", "minecraft:chainmail_leggings", "minecraft:chainmail_boots",
    "minecraft:diamond_helmet", "minecraft:diamond_chestplate", "minecraft:diamond_leggings", "minecraft:diamond_boots",
    "minecraft:netherite_helmet", "minecraft:netherite_chestplate", "minecraft:netherite_leggings", "minecraft:netherite_boots",
    "minecraft:wooden_sword", "minecraft:wooden_shovel", "minecraft:wooden_pickaxe", "minecraft:wooden_axe", "minecraft:wooden_hoe",
    "minecraft:golden_sword", "minecraft:golden_shovel", "minecraft:golden_pickaxe", "minecraft:golden_axe", "minecraft:golden_hoe",
    "farmersdelight:flint_knife", "farmersdelight:golden_knife", "farmersdelight:diamond_knife", "farmersdelight:netherite_knife",
    "archers:golden_spear", "forcemaster_rpg:golden_knuckle", "paladins:golden_claymore", "paladins:golden_great_hammer",
    "soulsweapons:arkenplate", "soulsweapons:enhanced_arkenplate", "soulsweapons:withered_chest", "soulsweapons:enhanced_withered_chest",
    "soulsweapons:chaos_helmet", "soulsweapons:forlorn_helmet", "soulsweapons:forlorn_chestplate", "soulsweapons:forlorn_leggings",
    "soulsweapons:forlorn_boots", "soulsweapons:soul_ingot_helmet", "soulsweapons:soul_ingot_chestplate", "soulsweapons:soul_ingot_leggings",
    "soulsweapons:soul_ingot_boots", "soulsweapons:soul_robes_helmet", "soulsweapons:soul_robes_chestplate", "soulsweapons:soul_robes_leggings",
    "soulsweapons:soul_robes_boots", "artifacts:everlasting_beef", "artifacts:eternal_steak", "artifacts:pickaxe_heater",
    "artifacts:rooted_boots", "artifacts:vampiric_glove", "endrem:witch_pupil", "endrem:undead_soul", "endrem:black_eye",
    "endrem:old_eye", "endrem:rogue_eye", "endrem:witch_eye", "artifacts:cross_necklace", "paladins:golden_kite_shield", 
    "rogues:golden_double_axe", "paladins:golden_mace", "rogues:golden_sickle", "rogues:golden_dagger", 
    "rogues:golden_glaive", "berserker_rpg:golden_berserker_axe", "minecraft:golden_horse_armor", "minecraft:shield"
];

const REPLACEMENT_MAP = {
    "netherite": "minecraft:netherite_scrap",
    "diamond": "minecraft:diamond",
    "golden": "minecraft:gold_ingot",
    "gold_": "minecraft:gold_ingot",
    "iron": "minecraft:iron_ingot",
    "chainmail": "minecraft:iron_ingot",
    "soul_ingot": "soulsweapons:soul_ingot",
    "soul_robes": "minecraft:phantom_membrane",
    "arkenplate": "soulsweapons:soul_ingot",
    "forlorn": "minecraft:obsidian",
    "artifacts": "minecraft:diamond",
    "endrem": "minecraft:ender_eye"
};

LootJS.modifiers((event) => {
    // Limits the modifier to Chests and Entities (mob drops)
    event.addLootTypeModifier(LootType.CHEST, LootType.ENTITY)
        // This first argument acts as a strict whitelist. 
        // Logic will ONLY execute if the item is in FORBIDDEN_ITEMS.
        .replaceLoot(FORBIDDEN_ITEMS, (itemStack) => {
            let id = itemStack.getId();
            let replacementId = "minecraft:gold_nugget"; // Fallback if no map key matches

            // Check the forbidden item ID against our material map
            for (let key in REPLACEMENT_MAP) {
                if (id.includes(key)) {
                    replacementId = REPLACEMENT_MAP[key];
                    break; 
                }
            }

            // Return 1-3 of the base material instead of the finished gear
            let count = Math.floor(Math.random() * 3) + 1;
            return Item.of(replacementId, count);
        });
});