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

The following examples show how to use net.minecraft.block.Block#isAir() . 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: DroneAIDig.java    From PneumaticCraft with GNU General Public License v3.0 7 votes vote down vote up
public static boolean isBlockValidForFilter(IBlockAccess worldCache, IDroneBase drone, ChunkPosition pos, ProgWidgetAreaItemBase widget){
    int x = pos.chunkPosX;
    int y = pos.chunkPosY;
    int z = pos.chunkPosZ;
    Block block = worldCache.getBlock(x, y, z);

    if(!block.isAir(worldCache, x, y, z)) {
        int meta = worldCache.getBlockMetadata(x, y, z);
        List<ItemStack> droppedStacks;
        if(block.canSilkHarvest(drone.getWorld(), drone.getFakePlayer(), x, y, z, meta)) {
            droppedStacks = Arrays.asList(new ItemStack[]{getSilkTouchBlock(block, meta)});
        } else {
            droppedStacks = block.getDrops(drone.getWorld(), x, y, z, meta, 0);
        }
        for(ItemStack droppedStack : droppedStacks) {
            if(widget.isItemValidForFilters(droppedStack, meta)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: TileEntitySaltFurnace.java    From TofuCraftReload with MIT License 6 votes vote down vote up
/**
 * gets the water Level of the cauldron above this block
 *
 * @return water level. 0-3, int.
 * If there is no cauldron, returns negative value. -1, -2: must put fire one/two blck above, -3: inflammable
 */
@SuppressWarnings("deprecation")
public int getCauldronStatus() {
    IBlockState stateUp = this.world.getBlockState(this.pos.up());
    if (stateUp.getBlock() == Blocks.CAULDRON)
        return stateUp.getValue(BlockCauldron.LEVEL);
    else {
        Block block = stateUp.getBlock();
        if (block.isAir(stateUp, world, this.getPos().up()) || block == Blocks.FIRE) return -1;
        else if (!block.getMaterial(stateUp).getCanBurn()) return -3;
        else {
            IBlockState state2Up = this.world.getBlockState(this.pos.up(2));
            if (state2Up.getBlock().isAir(state2Up, world, this.pos.up(2))) return -2;
            else return -3;
        }
    }
}
 
Example 3
Source File: TileEssentiaCompressor.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void playVortexEffects() {
    for (int a = 0; a < Thaumcraft.proxy.particleCount(1); a++) {
        int tx = this.xCoord + this.worldObj.rand.nextInt(4) - this.worldObj.rand.nextInt(4);
        int ty = this.yCoord + 1 + this.worldObj.rand.nextInt(4) - this.worldObj.rand.nextInt(4);
        int tz = this.zCoord + this.worldObj.rand.nextInt(4) - this.worldObj.rand.nextInt(4);
        if (ty > this.worldObj.getHeightValue(tx, tz)) {
            ty = this.worldObj.getHeightValue(tx, tz);
        }
        Vec3 v1 = Vec3.createVectorHelper(this.xCoord + 0.5D, this.yCoord + 1.5D, this.zCoord + 0.5D);
        Vec3 v2 = Vec3.createVectorHelper(tx + 0.5D, ty + 0.5D, tz + 0.5D);

        MovingObjectPosition mop = ThaumcraftApiHelper.rayTraceIgnoringSource(this.worldObj, v1, v2, true, false, false);
        if ((mop != null) && (getDistanceFrom(mop.blockX, mop.blockY, mop.blockZ) < 16.0D)) {
            tx = mop.blockX;
            ty = mop.blockY;
            tz = mop.blockZ;
            Block bi = this.worldObj.getBlock(tx, ty, tz);
            int md = this.worldObj.getBlockMetadata(tx, ty, tz);
            if (!bi.isAir(this.worldObj, tx, ty, tz)) {
                Thaumcraft.proxy.hungryNodeFX(this.worldObj, tx, ty, tz, this.xCoord, this.yCoord + 1, this.zCoord, bi, md);
            }
        }
    }
}
 
Example 4
Source File: MobileChunk.java    From archimedes-ships with MIT License 6 votes vote down vote up
public boolean setBlockAsFilledAir(int x, int y, int z)
{
	ExtendedBlockStorage storage = getBlockStorage(x, y, z);
	if (storage == null) return true;
	
	Block block = storage.getBlockByExtId(x & 15, y & 15, z & 15);
	int meta = storage.getExtBlockMetadata(x & 15, y & 15, z & 15);
	if (block == Blocks.air && meta == 1)
	{
		return true;
	}
	if (block == null || block.isAir(worldObj, x, y, z))
	{
		storage.func_150818_a(x & 15, y & 15, z & 15, Blocks.air);
		storage.setExtBlockMetadata(x & 15, y & 15, z & 15, 1);
		onSetBlockAsFilledAir(x, y, z);
		return true;
	}
	return false;
}
 
Example 5
Source File: ChorusFlower.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
public static boolean canPlantStay(World world, int x, int y, int z) {
	Block block = world.getBlock(x, y - 1, z);
	if (block != ModBlocks.chorus_plant && block != Blocks.end_stone) {
		if (block.isAir(world, x, y - 1, z)) {
			int adjecentCount = 0;
			for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
				Block adjecentBlock = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
				if (adjecentBlock == ModBlocks.chorus_plant)
					adjecentCount++;
				else if (!adjecentBlock.isAir(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ))
					return false;
			}
			return adjecentCount == 1;
		} else
			return false;
	} else
		return true;
}
 
Example 6
Source File: WirelessBolt.java    From WirelessRedstone with MIT License 6 votes vote down vote up
private float rayTraceResistance(Vector3 start, Vector3 end, float prevresistance) {
    MovingObjectPosition mop = world.rayTraceBlocks(start.toVec3D(), end.toVec3D());

    if (mop == null)
        return prevresistance;

    if (mop.typeOfHit == MovingObjectType.BLOCK) {
        Block block = world.getBlock(mop.blockX, mop.blockY, mop.blockZ);
        if (block.isAir(world, mop.blockX, mop.blockY, mop.blockZ))
            return prevresistance;
        
        /*if(Block.blocksList[blockID] instanceof ISpecialResistance) 
        {
            ISpecialResistance isr = (ISpecialResistance) Block.blocksList[blockID];
             return prevresistance + (isr.getSpecialExplosionResistance(world, mop.blockX, mop.blockY, mop.blockZ, 
                     start.x, start.y, start.z, wrapper) + 0.3F);
        } 
        else 
        {*/
        return prevresistance + block.getExplosionResistance(wrapper) + 0.3F;
        //}
    }
    return prevresistance;
}
 
Example 7
Source File: WorldGenCandelilla.java    From GardenCollection with MIT License 6 votes vote down vote up
@Override
public boolean generate (World world, Random rand, int x, int y, int z) {
    do {
        Block block = world.getBlock(x, y, z);
        if (!(block.isLeaves(world, x, y, z) || block.isAir(world, x, y, z)))
            break;
        y--;
    } while (y > 0);

    int range = 5;
    for (int l = 0; l < 32; ++l) {
        int x1 = x + rand.nextInt(range) - rand.nextInt(range);
        int y1 = y + rand.nextInt(4) - rand.nextInt(4);
        int z1 = z + rand.nextInt(range) - rand.nextInt(range);
        int level = 1 + rand.nextInt(7);

        if (world.isAirBlock(x1, y1, z1) && (!world.provider.hasNoSky || y1 < 255) && plantBlock.canBlockStay(world, x1, y1, z1))
            world.setBlock(x1, y1, z1, plantBlock, level, 2);
    }

    return true;
}
 
Example 8
Source File: AIBreakBlock.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean isValid(Marker marker) {
    if(marker == null) return false;

    if(blacklist.containsKey(marker)) {
        if(blacklist.get(marker) + BLACKLIST_TICKS >= golem.ticksExisted) {
            return false;
        } else {
            blacklist.remove(marker);
        }
    }

    float range = golem.getRange();
    if(golem.getHomePosition().getDistanceSquared(marker.x, marker.y, marker.z) > range * range) {
        return false;
    }

    Block block = golem.worldObj.getBlock(marker.x, marker.y, marker.z);

    if(!block.isAir(golem.worldObj, marker.x, marker.y, marker.z)) {
        ItemStack blockStack = new ItemStack(Item.getItemFromBlock(block));
        boolean empty = true;
        for(int slot = 0; slot < golem.inventory.slotCount; slot++) {
            ItemStack stack = golem.inventory.inventory[slot];

            if(stack != null && Block.getBlockFromItem(stack.getItem()) != Blocks.air) {
                empty = false;
                if((marker.color == -1 || marker.color == golem.colors[slot])
                        && InventoryUtils.areItemStacksEqual(blockStack, stack,
                        golem.checkOreDict(), golem.ignoreDamage(), golem.ignoreNBT())) {
                    return true;
                }
            }
        }

        if(empty) {
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: MobileChunk.java    From archimedes-ships with MIT License 5 votes vote down vote up
public boolean isBlockTakingWaterVolume(int x, int y, int z)
{
	Block block = getBlock(x, y, z);
	if (block == null || block.isAir(worldObj, x, y, z))
	{
		if (getBlockMetadata(x, y, z) == 1) return false;
	}
	return true;
}
 
Example 10
Source File: TileEntitySprinkler.java    From AgriCraft with MIT License 5 votes vote down vote up
/**
 * This method will search through a vertical column of positions, starting from the top. It
 * will stop searching any lower once it hits anything other than air or plants. Any plant found
 * has an independant chance for a growth tick. That percentage is controlled by
 * AgriCraftConfig. Farmland also ends the search, but it first has its moisture set to max (7)
 * if it isn't already. The lowest position is special: a plant this far away is not helped.
 * Only farmland is currently.
 */
private void irrigateColumn(final int targetX, final int targetZ, final int highestY, final int lowestY) {
    for (int targetY = highestY; targetY >= lowestY; targetY -= 1) {
        BlockPos target = new BlockPos(targetX, targetY, targetZ);
        IBlockState state = this.getWorld().getBlockState(target);
        Block block = state.getBlock();

        // Option A: Skip empty/air blocks.
        // TODO: Is there a way to use isSideSolid to ignore minor obstructions? (Farmland isn't solid.)
        if (block.isAir(state, this.getWorld(), target)) {
            continue;
        }

        // Option B: Give plants a chance to grow, and then continue onward to irrigate the farmland too.
        if ((block instanceof IPlantable || block instanceof IGrowable) && targetY != lowestY) {
            if (this.getRandom().nextInt(100) < AgriCraftConfig.sprinklerGrowthChance) {
                block.updateTick(this.getWorld(), target, state, this.getRandom());
            }
            continue;
        }

        // Option C: Dry farmland gets set as moist.
        if (block instanceof BlockFarmland) {
            if (state.getValue(BlockFarmland.MOISTURE) < 7) {
                this.getWorld().setBlockState(target, state.withProperty(BlockFarmland.MOISTURE, 7), 2);
            }
            break; // Explicitly expresses the intent to stop.
        }

        // Option D: If it's none of the above, it blocks the sprinkler's irrigation. Stop.
        break;
    }
}
 
Example 11
Source File: ChunkAssembler.java    From archimedes-ships with MIT License 4 votes vote down vote up
public boolean canUseBlockForVehicle(Block block, int x, int y, int z)
{
	return !block.isAir(worldObj, x, y, z) && !block.getMaterial().isLiquid() && block != ArchimedesShipMod.blockBuffer && ArchimedesShipMod.instance.modConfig.isBlockAllowed(block);
}
 
Example 12
Source File: AnyComponent.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
@Override
public boolean matches(World world, int x, int y, int z) {
	Block block = world.getBlock(x, y, z);
	return !block.isAir(world, x, y, z) && block.getCollisionBoundingBoxFromPool(world, x, y, z) != null;
}
 
Example 13
Source File: WorldGenOrnamentalTree.java    From GardenCollection with MIT License 4 votes vote down vote up
private void generateBlock (World world, int x, int y, int z) {
    Block block = world.getBlock(x, y, z);
    if (block.isAir(world, x, y, z) || block.isLeaves(world, x, y, z))
        setBlockAndNotifyAdequately(world, x, y, z, leaves, metaLeaves);
}
 
Example 14
Source File: MobileChunk.java    From archimedes-ships with MIT License 4 votes vote down vote up
@Override
public boolean isAirBlock(int x, int y, int z)
{
	Block block = getBlock(x, y, z);
	return block == null || block.isAir(worldObj, x, y, z);
}
 
Example 15
Source File: PortalFormer.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean checkForValidPortalPosition(BlockPos posIn, EnumFacing ignoreSide)
{
    BlockPos pos = posIn;
    IBlockState state;
    Block block;
    EnumFacing continueTo = null;
    int adjacent = 0;

    if (this.visited.contains(posIn))
    {
        return true;
    }

    EnumFacing[] sides = PositionUtils.getSidesForAxis(this.portalAxis);

    for (EnumFacing side : sides)
    {
        if (side != ignoreSide)
        {
            pos = posIn.offset(side);

            if (pos.equals(this.lastPos))
            {
                continue;
            }

            state = this.world.getBlockState(pos);
            block = state.getBlock();

            if (block.isAir(state, this.world, pos))
            {
                if (this.visited.contains(pos) == false)
                {
                    if (adjacent == 0)
                    {
                        continueTo = side;
                    }
                    else
                    {
                        this.branches.add(pos);
                    }
                    adjacent++;
                }
            }
            else if (block != this.blockFrame)
            {
                return false;
            }
        }
    }

    this.visited.add(posIn);
    this.lastPos = posIn;

    this.nextSide = continueTo;

    return true;
}
 
Example 16
Source File: PortalFormer.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private EnumFacing checkFramePositionIgnoringSide(BlockPos posIn, EnumFacing ignoreSide)
{
    BlockPos pos = posIn;
    IBlockState state;
    Block block;
    EnumFacing continueTo = null;
    int frames = 0;

    if (this.visited.contains(posIn))
    {
        return null;
    }

    for (EnumFacing side : EnumFacing.values())
    {
        if (side != ignoreSide)
        {
            pos = posIn.offset(side);

            if (pos.equals(this.lastPos))
            {
                continue;
            }

            state = this.world.getBlockState(pos);
            block = state.getBlock();

            if (block.isAir(state, this.world, pos) || block == this.blockPortal)
            {
                this.checkForCorner(pos, false);

                // This is to fix single block portals not getting found via the checkForCorner() method.
                // The actual portal block count will be skewed, but it isn't used for anything other than a "> 0" check anyway.
                if (block == this.blockPortal)
                {
                    this.portalsFound++;
                }
            }
            else if (block == this.blockFrame)
            {
                if (this.visited.contains(pos) == false)
                {
                    if (frames == 0)
                    {
                        continueTo = side;
                    }
                    else
                    {
                        this.branches.add(pos);
                    }
                }
                frames++;
            }
        }
    }

    this.visited.add(posIn);
    this.lastPos = posIn;

    return continueTo;
}
 
Example 17
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private BlockPos checkReplacePositionIgnoringSide(World world, BlockPos posIn, EnumFacing side, BlockPos posMin, BlockPos posMax,
        Set<BlockPos> visited, List<BlockPos> branches, List<BlockPosStateDist> positions, boolean diagonals, BlockInfo biTarget, BlockInfo biBound)
{
    BlockPos pos = posIn;
    BlockPos continueTo = null;
    int sides = 0;

    if (visited.contains(pos) || PositionUtils.isPositionInsideArea(pos, posMin, posMax) == false)
    {
        return null;
    }

    IBlockState state = world.getBlockState(pos);

    // The block must be identical to the original targeted block
    if (state == biTarget.blockState)
    {
        BlockPos posAdj = pos.offset(side);
        IBlockState stateAdj = world.getBlockState(posAdj);
        Block blockAdj = stateAdj.getBlock();

        // The block must have a non-full block on the front face to be valid for replacing
        if (blockAdj.isAir(stateAdj, world, posAdj) || stateAdj.isSideSolid(world, posAdj, side.getOpposite()) == false)
        {
            positions.add(new BlockPosStateDist(posIn, world.provider.getDimension(), side, biBound));
        }
        else
        {
            return null;
        }
    }
    else
    {
        return null;
    }

    visited.add(pos);

    for (BlockPos posTmp : PositionUtils.getAdjacentPositions(pos, side, diagonals))
    {
        if (visited.contains(posTmp) || PositionUtils.isPositionInsideArea(posTmp, posMin, posMax) == false)
        {
            continue;
        }

        if (world.getBlockState(posTmp) == biTarget.blockState)
        {
            if (visited.contains(posTmp) == false)
            {
                if (sides == 0)
                {
                    continueTo = posTmp;
                }
                else if (branches.contains(posTmp) == false)
                {
                    branches.add(posTmp);
                }
            }

            sides++;
        }
    }

    return continueTo;
}
 
Example 18
Source File: ChorusFlower.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
public void updateTick(World world, int x, int y, int z, Random rand) {
	if (world.isRemote)
		return;
	int meta = world.getBlockMetadata(x, y, z);
	if (meta >= 5)
		return;

	if (!canBlockStay(world, x, y, z))
		world.func_147480_a(x, y, z, true);
	else if (world.isAirBlock(x, y + 1, z)) {
		boolean canGrowUp = false;
		boolean isSegmentOnEndstone = false;
		Block lowerBlock = world.getBlock(x, y - 1, z);
		if (lowerBlock == Blocks.end_stone)
			canGrowUp = true;
		else if (lowerBlock == ModBlocks.chorus_plant) {
			int par8 = 1;
			int height;
			for (height = 0; height < 4; height++) {
				Block b = world.getBlock(x, y - (par8 + 1), z);
				if (b != ModBlocks.chorus_plant) {
					if (b == Blocks.end_stone)
						isSegmentOnEndstone = true;
					break;
				}
				par8++;
			}

			height = 4;
			if (isSegmentOnEndstone)
				height++;

			if (par8 < 2 || rand.nextInt(height) >= par8)
				canGrowUp = true;
		} else if (lowerBlock.isAir(world, x, y - 1, z))
			canGrowUp = true;

		if (canGrowUp && isSpaceAroundFree(world, x, y + 1, z, ForgeDirection.DOWN) && world.isAirBlock(x, y + 2, z)) {
			world.setBlock(x, y, z, ModBlocks.chorus_plant);
			world.setBlock(x, y + 1, z, this, meta, 3);
		} else if (meta < 4) {
			int tries = rand.nextInt(4);
			boolean grew = false;
			if (isSegmentOnEndstone)
				tries++;
			for (int i = 0; i < tries; i++) {
				ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[rand.nextInt(ForgeDirection.VALID_DIRECTIONS.length)];
				int xx = x + dir.offsetX;
				int yy = y + dir.offsetY;
				int zz = z + dir.offsetZ;
				if (world.isAirBlock(xx, yy, zz) && isSpaceAroundFree(world, xx, yy, zz, dir.getOpposite())) {
					world.setBlock(xx, yy, zz, this, meta + 1, 3);
					grew = true;
				}
			}
			if (grew)
				world.setBlock(x, y, z, ModBlocks.chorus_plant, 0, 3);
			else
				world.setBlock(x, y, z, this, 5, 3);
		} else if (meta == 4)
			world.setBlock(x, y, z, this, 5, 3);
	}
}
 
Example 19
Source File: ItemExtendedNodeJar.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) {
    Block var11 = world.getBlock(x, y, z);
    if (var11 == Blocks.snow_layer) {
        side = 1;
    } else if ((var11 != Blocks.vine) && (var11 != Blocks.tallgrass) && (var11 != Blocks.deadbush) && ((var11.isAir(world, x, y, z)) || (!var11.isReplaceable(world, x, y, z)))) {
        if (side == 0) {
            y--;
        }
        if (side == 1) {
            y++;
        }
        if (side == 2) {
            z--;
        }
        if (side == 3) {
            z++;
        }
        if (side == 4) {
            x--;
        }
        if (side == 5) {
            x++;
        }
    }
    if (stack.stackSize == 0) {
        return false;
    }
    if (!player.canPlayerEdit(x, y, z, side, stack)) {
        return false;
    }
    if ((y == 255) && (RegisteredBlocks.blockExtendedNodeJar.getMaterial().isSolid())) {
        return false;
    }
    if (world.canPlaceEntityOnSide(RegisteredBlocks.blockExtendedNodeJar, x, y, z, false, side, player, stack)) {
        Block var12 = RegisteredBlocks.blockExtendedNodeJar;
        int var13 = 2;
        int var14 = RegisteredBlocks.blockExtendedNodeJar.onBlockPlaced(world, x, y, z, side, par8, par9, par10, var13);
        if (placeBlockAt(stack, player, world, x, y, z, side, par8, par9, par10, var14)) {
            TileEntity te = world.getTileEntity(x, y, z);

            if ((te != null) && ((te instanceof TileExtendedNodeJar))) {
                if (stack.hasTagCompound()) {
                    AspectList aspects = getAspects(stack);
                    if (aspects != null) {
                        ((TileExtendedNodeJar) te).setAspects(aspects);
                        ((TileExtendedNodeJar) te).setNodeType(getNodeType(stack));
                        ((TileExtendedNodeJar) te).setNodeModifier(getNodeModifier(stack));
                        ((TileExtendedNodeJar) te).setExtendedNodeType(getExtendedNodeType(stack));
                        ((TileExtendedNodeJar) te).setId(getNodeId(stack));
                        ((TileExtendedNodeJar) te).setBehaviorSnapshot(getBehaviorSnapshot(stack));
                    }
                }
            }


            world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, var12.stepSound.getStepResourcePath(), (var12.stepSound.getVolume() + 1.0F) / 2.0F, var12.stepSound.getPitch() * 0.8F);
            stack.stackSize -= 1;
        }
        return true;
    }
    return false;
}
 
Example 20
Source File: OilGeneratorFix.java    From NewHorizonsCoreMod with GNU General Public License v3.0 4 votes vote down vote up
private int getTopBlock( World pWorld, int pLocX, int pLocZ )
{
  Chunk tChunk = pWorld.getChunkFromBlockCoords( pLocX, pLocZ );
  int y = tChunk.getTopFilledSegment() + 15;

  int trimmedX = pLocX & 0xF;
  int trimmedZ = pLocZ & 0xF;
  for( ; y > 0; y-- )
  {
    Block tBlock = tChunk.getBlock( trimmedX, y, trimmedZ );

    if( !tBlock.isAir( pWorld, pLocX, y, pLocZ ) )
    {

      if(tBlock instanceof BlockStaticLiquid)
      {
        return y;
      }

      if(tBlock instanceof BlockFluidBase)
      {
        return y;
      }

      if(tBlock instanceof IFluidBlock)
      {
        return y;
      }

      if( tBlock.getMaterial().blocksMovement() )
      {

        if( !( tBlock instanceof BlockFlower ) )
        {

          return y - 1;
        }
      }
    }
  }
  return -1;
}