Java Code Examples for net.minecraft.entity.player.EntityPlayer.canEat()

The following are Jave code examples for showing how to use canEat() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DecompiledMinecraft   File: BlockCake.java   View Source Code Vote up 6 votes
private void eatCake(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (player.canEat(false))
    {
        player.triggerAchievement(StatList.field_181724_H);
        player.getFoodStats().addStats(2, 0.1F);
        int i = ((Integer)state.getValue(BITES)).intValue();

        if (i < 6)
        {
            worldIn.setBlockState(pos, state.withProperty(BITES, Integer.valueOf(i + 1)), 3);
        }
        else
        {
            worldIn.setBlockToAir(pos);
        }
    }
}
 
Example 2
Project: DecompiledMinecraft   File: BlockCake.java   View Source Code Vote up 6 votes
private void eatCake(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (player.canEat(false))
    {
        player.triggerAchievement(StatList.field_181724_H);
        player.getFoodStats().addStats(2, 0.1F);
        int i = ((Integer)state.getValue(BITES)).intValue();

        if (i < 6)
        {
            worldIn.setBlockState(pos, state.withProperty(BITES, Integer.valueOf(i + 1)), 3);
        }
        else
        {
            worldIn.setBlockToAir(pos);
        }
    }
}
 
Example 3
Project: BaseClient   File: BlockCake.java   View Source Code Vote up 6 votes
private void eatCake(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (player.canEat(false))
    {
        player.triggerAchievement(StatList.field_181724_H);
        player.getFoodStats().addStats(2, 0.1F);
        int i = ((Integer)state.getValue(BITES)).intValue();

        if (i < 6)
        {
            worldIn.setBlockState(pos, state.withProperty(BITES, Integer.valueOf(i + 1)), 3);
        }
        else
        {
            worldIn.setBlockToAir(pos);
        }
    }
}
 
Example 4
Project: BaseClient   File: BlockCake.java   View Source Code Vote up 6 votes
private void eatCake(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (player.canEat(false))
    {
        player.triggerAchievement(StatList.field_181724_H);
        player.getFoodStats().addStats(2, 0.1F);
        int i = ((Integer)state.getValue(BITES)).intValue();

        if (i < 6)
        {
            worldIn.setBlockState(pos, state.withProperty(BITES, Integer.valueOf(i + 1)), 3);
        }
        else
        {
            worldIn.setBlockToAir(pos);
        }
    }
}
 
Example 5
Project: Backmemed   File: BlockCake.java   View Source Code Vote up 6 votes
private boolean eatCake(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (!player.canEat(false))
    {
        return false;
    }
    else
    {
        player.addStat(StatList.CAKE_SLICES_EATEN);
        player.getFoodStats().addStats(2, 0.1F);
        int i = ((Integer)state.getValue(BITES)).intValue();

        if (i < 6)
        {
            worldIn.setBlockState(pos, state.withProperty(BITES, Integer.valueOf(i + 1)), 3);
        }
        else
        {
            worldIn.setBlockToAir(pos);
        }

        return true;
    }
}
 
Example 6
Project: CustomWorldGen   File: BlockCake.java   View Source Code Vote up 6 votes
private void eatCake(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (player.canEat(false))
    {
        player.addStat(StatList.CAKE_SLICES_EATEN);
        player.getFoodStats().addStats(2, 0.1F);
        int i = ((Integer)state.getValue(BITES)).intValue();

        if (i < 6)
        {
            worldIn.setBlockState(pos, state.withProperty(BITES, Integer.valueOf(i + 1)), 3);
        }
        else
        {
            worldIn.setBlockToAir(pos);
        }
    }
}
 
Example 7
Project: DecompiledMinecraft   File: ItemFood.java   View Source Code Vote up 5 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.canEat(this.alwaysEdible))
    {
        playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
    }

    return itemStackIn;
}
 
Example 8
Project: DecompiledMinecraft   File: ItemFood.java   View Source Code Vote up 5 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.canEat(this.alwaysEdible))
    {
        playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
    }

    return itemStackIn;
}
 
Example 9
Project: BaseClient   File: ItemFood.java   View Source Code Vote up 5 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.canEat(this.alwaysEdible))
    {
        playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
    }

    return itemStackIn;
}
 
Example 10
Project: BaseClient   File: ItemFood.java   View Source Code Vote up 5 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.canEat(this.alwaysEdible))
    {
        playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
    }

    return itemStackIn;
}
 
Example 11
Project: Pangu   File: ItemPanguFood.java   View Source Code Vote up 5 votes
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, @Nonnull EnumHand handIn) {
    ItemStack itemstack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(getStats(itemstack).isAlwaysEdible())) {
        playerIn.setActiveHand(handIn);
        return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
    }
    else
        return new ActionResult<>(EnumActionResult.FAIL, itemstack);
}
 
Example 12
Project: customstuff4   File: ItemFood.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack stack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(content.alwaysEdible.get(stack.getMetadata()).orElse(false)))
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    } else
    {
        return new ActionResult<>(EnumActionResult.FAIL, stack);
    }
}
 
Example 13
Project: Backmemed   File: ItemFood.java   View Source Code Vote up 5 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);

    if (worldIn.canEat(this.alwaysEdible))
    {
        worldIn.setActiveHand(playerIn);
        return new ActionResult(EnumActionResult.SUCCESS, itemstack);
    }
    else
    {
        return new ActionResult(EnumActionResult.FAIL, itemstack);
    }
}
 
Example 14
Project: CustomWorldGen   File: ItemFood.java   View Source Code Vote up 5 votes
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    if (playerIn.canEat(this.alwaysEdible))
    {
        playerIn.setActiveHand(hand);
        return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
    }
    else
    {
        return new ActionResult(EnumActionResult.FAIL, itemStackIn);
    }
}