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;
}
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;
}
Aggregations