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

The following examples show how to use net.minecraft.block.Block#getHarvestLevel() . 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: 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 3
Source File: ComponentExcavation.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public boolean canHarvestBlock(Block block, ItemStack itemStack) {
	ToolMaterial toolMaterial = ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")];
	
	try {
		if(block.getBlockHardness(null, 0, 0, 0) == -1) {
			return false;
		}
	}
	catch(NullPointerException e) {
		return false;
	}
	
	if(block.getMaterial().isToolNotRequired()) {
		return true;
	}
	
	if(toolMaterial == ToolMaterial.WOOD) {
		return Items.wooden_pickaxe.func_150897_b/*canHarvestBlock*/(block) || Items.wooden_shovel.func_150897_b(block);
	}
	else if(toolMaterial == ToolMaterial.STONE) {
		return Items.stone_pickaxe.func_150897_b(block) || Items.stone_shovel.func_150897_b(block);
	}
	else if(toolMaterial == ToolMaterial.EMERALD) {
		return Items.diamond_pickaxe.func_150897_b(block) || Items.diamond_shovel.func_150897_b(block);
	}
	else if(toolMaterial == ToolMaterial.IRON) {
		return Items.iron_pickaxe.func_150897_b(block) || Items.iron_shovel.func_150897_b(block);
	}
	else if(toolMaterial == ToolMaterial.GOLD) {
		return Items.golden_pickaxe.func_150897_b(block) || Items.golden_shovel.func_150897_b(block);
	}

	return toolMaterial.getHarvestLevel() >= block.getHarvestLevel(0);
}
 
Example 4
Source File: ItemVanillaDrill.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canHarvestBlock(Block block, ItemStack stack) {
    return (block.getHarvestLevel(new ItemStack(Item.getItemFromBlock(block)).getItemDamage()) <= this.toolMaterial.getHarvestLevel());
}
 
Example 5
Source File: ItemVanillaOmnitool.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canHarvestBlock(Block block, ItemStack stack) {
    return (block.getHarvestLevel(new ItemStack(Item.getItemFromBlock(block)).getItemDamage()) <= this.toolMaterial.getHarvestLevel());
}
 
Example 6
Source File: ItemVanillaChainsaw.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canHarvestBlock(Block block, ItemStack stack) {
    return (block.getHarvestLevel(new ItemStack(Item.getItemFromBlock(block)).getItemDamage()) <= this.toolMaterial.getHarvestLevel());
}