Beispiel #1
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;
  }
Beispiel #2
0
  public static ItemStack createItemStack() {
    ItemStack ret = new ItemStack(Material.POTION, 1, POTION_VALUES.get(0).shortValue());

    PotionMeta meta = (PotionMeta) ret.getItemMeta();
    meta.setDisplayName(NAME);
    meta.setLore(LORE);
    meta.addCustomEffect(EFFECT, false);
    ret.setItemMeta(meta);

    return ret;
  }
Beispiel #3
0
  // Create a Potion from this Recipe with best values. Quality can be set, but will reset to 10 if
  // put in a barrel
  public ItemStack create(int quality) {
    ItemStack potion = new ItemStack(Material.POTION);
    PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();

    int uid = Brew.generateUID();

    ArrayList<ItemStack> list = new ArrayList<ItemStack>(ingredients.size());
    for (ItemStack item : ingredients) {
      if (item.getDurability() == -1) {
        list.add(new ItemStack(item.getType(), item.getAmount()));
      } else {
        list.add(item.clone());
      }
    }

    BIngredients bIngredients = new BIngredients(list, cookingTime);

    Brew brew =
        new Brew(
            uid,
            bIngredients,
            quality,
            distillruns,
            getAge(),
            wood,
            getName(5),
            false,
            false,
            true);

    potion.setDurability(Brew.PotionColor.valueOf(getColor()).getColorId(false));
    potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
    // This effect stores the UID in its Duration
    potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);

    brew.convertLore(potionMeta, false);
    Brew.addOrReplaceEffects(potionMeta, effects, quality);

    potion.setItemMeta(potionMeta);
    return potion;
  }