const potionQuests = {
  // TaskId: PotionEffect
  "417152BD4FDAD199": "monobank:thief",
};
// give each quest Task 1 max Progress
Object.keys(potionQuests).forEach((questId) => {
  FTBQuestsEvents.customTask(questId, (event) => {
    event.setMaxProgress(1);
  });
});

PlayerEvents.tick((event) => {
  const { player, level } = event;

  // Pdata Timer
  let pData = player.persistentData;
  pData.questTimer = pData.questTimer ?? 0;
  pData.questTimer++;
  if (pData.questTimer % 20 != 0) return;
  pData.questTimer = 0;

  // Loop through all potion Quests
  Object.keys(potionQuests).forEach((questId) => {
    let task = getQuestObject(level, questId);
    let potion = potionQuests[questId];
    if (
      player.potionEffects.isActive(potion) &&
      getQuestProgress(player, task) < 1
    ) {
      addQuestProgress(player, task, 1);
    }
  });
});

let getQuestData = (player) => FTBQuests.getData(player);
let getQuestObject = (level, id) => FTBQuests.getObject(level, id);
let getQuestProgress = (player, questObject) =>
  getQuestData(player).getProgress(questObject);
// let setQuestProgress = (player, questObject, progress) => getQuestData(player).setProgress(questObject, progress)
let addQuestProgress = (player, questObject, amount) =>
  getQuestData(player).addProgress(questObject, amount);
