Search in sources :

Example 1 with Ingredient

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

the class TileEntityDrinkMixer method addToMixer.

public boolean addToMixer(@Nonnull ItemStack ingredient) {
    if (this.ingredients.get(0).isEmpty()) {
        if (ingredient.getItem() != ItemRegistry.cocktail) {
            Ingredient i = findMatchingIngredient(ingredient);
            // is as relevant anymore. Will leave it here just in case!
            if (i == null) /* || !i.isPrimary()*/
            {
                return false;
            }
        }
        this.ingredients.set(0, ingredient);
        syncInventory();
        return true;
    } else if (this.ingredients.get(1).isEmpty()) {
        if (ingredient.getItem() == ItemRegistry.cocktail) {
            // all cocktails already contain one
            return false;
        }
        Ingredient ing0 = findMatchingIngredient(this.ingredients.get(0));
        Ingredient i = findMatchingIngredient(ingredient);
        // See above comment about isPrimary()
        if (i == null || /* || i.isPrimary()*/
        ing0.id == i.id) {
            return false;
        }
        this.ingredients.set(1, ingredient);
        syncInventory();
        return true;
    } else if (this.ingredients.get(2).isEmpty()) {
        if (ingredient.getItem() == ItemRegistry.cocktail) {
            // all cocktails already contain one
            return false;
        }
        Ingredient ing0 = findMatchingIngredient(this.ingredients.get(0));
        Ingredient ing1 = findMatchingIngredient(this.ingredients.get(1));
        Ingredient i = findMatchingIngredient(ingredient);
        // See above comment about isPrimary()
        if (i == null || /* || i.isPrimary()*/
        ing0.id == i.id || ing1.id == i.id) {
            return false;
        }
        this.ingredients.set(2, ingredient);
        syncInventory();
        return true;
    } else {
        return false;
    }
}
Also used : Ingredient(net.tropicraft.core.common.drinks.Ingredient)

Example 2 with Ingredient

use of net.tropicraft.core.common.drinks.Ingredient 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)

Example 3 with Ingredient

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

the class ItemCocktail method onFoodEaten.

public ItemStack onFoodEaten(ItemStack itemstack, World world, EntityPlayer player) {
    world.playSound(player, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
    for (Ingredient ingredient : getIngredients(itemstack)) {
        ingredient.onDrink(player);
    }
    Drink drink = getDrink(itemstack);
    if (drink != null) {
        drink.onDrink(player);
    }
    return new ItemStack(ItemRegistry.bambooMug);
}
Also used : Ingredient(net.tropicraft.core.common.drinks.Ingredient) Drink(net.tropicraft.core.common.drinks.Drink) ItemStack(net.minecraft.item.ItemStack)

Example 4 with Ingredient

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

the class DrinkMixerBlockEntity method addToMixer.

public boolean addToMixer(@Nonnull ItemStack ingredient) {
    if (ingredients.get(0).isEmpty()) {
        if (!Drink.isDrink(ingredient.getItem())) {
            Ingredient i = Ingredient.findMatchingIngredient(ingredient);
            // is as relevant anymore. Will leave it here just in case!
            if (i == null) /* || !i.isPrimary()*/
            {
                return false;
            }
        }
        ingredients.set(0, ingredient);
        syncInventory();
        return true;
    } else if (ingredients.get(1).isEmpty()) {
        if (Drink.isDrink(ingredient.getItem())) {
            // all cocktails already contain one
            return false;
        }
        Ingredient ing0 = Ingredient.findMatchingIngredient(ingredients.get(0));
        Ingredient i = Ingredient.findMatchingIngredient(ingredient);
        // See above comment about isPrimary()
        if (i == null || /* || i.isPrimary()*/
        ing0.id == i.id) {
            return false;
        }
        ingredients.set(1, ingredient);
        syncInventory();
        return true;
    } else if (ingredients.get(2).isEmpty()) {
        if (Drink.isDrink(ingredient.getItem())) {
            // all cocktails already contain one
            return false;
        }
        Ingredient ing0 = Ingredient.findMatchingIngredient(ingredients.get(0));
        Ingredient ing1 = Ingredient.findMatchingIngredient(ingredients.get(1));
        Ingredient i = Ingredient.findMatchingIngredient(ingredient);
        // See above comment about isPrimary()
        if (i == null || /* || i.isPrimary()*/
        ing0.id == i.id || ing1.id == i.id) {
            return false;
        }
        ingredients.set(2, ingredient);
        syncInventory();
        return true;
    } else {
        return false;
    }
}
Also used : Ingredient(net.tropicraft.core.common.drinks.Ingredient)

Example 5 with Ingredient

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

the class CocktailItem method onFoodEaten.

public ItemStack onFoodEaten(ItemStack itemstack, Level world, Player player) {
    world.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_BURP, SoundSource.PLAYERS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
    for (Ingredient ingredient : getIngredients(itemstack)) {
        ingredient.onDrink(player);
    }
    Drink drink = getDrink(itemstack);
    if (drink != null) {
        drink.onDrink(player);
    }
    return new ItemStack(TropicraftItems.BAMBOO_MUG.get());
}
Also used : Ingredient(net.tropicraft.core.common.drinks.Ingredient) Drink(net.tropicraft.core.common.drinks.Drink) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

Ingredient (net.tropicraft.core.common.drinks.Ingredient)11 Nonnull (javax.annotation.Nonnull)5 LinkedList (java.util.LinkedList)4 ItemStack (net.minecraft.item.ItemStack)4 Drink (net.tropicraft.core.common.drinks.Drink)4 CompoundTag (net.minecraft.nbt.CompoundTag)3 ListTag (net.minecraft.nbt.ListTag)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 ItemStack (net.minecraft.world.item.ItemStack)3 ArrayList (java.util.ArrayList)2 MixerRecipe (net.tropicraft.core.common.drinks.MixerRecipe)1