// 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) => {
  event
    .addLootTypeModifier([
      LootType.ENTITY,
      LootType.UNKNOWN,
      LootType.BLOCK,
      LootType.ENTITY,
      LootType.CHEST,
      LootType.FISHING,
      LootType.GIFT,
    ])
    .apply((context) => {
      try {
        let lootToRemove = [];
        context.forEachLoot((item) => {
          // console.log("LOOT: " + item.id);
          let itemIDString = item.id.toString(); //This is the item name
          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);
      }
    });
});
