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

The following examples show how to use net.minecraft.block.Block#getBlockHardness() . 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: ItemMorphShovel.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase player) {
    if(EnchantmentHelper.getEnchantmentLevel(DarkEnchantments.impact.effectId, stack) <= 0)
        return super.onBlockDestroyed(stack, world, block, x, y, z, player);
    if(!player.worldObj.isRemote) {
        int meta = world.getBlockMetadata(x, y, z);
        if(ForgeHooks.isToolEffective(stack, block, meta)) {
            for(int aa = -1; aa <= 1; ++aa) {
                for(int bb = -1; bb <= 1; ++bb) {
                    int xx = 0;
                    int yy = 0;
                    int zz = 0;
                    if(this.side <= 1) {
                        xx = aa;
                        zz = bb;
                    } else if(this.side <= 3) {
                        xx = aa;
                        yy = bb;
                    } else {
                        zz = aa;
                        yy = bb;
                    }

                    if(!(player instanceof EntityPlayer) || world.canMineBlock((EntityPlayer)player, x + xx, y + yy, z + zz)) {
                        Block bl = world.getBlock(x + xx, y + yy, z + zz);
                        meta = world.getBlockMetadata(x + xx, y + yy, z + zz);
                        if(bl.getBlockHardness(world, x + xx, y + yy, z + zz) >= 0.0F && ForgeHooks.isToolEffective(stack, bl, meta)) {
                            stack.damageItem(1, player);
                            BlockUtils.harvestBlock(world, (EntityPlayer)player, x + xx, y + yy, z + zz, true, 2);
                        }
                    }
                }
            }
        }
        else
            return super.onBlockDestroyed(stack, world, block, x, y, z, player);
    }

    return super.onBlockDestroyed(stack, world, block, x, y, z, player);
}
 
Example 2
Source File: ItemMorphPickaxe.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase player) {
    if(EnchantmentHelper.getEnchantmentLevel(DarkEnchantments.impact.effectId, stack) <= 0)
        return super.onBlockDestroyed(stack, world, block, x, y, z, player);
    if(!player.worldObj.isRemote) {
        int meta = world.getBlockMetadata(x, y, z);
        if(ForgeHooks.isToolEffective(stack, block, meta)) {
            for(int aa = -1; aa <= 1; ++aa) {
                for(int bb = -1; bb <= 1; ++bb) {
                    int xx = 0;
                    int yy = 0;
                    int zz = 0;
                    if(this.side <= 1) {
                        xx = aa;
                        zz = bb;
                    } else if(this.side <= 3) {
                        xx = aa;
                        yy = bb;
                    } else {
                        zz = aa;
                        yy = bb;
                    }

                    if(!(player instanceof EntityPlayer) || world.canMineBlock((EntityPlayer)player, x + xx, y + yy, z + zz)) {
                        Block bl = world.getBlock(x + xx, y + yy, z + zz);
                        meta = world.getBlockMetadata(x + xx, y + yy, z + zz);
                        if(bl.getBlockHardness(world, x + xx, y + yy, z + zz) >= 0.0F && ForgeHooks.isToolEffective(stack, bl, meta)) {
                            stack.damageItem(1, player);
                            BlockUtils.harvestBlock(world, (EntityPlayer)player, x + xx, y + yy, z + zz, true, 2);
                        }
                    }
                }
            }
        }
        else
            return super.onBlockDestroyed(stack, world, block, x, y, z, player);
    }

    return super.onBlockDestroyed(stack, world, block, x, y, z, player);
}
 
Example 3
Source File: DroneAIDig.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock){
    if(!((FakePlayerItemInWorldManager)drone.getFakePlayer().theItemInWorldManager).isDigging() || !((FakePlayerItemInWorldManager)drone.getFakePlayer().theItemInWorldManager).isAcknowledged()) {
        int x = pos.chunkPosX;
        int y = pos.chunkPosY;
        int z = pos.chunkPosZ;

        Block block = worldCache.getBlock(x, y, z);
        if(!ignoreBlock(block) && isBlockValidForFilter(worldCache, drone, pos, widget)) {
            if(block.getBlockHardness(drone.getWorld(), x, y, z) < 0) {
                addToBlacklist(pos);
                drone.addDebugEntry("gui.progWidget.dig.debug.cantDigBlock", pos);
                drone.setDugBlock(0, 0, 0);
                return false;
            }
            FakePlayerItemInWorldManager manager = (FakePlayerItemInWorldManager)drone.getFakePlayer().theItemInWorldManager;
            manager.onBlockClicked(x, y, z, 0);
            if(!manager.isAccepted) {
                addToBlacklist(pos);
                drone.addDebugEntry("gui.progWidget.dig.debug.cantDigBlock", pos);
                drone.setDugBlock(0, 0, 0);
                return false;
            }
            drone.setDugBlock(x, y, z);
            return true;
        }
        drone.setDugBlock(0, 0, 0);
        return false;
    } else {
        return true;
    }
}
 
Example 4
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 5
Source File: SpeedMineModule.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
private boolean canBreak(BlockPos pos) {
    final IBlockState blockState = Minecraft.getMinecraft().world.getBlockState(pos);
    final Block block = blockState.getBlock();

    return block.getBlockHardness(blockState, Minecraft.getMinecraft().world, pos) != -1;
}
 
Example 6
Source File: NukerModule.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
private boolean canBreak(BlockPos pos) {
    final IBlockState blockState = Minecraft.getMinecraft().world.getBlockState(pos);
    final Block block = blockState.getBlock();

    return block.getBlockHardness(blockState, Minecraft.getMinecraft().world, pos) != -1;
}
 
Example 7
Source File: ScaffoldModule.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
private boolean canBreak(BlockPos pos) {
    final IBlockState blockState = Minecraft.getMinecraft().world.getBlockState(pos);
    final Block block = blockState.getBlock();

    return block.getBlockHardness(blockState, Minecraft.getMinecraft().world, pos) != -1 && !(block instanceof BlockLiquid);
}
 
Example 8
Source File: ItemBaseChainsaw.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entityLiving) {
    if ((double) block.getBlockHardness(world, x, y, z) != 0.0D) stack.damageItem(1, entityLiving);
    return true;
}
 
Example 9
Source File: ItemBaseOmnitool.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entityLiving) {
    if ((double) block.getBlockHardness(world, x, y, z) != 0.0D) stack.damageItem(1, entityLiving);
    return true;
}
 
Example 10
Source File: ItemBaseDrill.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entityLiving) {
    if ((double) block.getBlockHardness(world, x, y, z) != 0.0D) stack.damageItem(1, entityLiving);
    return true;
}