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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#canEat() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Ex-Aliquo   File: BlockEndCake.java    License: MIT License 6 votes vote down vote up
private void nomEndCake(World world, int x, int y, int z, EntityPlayer player)
{
    if (player.canEat(false))
    {
        int l = world.getBlockMetadata(x, y, z) + 1;

        if (l >= 6)
        {
        	return;
        }
        else
        {
        	player.getFoodStats().addStats(2, 0.1F);
            world.setBlockMetadataWithNotify(x, y, z, l, 2);
            if (world.provider.dimensionId == 0)
            {
            	if (!BlockEndPortal.bossDefeated) player.addPotionEffect(new PotionEffect(Potion.resistance.id, 200, 1));
            	player.travelToDimension(1);
            }
        }
    }
}
 
Example 2
Source Project: TofuCraftReload   File: DrinkSoymilkRamune.java    License: MIT License 5 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack itemstack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(true)||playerIn.isCreative())
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
    }
    else
    {
        return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
    }
}
 
Example 3
Source Project: TofuCraftReload   File: ItemGrowingTofu.java    License: MIT License 5 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack itemstack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(false))
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
    }
    else
    {
        return new ActionResult<>(EnumActionResult.FAIL, itemstack);
    }
}
 
Example 4
@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 5
Source Project: Production-Line   File: ItemPLFood.java    License: MIT License 5 votes vote down vote up
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    if (playerIn.canEat(this.alwaysEdible)) {
        playerIn.setActiveHand(hand);
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    } else {
        return new ActionResult<>(EnumActionResult.FAIL, stack);
    }
}
 
Example 6
Source Project: TFC2   File: ItemFoodTFC.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
	ItemStack itemStackIn = playerIn.getHeldItem(handIn);
	if (playerIn.canEat(false))
	{
		playerIn.setActiveHand(handIn);
		return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
	}

	return new ActionResult(EnumActionResult.FAIL, itemStackIn);
}
 
Example 7
private void eatCakeSlice(World world, int x, int y, int z, EntityPlayer player) {
    if (player.canEat(false)) {
        player.getFoodStats().addStats(2, 1.0F);
        int l = world.getBlockMetadata(x, y, z) + 1;

        if (l >= 12) {
            world.setBlockToAir(x, y, z);
        } else {
            world.setBlockMetadataWithNotify(x, y, z, l, 2);
        }

    }
}