Search in sources :

Example 51 with ListTag

use of net.minecraft.nbt.ListTag 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)

Example 52 with ListTag

use of net.minecraft.nbt.ListTag in project Tropicraft by Tropicraft.

the class CocktailItem method getIngredients.

public static Ingredient[] getIngredients(ItemStack stack) {
    if (!Drink.isDrink(stack.getItem()) || !stack.hasTag()) {
        return new Ingredient[0];
    }
    CompoundTag nbt = stack.getTag();
    ListTag tagList = nbt.getList("Ingredients", 10);
    Ingredient[] ingredients = new Ingredient[tagList.size()];
    for (int i = 0; i < tagList.size(); ++i) {
        final int ingredientID = (tagList.getCompound(i)).getByte("IngredientID");
        ingredients[i] = Ingredient.ingredientsList[ingredientID];
    }
    return ingredients;
}
Also used : Ingredient(net.tropicraft.core.common.drinks.Ingredient) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

ListTag (net.minecraft.nbt.ListTag)52 CompoundTag (net.minecraft.nbt.CompoundTag)38 ItemStack (net.minecraft.world.item.ItemStack)10 TagCompound (de.keyle.knbt.TagCompound)8 TagList (de.keyle.knbt.TagList)8 List (java.util.List)7 IntArrayTag (net.minecraft.nbt.IntArrayTag)7 ResourceLocation (net.minecraft.resources.ResourceLocation)7 TagString (de.keyle.knbt.TagString)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 StringTag (net.minecraft.nbt.StringTag)5 ByteArrayTag (net.minecraft.nbt.ByteArrayTag)4 IntTag (net.minecraft.nbt.IntTag)4 Tag (net.minecraft.nbt.Tag)4 ByteTag (net.minecraft.nbt.ByteTag)3 DoubleTag (net.minecraft.nbt.DoubleTag)3 FloatTag (net.minecraft.nbt.FloatTag)3 LongTag (net.minecraft.nbt.LongTag)3 ShortTag (net.minecraft.nbt.ShortTag)3