use of net.tropicraft.core.common.drinks.Drink in project Tropicraft by Tropicraft.
the class CocktailItem method use.
@Override
public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, InteractionHand hand) {
ItemStack stack = playerIn.getItemInHand(hand);
Drink drink = getDrink(stack);
if (drink == null) {
return new InteractionResultHolder<>(InteractionResult.FAIL, stack);
}
playerIn.startUsingItem(hand);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
use of net.tropicraft.core.common.drinks.Drink 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.tropicraft.core.common.drinks.Drink in project Tropicraft by Tropicraft.
the class CocktailItem method finishUsingItem.
/**
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
* the Item before the action is complete.
*/
@Override
public ItemStack finishUsingItem(@Nonnull ItemStack stack, @Nonnull Level worldIn, @Nonnull LivingEntity entityLiving) {
if (entityLiving instanceof Player) {
final Player player = (Player) entityLiving;
onFoodEaten(stack, worldIn, player);
Drink drink = getDrink(stack);
if (worldIn.isRainingAt(player.blockPosition()) && drink == Drink.PINA_COLADA) {
// TODO 1.17 advancements player.addStat(AchievementRegistry.drinkPinaColada);
}
return player.getAbilities().instabuild ? stack : new ItemStack(TropicraftItems.BAMBOO_MUG.get());
}
return new ItemStack(TropicraftItems.BAMBOO_MUG.get());
}
Aggregations