Example #1
0
  // best recipe for current state of potion, STILL not always returns the
  // correct one...
  public BRecipe getBestRecipe(float wood, float time, boolean distilled) {
    float quality = 0;
    int ingredientQuality;
    int cookingQuality;
    int woodQuality;
    int ageQuality;
    BRecipe bestRecipe = null;
    for (BRecipe recipe : recipes) {
      ingredientQuality = getIngredientQuality(recipe);
      cookingQuality = getCookingQuality(recipe, distilled);

      if (ingredientQuality > -1 && cookingQuality > -1) {
        if (recipe.needsToAge() || time > 0.5) {
          // needs riping in barrel
          ageQuality = getAgeQuality(recipe, time);
          woodQuality = getWoodQuality(recipe, wood);
          P.p.debugLog(
              "Ingredient Quality: "
                  + ingredientQuality
                  + " Cooking Quality: "
                  + cookingQuality
                  + " Wood Quality: "
                  + woodQuality
                  + " age Quality: "
                  + ageQuality
                  + " for "
                  + recipe.getName(5));

          // is this recipe better than the previous best?
          if ((((float) ingredientQuality + cookingQuality + woodQuality + ageQuality) / 4)
              > quality) {
            quality = ((float) ingredientQuality + cookingQuality + woodQuality + ageQuality) / 4;
            bestRecipe = recipe;
          }
        } else {
          P.p.debugLog(
              "Ingredient Quality: "
                  + ingredientQuality
                  + " Cooking Quality: "
                  + cookingQuality
                  + " for "
                  + recipe.getName(5));
          // calculate quality without age and barrel
          if ((((float) ingredientQuality + cookingQuality) / 2) > quality) {
            quality = ((float) ingredientQuality + cookingQuality) / 2;
            bestRecipe = recipe;
          }
        }
      }
    }
    if (bestRecipe != null) {
      P.p.debugLog("best recipe: " + bestRecipe.getName(5) + " has Quality= " + quality);
    }
    return bestRecipe;
  }
Example #2
0
  // returns an Potion item with cooked ingredients
  public ItemStack cook(int state) {

    ItemStack potion = new ItemStack(Material.POTION);
    PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();

    // cookedTime is always time in minutes, state may differ with number of ticks
    cookedTime = state;
    String cookedName = null;
    BRecipe cookRecipe = getCookRecipe();

    int uid = Brew.generateUID();

    if (cookRecipe != null) {
      // Potion is best with cooking only
      int quality =
          (int)
              Math.round(
                  (getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0);
      P.p.debugLog("cooked potion has Quality: " + quality);
      Brew brew = new Brew(uid, quality, cookRecipe, this);
      Brew.addOrReplaceEffects(potionMeta, brew.getEffects());

      cookedName = cookRecipe.getName(quality);
      potion.setDurability(Brew.PotionColor.valueOf(cookRecipe.getColor()).getColorId(false));

    } else {
      // new base potion
      new Brew(uid, this);

      if (state <= 1) {
        cookedName = P.p.languageReader.get("Brew_ThickBrew");
        potion.setDurability(Brew.PotionColor.BLUE.getColorId(false));
      } else {
        for (Material ingredient : ingredients.keySet()) {
          if (cookedNames.containsKey(ingredient)) {
            // if more than half of the ingredients is of one kind
            if (ingredients.get(ingredient) > (getIngredientsCount() / 2)) {
              cookedName = cookedNames.get(ingredient);
              potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
            }
          }
        }
      }
    }
    if (cookedName == null) {
      // if no name could be found
      cookedName = P.p.languageReader.get("Brew_Undefined");
      potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
    }

    potionMeta.setDisplayName(P.p.color("&f" + cookedName));
    // This effect stores the UID in its Duration
    potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
    potion.setItemMeta(potionMeta);

    return potion;
  }