Search in sources :

Example 6 with Drink

use of net.tropicraft.core.common.drinks.Drink 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 Drink

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

the class ItemCocktail method onItemUseFinish.

/**
 * 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
@Nonnull
public ItemStack onItemUseFinish(@Nonnull ItemStack stack, @Nonnull World worldIn, @Nonnull EntityLivingBase entityLiving) {
    if (entityLiving instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entityLiving;
        this.onFoodEaten(stack, worldIn, player);
        Drink drink = getDrink(stack);
        if (worldIn.isRainingAt(player.getPosition()) && drink == Drink.pinaColada) {
        // TODO advancements player.addStat(AchievementRegistry.drinkPinaColada);
        }
    }
    return new ItemStack(ItemRegistry.bambooMug);
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Drink(net.tropicraft.core.common.drinks.Drink) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 8 with Drink

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

the class ItemCocktail method getUnlocalizedName.

@Override
public String getUnlocalizedName(ItemStack itemstack) {
    @Nonnull String name = getUnlocalizedName();
    Drink drink = getDrink(itemstack);
    if (drink != null) {
        name = Info.MODID + ".drink." + drink.name;
    }
    return name;
}
Also used : Nonnull(javax.annotation.Nonnull) Drink(net.tropicraft.core.common.drinks.Drink)

Example 9 with Drink

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

the class BlockDrinkMixer method onBlockActivated.

@Override
public boolean onBlockActivated(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull EntityPlayer entityPlayer, @Nonnull EnumHand hand, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return true;
    }
    ItemStack stack = entityPlayer.getHeldItemMainhand();
    TileEntityDrinkMixer mixer = (TileEntityDrinkMixer) world.getTileEntity(pos);
    if (mixer == null) {
        return false;
    }
    if (mixer.isDoneMixing()) {
        mixer.retrieveResult(entityPlayer);
        return true;
    }
    if (stack.isEmpty()) {
        mixer.emptyMixer(entityPlayer);
        return true;
    }
    ItemStack ingredientStack = stack.copy();
    ingredientStack.setCount(1);
    if (mixer.addToMixer(ingredientStack)) {
        entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
    }
    if (ingredientStack.getItem() == ItemRegistry.bambooMug && mixer.canMix()) {
        mixer.startMixing();
        entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
        Drink craftedDrink = MixerRecipes.getDrink(mixer.ingredients);
        Drink pinaColada = Drink.pinaColada;
        if (craftedDrink != null && craftedDrink.drinkId == pinaColada.drinkId) {
        // TODO advancements entityPlayer.addStat(AchievementRegistry.craftPinaColada);
        }
    }
    return true;
}
Also used : TileEntityDrinkMixer(net.tropicraft.core.common.block.tileentity.TileEntityDrinkMixer) Drink(net.tropicraft.core.common.drinks.Drink) ItemStack(net.minecraft.item.ItemStack)

Example 10 with Drink

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

the class DrinkMixerBlock method use.

@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
    if (world.isClientSide) {
        return InteractionResult.SUCCESS;
    }
    ItemStack stack = player.getMainHandItem();
    DrinkMixerBlockEntity mixer = (DrinkMixerBlockEntity) world.getBlockEntity(pos);
    if (mixer == null) {
        return InteractionResult.FAIL;
    }
    if (mixer.isDoneMixing()) {
        mixer.retrieveResult(player);
        return InteractionResult.CONSUME;
    }
    if (stack.isEmpty()) {
        mixer.emptyMixer(player);
        return InteractionResult.CONSUME;
    }
    ItemStack ingredientStack = stack.copy();
    ingredientStack.setCount(1);
    if (mixer.addToMixer(ingredientStack)) {
        if (!player.isCreative()) {
            player.getInventory().removeItem(player.getInventory().selected, 1);
        }
    }
    if (ingredientStack.getItem() == TropicraftItems.BAMBOO_MUG.get() && mixer.canMix()) {
        mixer.startMixing();
        if (!player.isCreative()) {
            player.getInventory().removeItem(player.getInventory().selected, 1);
        }
        Drink craftedDrink = MixerRecipes.getDrink(mixer.ingredients);
        Drink pinaColada = Drink.PINA_COLADA;
        if (craftedDrink != null && craftedDrink.drinkId == pinaColada.drinkId) {
        // TODO advancements entityPlayer.addStat(AchievementRegistry.craftPinaColada);
        }
    }
    return InteractionResult.CONSUME;
}
Also used : DrinkMixerBlockEntity(net.tropicraft.core.common.block.tileentity.DrinkMixerBlockEntity) 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