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

The following examples show how to use net.minecraft.block.Block#getMaterial() . 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: TileEntityTreeFarm.java    From AdvancedMod with GNU General Public License v3.0 7 votes vote down vote up
private void cutTree(){
    if(inventory != null) {
        Block block = worldObj.getBlock(xCoord, yCoord + 2, zCoord);
        int offsetY = yCoord + 2;
        while(block.getMaterial() == Material.wood) {
            List<ItemStack> items = block.getDrops(worldObj, xCoord, offsetY, zCoord, worldObj.getBlockMetadata(xCoord, offsetY, zCoord), 0);
            for(ItemStack item : items) {
                ItemStack remainder = TileEntityHopper.func_145889_a(inventory, item, 0);
                if(remainder != null) {
                    worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord + 0.5, yCoord + 2.5, zCoord + 0.5, remainder));
                }
            }
            worldObj.setBlock(xCoord, offsetY, zCoord, Blocks.air);
            offsetY++;
            block = worldObj.getBlock(xCoord, offsetY, zCoord);
        }
    }
}
 
Example 2
Source File: Projectiles.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
private boolean isInMaterial(AxisAlignedBB axisalignedBB, Material material) {
    int chunkMinX = MathHelper.floor_double(axisalignedBB.minX);
    int chunkMaxX = MathHelper.floor_double((axisalignedBB.maxX + 1.0));
    int chunkMinY = MathHelper.floor_double(axisalignedBB.minY);
    int chunkMaxY = MathHelper.floor_double((axisalignedBB.maxY + 1.0));
    int chunkMinZ = MathHelper.floor_double(axisalignedBB.minZ);
    int chunkMaxZ = MathHelper.floor_double((axisalignedBB.maxZ + 1.0));
    if (!Wrapper.INSTANCE.world().checkChunksExist(chunkMinX, chunkMinY, chunkMinZ, chunkMaxX, chunkMaxY, chunkMaxZ)) {
        return false;
    }
    boolean isWithin = false;
    for (int x = chunkMinX; x < chunkMaxX; ++x) {
        for (int y = chunkMinY; y < chunkMaxY; ++y) {
            for (int z = chunkMinZ; z < chunkMaxZ; ++z) {
                Block block = Block.getBlockById(Wrapper.INSTANCE.world().getBlockMetadata(x, y, z));
                if (block == null || block.getMaterial() != material || chunkMaxY < ((y + 1) - BlockLiquid.getLiquidHeightPercent(Wrapper.INSTANCE.world().getBlockMetadata(x, y, z)))) {
                    continue;
                }
                isWithin = true;
            }
        }
    }
    return isWithin;
}
 
Example 3
Source File: WaterFall.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onTicks() {
    if (Wrapper.INSTANCE.player().fallDistance >= 5.0f) {
        this.switchToItem(I18n.format("item.bucketWater.name", (Object[]) new Object[0]));
        Block blocks = Wrapper.INSTANCE.world().getBlock((int) Wrapper.INSTANCE.player().posX, (int) Wrapper.INSTANCE.player().posY - 3, (int) Wrapper.INSTANCE.player().posZ);
        if (blocks.getMaterial() != Material.air && this.hasItem(I18n.format("item.bucketWater.name", (Object[]) new Object[0]))) {
            this.useItem();
            ++this.delay;
            if (this.delay >= 20) {
                this.switchToItem(I18n.format("item.bucket.name", (Object[]) new Object[0]));
                this.useItem();
                this.delay = 0;
            }
        }
    }
}
 
