Java Code Examples for net.minecraft.block.Block#onBlockHarvested()

The following examples show how to use net.minecraft.block.Block#onBlockHarvested() . 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 check out the related API usage on the sidebar.
Example 1
Source File: BlockUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Breaks the block as a player, and thus drops the item(s) from it
 */
public static void breakBlockAsPlayer(World world, BlockPos pos, EntityPlayerMP playerMP, ItemStack toolStack)
{
    PlayerInteractionManager manager = playerMP.interactionManager;
    int exp = ForgeHooks.onBlockBreakEvent(world, manager.getGameType(), playerMP, pos);

    if (exp != -1)
    {
        IBlockState stateExisting = world.getBlockState(pos);
        Block blockExisting = stateExisting.getBlock();

        blockExisting.onBlockHarvested(world, pos, stateExisting, playerMP);
        boolean harvest = blockExisting.removedByPlayer(stateExisting, world, pos, playerMP, true);

        if (harvest)
        {
            blockExisting.onPlayerDestroy(world, pos, stateExisting);
            blockExisting.harvestBlock(world, playerMP, pos, stateExisting, world.getTileEntity(pos), toolStack);
        }
    }
}
 
Example 2
Source File: DiamondTofuToolHandler.java    From TofuCraftReload with MIT License 5 votes vote down vote up
private boolean canBreakExtraBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos, BlockPos refPos) {
    if (world.isAirBlock(pos)) {
        return false;
    }
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (tool.getDestroySpeed(stack, state) <= 1.0F)
        return false;

    IBlockState refState = world.getBlockState(refPos);
    float refStrength = ForgeHooks.blockStrength(refState, player, world, refPos);
    float strength = ForgeHooks.blockStrength(state, player, world, pos);

    if (!ForgeHooks.canHarvestBlock(block, player, world, pos) || refStrength / strength > 10f) {
        return false;
    }

    if (player.capabilities.isCreativeMode) {
        block.onBlockHarvested(world, pos, state, player);
        if (block.removedByPlayer(state, world, pos, player, false)) {
            block.onBlockDestroyedByPlayer(world, pos, state);
        }
        // send update to client
        if (!world.isRemote) {
            if (player instanceof EntityPlayerMP && ((EntityPlayerMP) player).connection != null) {
                ((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));
            }
        }
        return false;
    }
    return true;
}
 
Example 3
Source File: FakePlayerItemInWorldManager.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Removes a block and triggers the appropriate events
 */
private boolean removeBlock(int par1, int par2, int par3){
    Block block = theWorld.getBlock(par1, par2, par3);
    int l = theWorld.getBlockMetadata(par1, par2, par3);
    block.onBlockHarvested(theWorld, par1, par2, par3, l, thisPlayerMP);
    boolean flag = block != null && block.removedByPlayer(theWorld, thisPlayerMP, par1, par2, par3);

    if(flag) {
        block.onBlockDestroyedByPlayer(theWorld, par1, par2, par3, l);
    }

    return flag;
}