Search in sources :

Example 6 with Ingredient

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

the class ItemCocktail method makeCocktail.

@Nonnull
public static ItemStack makeCocktail(MixerRecipe recipe) {
    ItemStack stack = new ItemStack(ItemRegistry.cocktail);
    NBTTagCompound nbt = new NBTTagCompound();
    Drink drink = recipe.getCraftingResult();
    nbt.setByte("DrinkID", (byte) drink.drinkId);
    NBTTagList tagList = new NBTTagList();
    Ingredient primary = null;
    List<Ingredient> additives = new LinkedList<Ingredient>();
    for (Ingredient ingredient : recipe.getIngredients()) {
        NBTTagCompound ingredientNbt = new NBTTagCompound();
        ingredientNbt.setByte("IngredientID", (byte) ingredient.id);
        tagList.appendTag(ingredientNbt);
        if (ingredient.isPrimary()) {
            primary = ingredient;
        } else {
            additives.add(ingredient);
        }
    }
    nbt.setTag("Ingredients", tagList);
    int color = primary == null ? DEFAULT_COLOR : primary.getColor();
    for (Ingredient additive : additives) {
        color = ColorMixer.getInstance().alphaBlendRGBA(color, additive.getColor(), additive.getAlpha());
    }
    nbt.setInteger("Color", color);
    stack.setTagCompound(nbt);
    return stack;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Ingredient(net.tropicraft.core.common.drinks.Ingredient) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Drink(net.tropicraft.core.common.drinks.Drink) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull)

Example 7 with Ingredient

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

the class ItemCocktail method makeCocktail.

@Nonnull
public static ItemStack makeCocktail(Ingredient[] ingredients) {
    ItemStack stack = new ItemStack(ItemRegistry.cocktail);
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setByte("DrinkID", (byte) 0);
    NBTTagList tagList = new NBTTagList();
    Ingredient primary = null;
    List<Ingredient> additives = new LinkedList<Ingredient>();
    for (Ingredient ingredient : ingredients) {
        NBTTagCompound ingredientNbt = new NBTTagCompound();
        ingredientNbt.setByte("IngredientID", (byte) ingredient.id);
        tagList.appendTag(ingredientNbt);
        if (ingredient.isPrimary()) {
            primary = ingredient;
        } else {
            additives.add(ingredient);
        }
    }
    nbt.setTag("Ingredients", tagList);
    int color = primary == null ? DEFAULT_COLOR : primary.getColor();
    for (Ingredient additive : additives) {
        color = ColorMixer.getInstance().alphaBlendRGBA(color, additive.getColor(), additive.getAlpha());
    }
    nbt.setInteger("Color", color);
    stack.setTagCompound(nbt);
    return stack;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Ingredient(net.tropicraft.core.common.drinks.Ingredient) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull)

Example 8 with Ingredient

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

the class ItemCocktail method getIngredients.

public static Ingredient[] getIngredients(ItemStack stack) {
    if (stack.getItem() != ItemRegistry.cocktail || !stack.hasTagCompound()) {
        return new Ingredient[0];
    }
    NBTTagCompound nbt = stack.getTagCompound();
    NBTTagList tagList = nbt.getTagList("Ingredients", 10);
    Ingredient[] ingredients = new Ingredient[tagList.tagCount()];
    for (int i = 0; i < tagList.tagCount(); ++i) {
        int id = ((NBTTagCompound) tagList.getCompoundTagAt(i)).getByte("IngredientID");
        ingredients[i] = Ingredient.ingredientsList[id];
    }
    return ingredients;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Ingredient(net.tropicraft.core.common.drinks.Ingredient) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 9 with Ingredient

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

the class CocktailItem method makeCocktail.

@Nonnull
public static ItemStack makeCocktail(final NonNullList<ItemStack> itemStacks) {
    // TODO fixme this is so ugly ugh
    final ItemStack stack = new ItemStack(TropicraftItems.COCKTAILS.get(Drink.COCKTAIL).get());
    CompoundTag nbt = new CompoundTag();
    nbt.putByte("DrinkID", (byte) Drink.COCKTAIL.drinkId);
    ListTag tagList = new ListTag();
    List<Ingredient> ingredients = new ArrayList<>();
    for (ItemStack ingredientStack : itemStacks) {
        ingredients.addAll(Ingredient.listIngredients(ingredientStack));
    }
    Collections.sort(ingredients);
    Ingredient primary = null;
    List<Ingredient> additives = new LinkedList<>();
    for (Ingredient ingredient : ingredients) {
        CompoundTag ingredientNbt = new CompoundTag();
        ingredientNbt.putByte("IngredientID", (byte) ingredient.id);
        tagList.add(ingredientNbt);
        if (ingredient.isPrimary()) {
            primary = ingredient;
        } else {
            additives.add(ingredient);
        }
    }
    nbt.put("Ingredients", tagList);
    int color = primary == null ? DEFAULT_COLOR : primary.getColor();
    for (Ingredient additive : additives) {
        color = ColorMixer.getInstance().alphaBlendRGBA(color, additive.getColor(), additive.getAlpha());
    }
    nbt.putInt("Color", color);
    stack.setTag(nbt);
    return stack;
}
Also used : Ingredient(net.tropicraft.core.common.drinks.Ingredient) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.world.item.ItemStack) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull)

Example 10 with Ingredient

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

the class CocktailItem method makeCocktail.

@Nonnull
public static ItemStack makeCocktail(MixerRecipe recipe) {
    final ItemStack stack = MixerRecipes.getItemStack(recipe.getCraftingResult());
    CompoundTag nbt = new CompoundTag();
    Drink drink = recipe.getCraftingResult();
    nbt.putByte("DrinkID", (byte) drink.drinkId);
    ListTag tagList = new ListTag();
    Ingredient primary = null;
    List<Ingredient> additives = new LinkedList<>();
    for (Ingredient ingredient : recipe.getIngredients()) {
        CompoundTag ingredientNbt = new CompoundTag();
        ingredientNbt.putByte("IngredientID", (byte) ingredient.id);
        tagList.add(ingredientNbt);
        if (ingredient.isPrimary()) {
            primary = ingredient;
        } else {
            additives.add(ingredient);
        }
    }
    nbt.put("Ingredients", tagList);
    int color = primary == null ? DEFAULT_COLOR : primary.getColor();
    for (Ingredient additive : additives) {
        color = ColorMixer.getInstance().alphaBlendRGBA(color, additive.getColor(), additive.getAlpha());
    }
    nbt.putInt("Color", color);
    stack.setTag(nbt);
    return stack;
}
Also used : Ingredient(net.tropicraft.core.common.drinks.Ingredient) Drink(net.tropicraft.core.common.drinks.Drink) ItemStack(net.minecraft.world.item.ItemStack) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull)

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