Example 4
Source File: BlockLightChain.java    From GardenCollection with MIT License 6 votes vote down vote up
public Vec3[] getAttachPoints (IBlockAccess world, int x, int y, int z) {
    int yMin = findMinY(world, x, y, z);
    Block bottomBlock = world.getBlock(x, yMin - 1, z);

    IAttachable attachable = GardenAPI.instance().registries().attachable().getAttachable(bottomBlock, world.getBlockMetadata(x, y - 1, z));

    Vec3[] attachPoints = singleAttachPoint;
    if (bottomBlock instanceof IChainAttachable)
        attachPoints = ((IChainAttachable) bottomBlock).getChainAttachPoints(1);
    else if (attachable != null && attachable.isAttachable(world, x, y - 1, z, 1))
        attachPoints = new Vec3[] { Vec3.createVectorHelper(.5, attachable.getAttachDepth(world, x, y - 1, z, 1), .5) };
    else if (bottomBlock instanceof IChainSingleAttachable) {
        Vec3 attachPoint = ((IChainSingleAttachable) bottomBlock).getChainAttachPoint(world, x, y, z, 1);
        if (attachPoint != null)
            attachPoints = new Vec3[] { attachPoint };
    }
    else if (bottomBlock.renderAsNormalBlock() && bottomBlock.getMaterial() != Material.air)
        attachPoints = defaultAttachPoints;

    return attachPoints;
}
 
Example 5
Source File: ComponentMining.java    From Artifacts with MIT License 6 votes vote down vote up
@Override
public boolean canHarvestBlock(Block block, ItemStack itemStack) {
	ToolMaterial toolMaterial = ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")];
	
	if(toolMaterial == toolMaterial.WOOD) {
		return Items.wooden_pickaxe.func_150897_b/*canHarvestBlock*/(block);
	}
	else if(toolMaterial == toolMaterial.STONE) {
		return Items.stone_pickaxe.func_150897_b(block);
	}
	else if(toolMaterial == ToolMaterial.EMERALD) {
		return Items.diamond_pickaxe.func_150897_b(block);
	}
	else if(toolMaterial == ToolMaterial.IRON) {
		return Items.iron_pickaxe.func_150897_b(block);
	}
	else if(toolMaterial == ToolMaterial.GOLD) {
		return Items.golden_pickaxe.func_150897_b(block);
	}
	return block == Blocks.obsidian ? toolMaterial.getHarvestLevel() == 3 : (block != Blocks.diamond_block && block != Blocks.diamond_ore ? (block != Blocks.emerald_ore && block != Blocks.emerald_block ? (block != Blocks.gold_block && block != Blocks.gold_ore ? (block != Blocks.iron_block && block != Blocks.iron_ore ? (block != Blocks.lapis_block && block != Blocks.lapis_ore ? (block != Blocks.redstone_ore && block != Blocks.lit_redstone_ore ? (block.getMaterial() == Material.rock ? true : (block.getMaterial() == Material.iron ? true : block.getMaterial() == Material.anvil)) : toolMaterial.getHarvestLevel() >= 2) : toolMaterial.getHarvestLevel() >= 1) : toolMaterial.getHarvestLevel() >= 1) : toolMaterial.getHarvestLevel() >= 2) : toolMaterial.getHarvestLevel() >= 2) : toolMaterial.getHarvestLevel() >= 2);
}
 
Example 6
Source File: ComponentDamage.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public boolean canHarvestBlock(Block par1Block, ItemStack itemStack) {
	if (par1Block == Blocks.web)
       {
           return true;
       }
       else
       {
           Material material = par1Block.getMaterial();
           return material != Material.plants && material != Material.vine && material != Material.coral && material != Material.leaves && material != Material.gourd ? false : true;
       }
}
 
Example 7
Source File: BlockGravity.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canFallInto(World worldIn, BlockPos pos)
{
	if (worldIn.isAirBlock(pos)) return true;
	Block block = worldIn.getBlockState(pos).getBlock();
	Material material = block.getMaterial(worldIn.getBlockState(pos));
	return (block == Blocks.FIRE) || (material == Material.AIR) || (material == Material.WATER) || (material == Material.LAVA) || block.isReplaceable(worldIn, pos);
}
 
Example 8
Source File: ItemTaintShovel.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
@Override
public float getDigSpeed(ItemStack stack, Block block, int meta)
{
    if (ForgeHooks.isToolEffective(stack, block, meta) ||
            (block.getMaterial() == Config.taintMaterial && block != ForbiddenBlocks.taintLog && block != ForbiddenBlocks.taintPlanks
            && block != ForbiddenBlocks.taintStone))
    {
        return efficiencyOnProperMaterial;
    }

    return func_150893_a(stack, block);
}
 
