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

The following are Jave code examples for showing how to use canHarvestBlock() 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: CustomWorldGen   File: ForgeHooks.java   View Source Code Vote up 6 votes
public static boolean canHarvestBlock(Block block, EntityPlayer player, IBlockAccess world, BlockPos pos)
{
    IBlockState state = world.getBlockState(pos);
    state = state.getBlock().getActualState(state, world, pos);
    if (state.getMaterial().isToolNotRequired())
    {
        return true;
    }

    ItemStack stack = player.inventory.getCurrentItem();
    String tool = block.getHarvestTool(state);
    if (stack == null || tool == null)
    {
        return player.canHarvestBlock(state);
    }

    int toolLevel = stack.getItem().getHarvestLevel(stack, tool, player, state);
    if (toolLevel < 0)
    {
        return player.canHarvestBlock(state);
    }

    return toolLevel >= block.getHarvestLevel(state);
}
 
Example 2
Project: BaseClient   File: Block.java   View Source Code Vote up 5 votes
/**
 * Get the hardness of this Block relative to the ability of the given
 * player
 */
public float getPlayerRelativeBlockHardness(EntityPlayer playerIn, World worldIn, BlockPos pos) {
	float f = this.getBlockHardness(worldIn, pos);
	return f < 0.0F ? 0.0F
			: (!playerIn.canHarvestBlock(this) ? playerIn.getToolDigEfficiency(this) / f / 100.0F
					: playerIn.getToolDigEfficiency(this) / f / 30.0F);
}
 
Example 3
Project: Backmemed   File: Block.java   View Source Code Vote up 5 votes
@Deprecated

    /**
     * Get the hardness of this Block relative to the ability of the given player
     */
    public float getPlayerRelativeBlockHardness(IBlockState state, EntityPlayer player, World worldIn, BlockPos pos)
    {
        float f = state.getBlockHardness(worldIn, pos);
        return f < 0.0F ? 0.0F : (!player.canHarvestBlock(state) ? player.getDigSpeed(state) / f / 100.0F : player.getDigSpeed(state) / f / 30.0F);
    }
 
Example 4
Project: DecompiledMinecraft   File: Block.java   View Source Code Vote up 4 votes
/**
 * Get the hardness of this Block relative to the ability of the given player
 */
public float getPlayerRelativeBlockHardness(EntityPlayer playerIn, World worldIn, BlockPos pos)
{
    float f = this.getBlockHardness(worldIn, pos);
    return f < 0.0F ? 0.0F : (!playerIn.canHarvestBlock(this) ? playerIn.getToolDigEfficiency(this) / f / 100.0F : playerIn.getToolDigEfficiency(this) / f / 30.0F);
}
 
Example 5
Project: DecompiledMinecraft   File: Block.java   View Source Code Vote up 4 votes
/**
 * Get the hardness of this Block relative to the ability of the given player
 */
public float getPlayerRelativeBlockHardness(EntityPlayer playerIn, World worldIn, BlockPos pos)
{
    float f = this.getBlockHardness(worldIn, pos);
    return f < 0.0F ? 0.0F : (!playerIn.canHarvestBlock(this) ? playerIn.getToolDigEfficiency(this) / f / 100.0F : playerIn.getToolDigEfficiency(this) / f / 30.0F);
}
 
Example 6
Project: BaseClient   File: Block.java   View Source Code Vote up 4 votes
/**
 * Get the hardness of this Block relative to the ability of the given player
 */
public float getPlayerRelativeBlockHardness(EntityPlayer playerIn, World worldIn, BlockPos pos)
{
    float f = this.getBlockHardness(worldIn, pos);
    return f < 0.0F ? 0.0F : (!playerIn.canHarvestBlock(this) ? playerIn.getToolDigEfficiency(this) / f / 100.0F : playerIn.getToolDigEfficiency(this) / f / 30.0F);
}