Example #1
0
  private void mixPotions() {
    ItemStack resultPotion = new ItemStack(ModItems.mixedPotion, 1);
    int emulsifierLevel = calculateEmulsifierLevel();
    ArrayList<PotionEffect> resultList = new ArrayList<PotionEffect>();
    NBTTagCompound potionEffects = new NBTTagCompound();
    NBTTagList taglist = new NBTTagList();

    for (int i = POTION_START; i < getSizeInventory(); i++) {
      ItemStack potion = getStackInSlot(i);
      ArrayList<PotionEffect> effectList = getPotionEffects(potion);
      if (resultList.size() == emulsifierLevel) {
        break;
      } else if (resultList.size() + effectList.size() > emulsifierLevel) {
        continue;
      } else {
        for (PotionEffect effect : effectList) {
          if (!resultList.contains(effect)) {
            resultList.add(effect);
            NBTTagCompound effectCompound = new NBTTagCompound();
            taglist.appendTag(effect.writeCustomPotionEffectToNBT(effectCompound));
          }
        }
        // since this potion was used, remove it from the inventory
        setInventorySlotContents(i, null);
      }
    }

    potionEffects.setTag("CustomPotionEffects", taglist);
    resultPotion.setTagCompound(potionEffects);
    setInventorySlotContents(EMULSIFIER_INDEX, decrStackSize(EMULSIFIER_INDEX, 1));
    setInventorySlotContents(RESULT_INDEX, resultPotion);
  }