Example 9
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 10
Source File: ComponentDamage.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public float getDigSpeed(ItemStack itemStack, Block block, int meta) {
	if (block == Blocks.web)
       {
           return 15.0F;
       }
       else
       {
           Material material = block.getMaterial();
           return material != Material.plants && material != Material.vine && material != Material.coral && material != Material.leaves && material != Material.gourd ? 0.0F : 1.5F;
       }
}
 
Example 11
Source File: Entity.java    From TickDynamic with MIT License 5 votes vote down vote up
/**
 * Checks if the current block the entity is within of the specified material type
 */
public boolean isInsideOfMaterial(Material p_70055_1_)
{
    double d0 = this.posY + (double)this.getEyeHeight();
    int i = MathHelper.floor_double(this.posX);
    int j = MathHelper.floor_float((float)MathHelper.floor_double(d0));
    int k = MathHelper.floor_double(this.posZ);
    Block block = this.worldObj.getBlock(i, j, k);

    if (block.getMaterial() == p_70055_1_)
    {
        double filled = 1.0f; //If it's not a liquid assume it's a solid block
        if (block instanceof IFluidBlock)
        {
            filled = ((IFluidBlock)block).getFilledPercentage(worldObj, i, j, k);
        }

        if (filled < 0)
        {
            filled *= -1;
            //filled -= 0.11111111F; //Why this is needed.. not sure...
            return d0 > (double)(j + (1 - filled));
        }
        else
        {
            return d0 < (double)(j + filled);
        }
    }
    else
    {
        return false;
    }
}
 
