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

The following examples show how to use net.minecraft.block.Block#getHarvestTool() . 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: AutoToolModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
private boolean canHarvestBlock(Block block, BlockPos pos, ItemStack stack) {
    final Minecraft mc = Minecraft.getMinecraft();
    IBlockState state = mc.world.getBlockState(pos);
    state = state.getBlock().getActualState(state, mc.world, pos);

    if (state.getMaterial().isToolNotRequired()) {
        return true;
    }

    String tool = block.getHarvestTool(state);

    if (stack.isEmpty() || tool == null) {
        return mc.player.canHarvestBlock(state);
    }

    final int toolLevel = stack.getItem().getHarvestLevel(stack, tool, mc.player, state);

    if (toolLevel < 0) {
        return mc.player.canHarvestBlock(state);
    }

    return toolLevel >= block.getHarvestLevel(state);
}
 
Example 2
Source File: ToolWrench.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean canMineBlock(IBlockState blockState, ItemStack stack) {
    Block block = blockState.getBlock();
    String tool = block.getHarvestTool(blockState);
    return (tool != null && tool.equals("wrench"))
        || blockState.getMaterial() == Material.PISTON
        || block == Blocks.HOPPER
        || block == Blocks.DISPENSER
        || block == Blocks.DROPPER
        || blockState.getMaterial() == Material.IRON;
}
 
Example 3
Source File: ItemMetalCrackHammer.java    From BaseMetals with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean canHarvestBlock(final IBlockState targetBS) {
       Block target = targetBS.getBlock();
	// go to net.minecraftforge.common.ForgeHooks.initTools(); to see all tool type strings
	String toolType = target.getHarvestTool(target.getDefaultState());
	if(this.toolTypes.contains(toolType) || target.getMaterial(targetBS) == Material.ROCK){
		// can mine like a Pickaxe
		return this.getHarvestLevel(null, "pickaxe") >= target.getHarvestLevel(target.getDefaultState());
	} else if("shovel".equals(toolType) && target.getHarvestLevel(target.getDefaultState()) <= 0){
		// can be dug with wooden shovel
		return true;
	}
	// return true if block doesn't need tools
	return target.getHarvestLevel(target.getDefaultState()) == -1;
}
 
Example 4
Source File: ItemBaseChainsaw.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public float getDigSpeed(ItemStack stack, Block block, int meta) {
    if (block.getHarvestTool(meta) == null) {
        return efficiencyOnProperMaterial;
    } else {
        if ((canHarvestBlock(block, stack) && (block.getHarvestTool(meta).equals("axe")) || Items.shears.canHarvestBlock(block, stack))) {
            return efficiencyOnProperMaterial;
        }
    }
    return super.getDigSpeed(stack, block, meta);
}
 
Example 5
Source File: ItemBaseOmnitool.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public float getDigSpeed(ItemStack stack, Block block, int meta) {
    if (block.getHarvestTool(meta) == null) {
        return efficiencyOnProperMaterial;
    } else {
        if (canHarvestBlock(block, stack) && (block.getHarvestTool(meta).equals("pickaxe") || block.getHarvestTool(meta).equals("shovel")) || block.getHarvestTool(meta).equals("axe") || Items.shears.canHarvestBlock(block, stack)) {
            return efficiencyOnProperMaterial;
        }
    }
    return super.getDigSpeed(stack, block, meta);
}
 
Example 6
Source File: ItemBaseDrill.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public float getDigSpeed(ItemStack stack, Block block, int meta) {
    if (block.getHarvestTool(meta) == null) {
        return efficiencyOnProperMaterial;
    } else {
        if (canHarvestBlock(block, stack) && (block.getHarvestTool(meta).equals("pickaxe") || block.getHarvestTool(meta).equals("shovel"))) {
            return efficiencyOnProperMaterial;
        }
    }
    return super.getDigSpeed(stack, block, meta);
}