Search in sources :

Example 11 with Drink

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);
}
Also used : InteractionResultHolder(net.minecraft.world.InteractionResultHolder) Drink(net.tropicraft.core.common.drinks.Drink) ItemStack(net.minecraft.world.item.ItemStack)

Example 12 with Drink

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;
}
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 13 with Drink

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());
}
Also used : Player(net.minecraft.world.entity.player.Player) Drink(net.tropicraft.core.common.drinks.Drink) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

Drink (net.tropicraft.core.common.drinks.Drink)13 Nonnull (javax.annotation.Nonnull)5 ItemStack (net.minecraft.item.ItemStack)5 ItemStack (net.minecraft.world.item.ItemStack)5 Ingredient (net.tropicraft.core.common.drinks.Ingredient)4 LinkedList (java.util.LinkedList)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Component (net.minecraft.network.chat.Component)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 InteractionResultHolder (net.minecraft.world.InteractionResultHolder)1 Player (net.minecraft.world.entity.player.Player)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 DrinkMixerBlockEntity (net.tropicraft.core.common.block.tileentity.DrinkMixerBlockEntity)1 TileEntityDrinkMixer (net.tropicraft.core.common.block.tileentity.TileEntityDrinkMixer)1