Advertisement
Guest User

getIngredientQuality

a guest
May 2nd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1.     public int getIngredientQuality(BRecipe recipe) {
  2.         float quality = 10;
  3.         int count;
  4.         int badStuff = 0;
  5.         if (recipe.isMissingIngredients(ingredients)) {
  6.             // when ingredients are not complete
  7.             return -1;
  8.         }
  9.         ArrayList<Material> mergedChecked = new ArrayList<Material>();
  10.         for (ItemStack ingredient : ingredients) {
  11.             if (mergedChecked.contains(ingredient.getType())) {
  12.                 // This ingredient type was already checked as part of a merged material
  13.                 continue;
  14.             }
  15.             int amountInRecipe = recipe.amountOf(ingredient);
  16.             // If we dont consider durability for this ingredient, check the merged material
  17.             if (recipe.hasExactData(ingredient)) {
  18.                 count = ingredient.getAmount();
  19.             } else {
  20.                 mergedChecked.add(ingredient.getType());
  21.                 count = materials.get(ingredient.getType());
  22.             }
  23.             if (amountInRecipe == 0) {
  24.                 // this ingredient doesnt belong into the recipe
  25.                 if (count > (getIngredientsCount() / 2)) {
  26.                     // when more than half of the ingredients dont fit into the
  27.                     // recipe
  28.                     return -1;
  29.                 }
  30.                 badStuff++;
  31.                 if (badStuff < ingredients.size()) {
  32.                     // when there are other ingredients
  33.                     quality -= count * (recipe.getDifficulty() / 2);
  34.                     continue;
  35.                 } else {
  36.                     // ingredients dont fit at all
  37.                     return -1;
  38.                 }
  39.             }
  40.             // calculate the quality
  41.             quality -= ((float) Math.abs(count - amountInRecipe) / recipe.allowedCountDiff(amountInRecipe)) * 10.0;
  42.         }
  43.         if (quality >= 0) {
  44.             return Math.round(quality);
  45.         }
  46.         return -1;
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement