Search in sources :

Example 1 with MixerRecipe

use of net.tropicraft.core.common.drinks.MixerRecipe in project Tropicraft by Tropicraft.

the class DrinkMixerRegistry method getResult.

@Nonnull
public static ItemStack getResult(NonNullList<ItemStack> ingredients) {
    for (MixerRecipe recipe : recipes) {
        int validIngredientsFound = 0;
        for (Ingredient recipeIngredient : recipe.getIngredients()) {
            for (ItemStack mixerIngredient : ingredients) {
                if (ItemStack.areItemStacksEqual(recipeIngredient.getIngredient(), mixerIngredient)) {
                    validIngredientsFound++;
                    break;
                }
            }
        }
        // Make sure to only count valid ingredients (non-empty) when getting size
        if (validIngredientsFound == ingredients.stream().filter(i -> !i.isEmpty()).count()) {
            return ItemCocktail.makeCocktail(recipe);
        }
    }
    List<Ingredient> is = new ArrayList<Ingredient>();
    for (ItemStack ingredientStack : ingredients) {
        is.addAll(Ingredient.listIngredients(ingredientStack));
    }
    Collections.sort(is);
    return ItemCocktail.makeCocktail(is.toArray(new Ingredient[is.size()]));
}
Also used : MixerRecipe(net.tropicraft.core.common.drinks.MixerRecipe) Ingredient(net.tropicraft.core.common.drinks.Ingredient) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 ItemStack (net.minecraft.item.ItemStack)1 Ingredient (net.tropicraft.core.common.drinks.Ingredient)1 MixerRecipe (net.tropicraft.core.common.drinks.MixerRecipe)1