Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int getIngredientQuality(BRecipe recipe) {
- float quality = 10;
- int count;
- int badStuff = 0;
- if (recipe.isMissingIngredients(ingredients)) {
- // when ingredients are not complete
- return -1;
- }
- ArrayList<Material> mergedChecked = new ArrayList<Material>();
- for (ItemStack ingredient : ingredients) {
- if (mergedChecked.contains(ingredient.getType())) {
- // This ingredient type was already checked as part of a merged material
- continue;
- }
- int amountInRecipe = recipe.amountOf(ingredient);
- // If we dont consider durability for this ingredient, check the merged material
- if (recipe.hasExactData(ingredient)) {
- count = ingredient.getAmount();
- } else {
- mergedChecked.add(ingredient.getType());
- count = materials.get(ingredient.getType());
- }
- if (amountInRecipe == 0) {
- // this ingredient doesnt belong into the recipe
- if (count > (getIngredientsCount() / 2)) {
- // when more than half of the ingredients dont fit into the
- // recipe
- return -1;
- }
- badStuff++;
- if (badStuff < ingredients.size()) {
- // when there are other ingredients
- quality -= count * (recipe.getDifficulty() / 2);
- continue;
- } else {
- // ingredients dont fit at all
- return -1;
- }
- }
- // calculate the quality
- quality -= ((float) Math.abs(count - amountInRecipe) / recipe.allowedCountDiff(amountInRecipe)) * 10.0;
- }
- if (quality >= 0) {
- return Math.round(quality);
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement