// priority: 10

/*
Disable ALL cyclic loot tables
kubejs loot events:
- ServerEvents.blockLootTables
- ServerEvents.entityLootTables 
- ServerEvents.giftLootTables
- ServerEvents.fishingLootTables
- ServerEvents.chestLootTables

LootJS Loot Types:
- LootType.UNKNOWN
- LootType.BLOCK
- LootType.ENTITY
- LootType.CHEST
- LootType.FISHING
- LootType.GIFT 
*/

/**
 * Test the loot blocker
 */
// LootJS.modifiers((event) => {
//   event
//     .addLootTypeModifier(LootType.BLOCK) //For every entity we kill, we have a 99% chance to get a flute
//     .randomChance(1.0)
//     .addLoot("cyclic:sprinkler");
//   event
//     .addLootTypeModifier(LootType.ENTITY) //For every entity we kill, we have a 99% chance to get a flute
//     .randomChance(1.0)
//     .addLoot("cyclic:flute_summoning");
//   event
//     .addLootTypeModifier(LootType.CHEST) //For every chest we open, we have a 99% chance to get a charm
//     .randomChance(1.0)
//     .addLoot("cyclic:charm_ultimate");
// });

/**
 *
 *
 *
 *
 * Remove all loot that starts with "cyclic:"
 */
LootJS.modifiers((event) => {
  //Block loot should not contain any OP stuff and It needs to be kept for the sake of the existing whitelisted items
  event
    .addLootTypeModifier([
      LootType.ENTITY,
      LootType.UNKNOWN,
      // LootType.BLOCK,
      LootType.ENTITY,
      LootType.CHEST,
      LootType.FISHING,
      LootType.GIFT,
    ])
    .apply((context) => {
      try {
        let lootToRemove = [];
        context.forEachLoot((item) => {
          let itemIDString = item.id.toString(); //This is the item name
          // let inWhitelist = whitelist.includes(itemIDString); //This does indeed work
          // console.log("LOOT: " + itemIDString + ", IN WHITELIST: " + inWhitelist);

          if (itemIDString.startsWith("cyclic:")) {
            // console.log("LOOT: Removing loot: " + itemIDString);
            lootToRemove.push(item);
          }
        });
        for (let i = 0; i < lootToRemove.length; i++) {
          context.removeLoot(lootToRemove[i]);
        }
      } catch (error) {
        console.log("LOOT ERROR: " + error);
      }
    });
});
