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