Example 12
Source File: TileEntityQuantumComputer.java    From qcraft-mod with Apache License 2.0 5 votes vote down vote up
private boolean checkCooling()
{
    for( int i = 0; i < 6; ++i )
    {
        int x = xCoord + Facing.offsetsXForSide[ i ];
        int y = yCoord + Facing.offsetsYForSide[ i ];
        int z = zCoord + Facing.offsetsZForSide[ i ];
        Block block = worldObj.getBlock( x, y, z );
        if( block != null && (block.getMaterial() == Material.ice || block.getMaterial() == Material.packedIce) )
        {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: OilGeneratorFix.java    From NewHorizonsCoreMod with GNU General Public License v3.0 4 votes vote down vote up
private boolean checkBlock( World pWorld, int pLocX, int pLocY, int pLocZ ) {
  Block tBlock = pWorld.getBlock(pLocX, pLocY, pLocZ);
  return tBlock.getMaterial() == Material.air || tBlock instanceof BlockLiquid && tBlock != _mBuildCraftOilBlock;
}
 
Example 14
Source File: WeatherRenderer.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
public static void addRainParticles(Random random, int rendererUpdateCount)
{
	Minecraft mc = Minecraft.getMinecraft();
	WorldClient worldclient = mc.world;
	if(worldclient.provider.getDimension() != 0)
		return;
	float rainStrength = (float)WeatherManager.getInstance().getPrecipitation((int)mc.player.posX, (int)mc.player.posZ);
	double tempPlayer = WeatherManager.getInstance().getTemperature((int)mc.player.posX,(int)mc.player.posY, (int)mc.player.posZ);
	if(tempPlayer <= 0)
		return;

	if (!mc.gameSettings.fancyGraphics)
	{
		rainStrength /= 2.0F;
	}

	if (rainStrength > 0.0F)
	{
		worldclient.rand.setSeed((long)rendererUpdateCount * 312987231L);
		Entity entity = mc.getRenderViewEntity();
		BlockPos blockpos = new BlockPos(entity);
		byte b0 = 10;
		double d0 = 0.0D;
		double d1 = 0.0D;
		double d2 = 0.0D;
		int i = 0;
		int rainParticles = Math.max((int)(100.0F * rainStrength * rainStrength), 4);

		if (mc.gameSettings.particleSetting == 1)
		{
			rainParticles >>= 1;
		}
		else if (mc.gameSettings.particleSetting == 2)
		{
			rainParticles = 0;
		}

		for (int k = 0; k < rainParticles; ++k)
		{
			BlockPos blockPos1 = worldclient.getPrecipitationHeight(blockpos.add(worldclient.rand.nextInt(b0) - worldclient.rand.nextInt(b0), 0, worldclient.rand.nextInt(b0) - worldclient.rand.nextInt(b0)));
			double temp = WeatherManager.getInstance().getTemperature(blockPos1);
			BlockPos blockpos2 = blockPos1.down();
			IBlockState state = worldclient.getBlockState(blockpos2);
			Block block = worldclient.getBlockState(blockpos2).getBlock();

			if (blockPos1.getY() <= blockpos.getY() + b0 && blockPos1.getY() >= blockpos.getY() - b0 && temp > 0)
			{
				float f1 = worldclient.rand.nextFloat();
				float f2 = worldclient.rand.nextFloat();
				AxisAlignedBB axisalignedbb = state.getBoundingBox(worldclient, blockpos2);

				if (block.getMaterial(state) == Material.LAVA)
				{
					mc.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, (double)((float)blockPos1.getX() + f1), (double)((float)blockPos1.getY() + 0.1F) - axisalignedbb.minY, (double)((float)blockPos1.getZ() + f2), 0.0D, 0.0D, 0.0D, new int[0]);
				}
				else if (block.getMaterial(state) != Material.AIR)
				{
					//block.setBlockBoundsBasedOnState(worldclient, blockpos2);
					++i;

					if (worldclient.rand.nextInt(i) == 0)
					{
						d0 = (double)((float)blockpos2.getX() + f1);
						d1 = (double)((float)blockpos2.getY() + 0.1F) + axisalignedbb.maxY - 1.0D;
						d2 = (double)((float)blockpos2.getZ() + f2);
					}

					mc.world.spawnParticle(EnumParticleTypes.WATER_DROP, (double)((float)blockpos2.getX() + f1), (double)((float)blockpos2.getY() + 0.1F) + axisalignedbb.maxY, (double)((float)blockpos2.getZ() + f2), 0.0D, 0.0D, 0.0D, new int[0]);
				}
			}
		}

		if (i > 0 && worldclient.rand.nextInt(3) < rainSoundCounter++)
		{
			rainSoundCounter = 0;

			if (d1 > (double)(blockpos.getY() + 1) && worldclient.getPrecipitationHeight(blockpos).getY() > MathHelper.floor((float)blockpos.getY()))
			{
				mc.world.playSound(d0, d1, d2, SoundEvents.WEATHER_RAIN_ABOVE, SoundCategory.WEATHER, 0.1F*rainStrength, 0.5F, false);
			}
			else
			{
				mc.world.playSound(d0, d1, d2, SoundEvents.WEATHER_RAIN, SoundCategory.WEATHER, 0.2F*rainStrength, 1.0F, false);
			}
		}
	}
}
 
Example 15
Source File: ShipHandlerCommon.java    From archimedes-ships with MIT License 4 votes vote down vote up
public void onChunkUpdate()
{
	MobileChunk chunk = ship.getShipChunk();
	ship.getCapabilities().clearBlockCount();
	for (int i = chunk.minX(); i < chunk.maxX(); i++)
	{
		for (int j = chunk.minY(); j < chunk.maxY(); j++)
		{
			for (int k = chunk.minZ(); k < chunk.maxZ(); k++)
			{
				Block block = chunk.getBlock(i, j, k);
				if (block.getMaterial() != Material.air)
				{
					ship.getCapabilities().onChunkBlockAdded(block, chunk.getBlockMetadata(i, j, k), i, j, k);
				}
			}
		}
	}
	
	ship.setSize(Math.max(chunk.maxX() - chunk.minX(), chunk.maxZ() - chunk.minZ()), chunk.maxY() - chunk.minY());
	World.MAX_ENTITY_RADIUS = Math.max(World.MAX_ENTITY_RADIUS, Math.max(ship.width, ship.height) + 2F);
	
	try
	{
		ship.fillAirBlocks(new HashSet<ChunkPosition>(), -1, -1, -1);
	} catch (StackOverflowError e)
	{
		ArchimedesShipMod.modLog.error("Failure during ship post-initialization", e);
	}
	
	ship.layeredBlockVolumeCount = new int[chunk.maxY() - chunk.minY()];
	for (int y = 0; y < ship.layeredBlockVolumeCount.length; y++)
	{
		for (int i = chunk.minX(); i < chunk.maxX(); i++)
		{
			for (int j = chunk.minZ(); j < chunk.maxZ(); j++)
			{
				if (chunk.isBlockTakingWaterVolume(i, y + chunk.minY(), j))
				{
					ship.layeredBlockVolumeCount[y]++;
				}
			}
		}
	}
	ship.isFlying = ship.getCapabilities().canFly();
}
 
Example 16
Source File: BlockMapleSaplingGreen.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
protected boolean canSustainBush(IBlockState state) {

	Block block = state.getBlock();
	return block == Blocks.GRASS || block == Blocks.DIRT || block.getMaterial(state) == Material.GROUND;
}
 
Example 17
Source File: BlockBeaconPost.java    From Cyberware with MIT License 4 votes vote down vote up
public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos)
{
	IBlockState iblockstate = worldIn.getBlockState(pos);
	Block block = iblockstate.getBlock();
	return block == Blocks.BARRIER ? false : ((!(block instanceof BlockBeaconPost) || block.getMaterial(iblockstate) != this.blockMaterial) && !(block instanceof BlockFenceGate) ? (block.getMaterial(iblockstate).isOpaque() && iblockstate.isFullCube() ? block.getMaterial(iblockstate) != Material.GOURD : false) : true);
}
 
Example 18
Source File: BlockMapleSaplingOrange.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
protected boolean canSustainBush(IBlockState state) {

	Block block = state.getBlock();
	return block == Blocks.GRASS || block == Blocks.DIRT || block.getMaterial(state) == Material.GROUND;
}
 
Example 19
Source File: BlockLaserBeamSource.java    From Artifacts with MIT License 4 votes vote down vote up
public void updateLaserState(World world, int x, int y, int z, Block block, int meta, boolean triggered, int par8, int par9)
{
    int l1 = meta & 3;
    boolean flag1 = (meta & 8) == 8;
    //boolean flag2 = (meta & 8) == 8;
    //boolean isThis = id == this.blockID;
    //boolean flag4 = false;
    //boolean solidTop = !world.isBlockSolidOnSide(x, y - 1, z, UP);
    int offsetX = Direction.offsetX[l1];
    int offsetZ = Direction.offsetZ[l1];
    //int k2 = 0;
    //int[] aint = new int[42];
    int l2;
    int i3;
    Block j3;
    int k3;
    //int l3;
    boolean shouldbetriggered = false;
    boolean quitEarly = false;
    for (i3 = 1; i3 < 16; ++i3)
    {
    	l2 = x + offsetX * i3;
        k3 = z + offsetZ * i3;
        j3 = world.getBlock(l2, y, k3);
        if(j3 == Blocks.air || (j3 != BlockLaserBeam.instance && j3.getMaterial() == Material.air)) {
        	if(!quitEarly)
        		world.setBlock(l2, y, k3, BlockLaserBeam.instance, 0, 3);
        }
        if(j3 == BlockLaserBeam.instance) {
        	if(quitEarly) {
        		world.setBlockToAir(l2, y, k3);
        	}
        	else if(world.getBlockMetadata(l2, y, k3) != 0) {
        		shouldbetriggered = true;
        		//world.scheduleBlockUpdate(l2, y, k3, blockID, 10);
        		//world.setBlockMetadataWithNotify(l2, y, k3, 0, 3);
        	}
        }
        if (world.getBlock(l2, y, k3).isOpaqueCube()) {
        	quitEarly = true;
        }
    }
    
    if(triggered) {
    	if(shouldbetriggered) {
    		world.setBlockMetadataWithNotify(x, y, z, l1|8, 3);
    		world.scheduleBlockUpdate(x, y, z, this.instance, this.tickRate(world));
    		notifyNeighborOfChange(world, x, y, z, l1);
    	}
    }
}
 
Example 20
Source File: BlockSakuraSapling.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
protected boolean canSustainBush(IBlockState state) {

	Block block = state.getBlock();
	return block == Blocks.GRASS || block == Blocks.DIRT || block.getMaterial(state) == Material.GROUND;
}