Java Code Examples for net.minecraft.world.World.isAirBlock()

The following are Jave code examples for showing how to use isAirBlock() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Infernum   File: PigmanMageTowerGenerator.java   View Source Code Vote up 6 votes
private static int findPosY(World world, BlockPos pos) {
	BlockPos checkPos = new BlockPos(pos.getX(), 120, pos.getZ());

	int airBlocks = 0;
	for (int yOffset = 1; yOffset <= 88; yOffset++) {
		if (world.isAirBlock(checkPos.down(yOffset))) {
			airBlocks++;
		} else {
			if (airBlocks > 20) {
				return 120 - yOffset;
			}
			airBlocks = 0;
		}
	}
	return -1;
}
 
Example 2
Project: MeeCreeps   File: WorkerHelper.java   View Source Code Vote up 6 votes
@Override
public boolean harvestAndPickup(BlockPos pos) {
    World world = entity.getEntityWorld();
    if (world.isAirBlock(pos)) {
        return true;
    }
    IBlockState state = world.getBlockState(pos);
    if (!allowedToHarvest(state, world, pos, GeneralTools.getHarvester())) {
        return false;
    }
    Block block = state.getBlock();
    List<ItemStack> drops = block.getDrops(world, pos, state, 0);
    net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1.0f, false, GeneralTools.getHarvester());
    SoundTools.playSound(world, block.getSoundType().getBreakSound(), pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f);
    block.onBlockHarvested(world, pos, state, GeneralTools.getHarvester());
    entity.getEntityWorld().setBlockToAir(pos);
    giveDropsToMeeCreeps(drops);
    return true;
}
 
Example 3
Project: uniquecrops   File: DevilSnare.java   View Source Code Vote up 6 votes
private void trySpread(World world, BlockPos pos) {
	
	for (EnumFacing face : EnumFacing.HORIZONTALS) {
		BlockPos looppos = pos.offset(face);
		if (world.getLightFor(EnumSkyBlock.BLOCK, looppos) > 5) continue;
		if (world.isAirBlock(looppos) && (world.getBlockState(looppos.down()).getBlock() == Blocks.DIRT || world.getBlockState(looppos.down()).getBlock() == Blocks.FARMLAND)) {
			if (world.rand.nextInt(2) == 0) {
				if (world.getBlockState(looppos.down()).getBlock() == Blocks.DIRT)
					world.setBlockState(looppos.down(), Blocks.FARMLAND.getDefaultState(), 3);
				else
					world.setBlockState(looppos, UCBlocks.cropDevilsnare.getDefaultState(), 3);
				break;
			}
		}
	}
}
 
Example 4
Project: Backmemed   File: WorldGenCactus.java   View Source Code Vote up 6 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    for (int i = 0; i < 10; ++i)
    {
        BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));

        if (worldIn.isAirBlock(blockpos))
        {
            int j = 1 + rand.nextInt(rand.nextInt(3) + 1);

            for (int k = 0; k < j; ++k)
            {
                if (Blocks.CACTUS.canBlockStay(worldIn, blockpos))
                {
                    worldIn.setBlockState(blockpos.up(k), Blocks.CACTUS.getDefaultState(), 2);
                }
            }
        }
    }

    return true;
}
 
Example 5
Project: DecompiledMinecraft   File: WorldGenDeadBush.java   View Source Code Vote up 6 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    Block block;

    while (((block = worldIn.getBlockState(position).getBlock()).getMaterial() == Material.air || block.getMaterial() == Material.leaves) && position.getY() > 0)
    {
        position = position.down();
    }

    for (int i = 0; i < 4; ++i)
    {
        BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));

        if (worldIn.isAirBlock(blockpos) && Blocks.deadbush.canBlockStay(worldIn, blockpos, Blocks.deadbush.getDefaultState()))
        {
            worldIn.setBlockState(blockpos, Blocks.deadbush.getDefaultState(), 2);
        }
    }

    return true;
}
 
Example 6
Project: Bewitchment   File: GrowFlowersBrew.java   View Source Code Vote up 6 votes
@Override
public void safeImpact(BlockPos pos, @Nullable EnumFacing side, World world, int amplifier) {
	Random rand = world.rand;
	int box = 1 + (int) ((float) amplifier / 2F);

	BlockPos posI = pos.add(box, box, box);
	BlockPos posF = pos.add(-box, -box, -box);

	Iterable<BlockPos> spots = BlockPos.getAllInBox(posI, posF);
	for (BlockPos spot : spots) {
		IBlockState state = world.getBlockState(spot);
		boolean place = amplifier > 2 || world.rand.nextInt(3) == 0;
		if (place && state.getBlock() == Blocks.GRASS && world.isAirBlock(spot.up())) {
			world.getBiome(pos).plantFlower(world, rand, spot.up());
		}
	}
}
 
Example 7
Project: Backmemed   File: WorldGenDeadBush.java   View Source Code Vote up 6 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    for (IBlockState iblockstate = worldIn.getBlockState(position); (iblockstate.getMaterial() == Material.AIR || iblockstate.getMaterial() == Material.LEAVES) && position.getY() > 0; iblockstate = worldIn.getBlockState(position))
    {
        position = position.down();
    }

    for (int i = 0; i < 4; ++i)
    {
        BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));

        if (worldIn.isAirBlock(blockpos) && Blocks.DEADBUSH.canBlockStay(worldIn, blockpos, Blocks.DEADBUSH.getDefaultState()))
        {
            worldIn.setBlockState(blockpos, Blocks.DEADBUSH.getDefaultState(), 2);
        }
    }

    return true;
}
 
Example 8
Project: Backmemed   File: WorldGenPumpkin.java   View Source Code Vote up 5 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    for (int i = 0; i < 64; ++i)
    {
        BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));

        if (worldIn.isAirBlock(blockpos) && worldIn.getBlockState(blockpos.down()).getBlock() == Blocks.GRASS && Blocks.PUMPKIN.canPlaceBlockAt(worldIn, blockpos))
        {
            worldIn.setBlockState(blockpos, Blocks.PUMPKIN.getDefaultState().withProperty(BlockPumpkin.FACING, EnumFacing.Plane.HORIZONTAL.random(rand)), 2);
        }
    }

    return true;
}
 
Example 9
Project: DecompiledMinecraft   File: StructureComponent.java   View Source Code Vote up 5 votes
/**
 * Deletes all continuous blocks from selected position upwards. Stops at hitting air.
 */
protected void clearCurrentPositionBlocksUpwards(World worldIn, int x, int y, int z, StructureBoundingBox structurebb)
{
    BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));

    if (structurebb.isVecInside(blockpos))
    {
        while (!worldIn.isAirBlock(blockpos) && blockpos.getY() < 255)
        {
            worldIn.setBlockState(blockpos, Blocks.air.getDefaultState(), 2);
            blockpos = blockpos.up();
        }
    }
}
 
Example 10
Project: ExPetrum   File: BlockCattail.java   View Source Code Vote up 5 votes
public void doPlacementChecks(IBlockAccess world, BlockPos pos)
{
	if (world instanceof World)
	{
		World w = (World) world;
		if (!Helpers.canPlantGrow(pos.up(), w))
		{
			this.breakReplaceSelf(w, pos);
			return;
		}
		
		if (w.isAirBlock(pos.down()) || !w.getBlockState(pos.down()).isSideSolid(w, pos.down(), EnumFacing.UP))
		{
			this.breakReplaceSelf(w, pos);
			return;
		}
		
		if (w.getBlockState(pos.up()).getMaterial() != Material.WATER)
		{
			this.breakReplaceSelf(w, pos);
			return;
		}
		
		if (w.getBlockState(pos.up()).getBlock() instanceof IWater && ((IWater)w.getBlockState(pos.up()).getBlock()).isSalt(w, pos.up()))
		{
			this.breakReplaceSelf(w, pos);
           }
	}
}
 
Example 11
Project: MeeCreeps   File: DigdownActionWorker.java   View Source Code Vote up 5 votes
private BlockPos findTopSpotNotDiggedYet() {
    IMeeCreep entity = helper.getMeeCreep();
    BlockPos p = options.getTargetPos();
    World world = entity.getWorld();
    IBlockState state = world.getBlockState(p);
    while (p.getY() > 0 && (world.isAirBlock(p) || state.getBlock() == Blocks.LADDER)) {
        p = p.down();
        state = world.getBlockState(p);
    }
    return p;
}
 
Example 12
Project: MeeCreeps   File: TeleportationTools.java   View Source Code Vote up 5 votes
public static void makePortalPair(World sourceWorld, BlockPos selectedBlock, EnumFacing selectedSide, TeleportDestination dest) {
    BlockPos sourcePortalPos = findBestPosition(sourceWorld, selectedBlock, selectedSide);
    if (sourcePortalPos == null) {
        return;
    }

    World destWorld = mcjty.lib.varia.TeleportationTools.getWorldForDimension(dest.getDimension());
    if (destWorld.getBlockState(dest.getPos()).getBlock() == ModBlocks.portalBlock) {
        return;
    }
    if (dest.getSide() == EnumFacing.DOWN) {
        if (!destWorld.isAirBlock(dest.getPos()) || !destWorld.isAirBlock(dest.getPos().down())) {
            return;
        }
    } else {
        if (!destWorld.isAirBlock(dest.getPos()) || !destWorld.isAirBlock(dest.getPos().up())) {
            return;
        }
    }

    sourceWorld.setBlockState(sourcePortalPos, ModBlocks.portalBlock.getDefaultState(), 3);
    PortalTileEntity source = (PortalTileEntity) sourceWorld.getTileEntity(sourcePortalPos);

    destWorld.setBlockState(dest.getPos(), ModBlocks.portalBlock.getDefaultState(), 3);
    PortalTileEntity destination = (PortalTileEntity) destWorld.getTileEntity(dest.getPos());

    source.setTimeout(Config.portalTimeout);
    source.setOther(dest);
    source.setPortalSide(selectedSide);

    destination.setTimeout(Config.portalTimeout);
    destination.setOther(new TeleportDestination("", sourceWorld.provider.getDimension(), sourcePortalPos, selectedSide));
    destination.setPortalSide(dest.getSide());
}
 
Example 13
Project: Bewitchment   File: BlockWitchAltar.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation")
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) {
	if (pos.getY() == fromPos.getY() && world.isAirBlock(fromPos) && !checkRecursive(world, pos, 0, new ArrayList<BlockPos>(6)) && blockIn.equals(ModBlocks.witch_altar)) {
		dismantleRecursive(world, pos);
	}
	;
}
 
Example 14
Project: BaseClient   File: WorldGenGlowStone2.java   View Source Code Vote up 4 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    if (!worldIn.isAirBlock(position))
    {
        return false;
    }
    else if (worldIn.getBlockState(position.up()).getBlock() != Blocks.netherrack)
    {
        return false;
    }
    else
    {
        worldIn.setBlockState(position, Blocks.glowstone.getDefaultState(), 2);

        for (int i = 0; i < 1500; ++i)
        {
            BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), -rand.nextInt(12), rand.nextInt(8) - rand.nextInt(8));

            if (worldIn.getBlockState(blockpos).getBlock().getMaterial() == Material.air)
            {
                int j = 0;

                for (EnumFacing enumfacing : EnumFacing.values())
                {
                    if (worldIn.getBlockState(blockpos.offset(enumfacing)).getBlock() == Blocks.glowstone)
                    {
                        ++j;
                    }

                    if (j > 1)
                    {
                        break;
                    }
                }

                if (j == 1)
                {
                    worldIn.setBlockState(blockpos, Blocks.glowstone.getDefaultState(), 2);
                }
            }
        }

        return true;
    }
}
 
Example 15
Project: CustomWorldGen   File: WorldGenLiquids.java   View Source Code Vote up 4 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    if (worldIn.getBlockState(position.up()).getBlock() != Blocks.STONE)
    {
        return false;
    }
    else if (worldIn.getBlockState(position.down()).getBlock() != Blocks.STONE)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(position);

        if (!iblockstate.getBlock().isAir(iblockstate, worldIn, position) && iblockstate.getBlock() != Blocks.STONE)
        {
            return false;
        }
        else
        {
            int i = 0;

            if (worldIn.getBlockState(position.west()).getBlock() == Blocks.STONE)
            {
                ++i;
            }

            if (worldIn.getBlockState(position.east()).getBlock() == Blocks.STONE)
            {
                ++i;
            }

            if (worldIn.getBlockState(position.north()).getBlock() == Blocks.STONE)
            {
                ++i;
            }

            if (worldIn.getBlockState(position.south()).getBlock() == Blocks.STONE)
            {
                ++i;
            }

            int j = 0;

            if (worldIn.isAirBlock(position.west()))
            {
                ++j;
            }

            if (worldIn.isAirBlock(position.east()))
            {
                ++j;
            }

            if (worldIn.isAirBlock(position.north()))
            {
                ++j;
            }

            if (worldIn.isAirBlock(position.south()))
            {
                ++j;
            }

            if (i == 3 && j == 1)
            {
                IBlockState iblockstate1 = this.block.getDefaultState();
                worldIn.setBlockState(position, iblockstate1, 2);
                worldIn.immediateBlockTick(position, iblockstate1, rand);
            }

            return true;
        }
    }
}
 
Example 16
Project: CustomWorldGen   File: WorldGenIcePath.java   View Source Code Vote up 4 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    while (worldIn.isAirBlock(position) && position.getY() > 2)
    {
        position = position.down();
    }

    if (worldIn.getBlockState(position).getBlock() != Blocks.SNOW)
    {
        return false;
    }
    else
    {
        int i = rand.nextInt(this.basePathWidth - 2) + 2;
        int j = 1;

        for (int k = position.getX() - i; k <= position.getX() + i; ++k)
        {
            for (int l = position.getZ() - i; l <= position.getZ() + i; ++l)
            {
                int i1 = k - position.getX();
                int j1 = l - position.getZ();

                if (i1 * i1 + j1 * j1 <= i * i)
                {
                    for (int k1 = position.getY() - 1; k1 <= position.getY() + 1; ++k1)
                    {
                        BlockPos blockpos = new BlockPos(k, k1, l);
                        Block block = worldIn.getBlockState(blockpos).getBlock();

                        if (block == Blocks.DIRT || block == Blocks.SNOW || block == Blocks.ICE)
                        {
                            worldIn.setBlockState(blockpos, this.block.getDefaultState(), 2);
                        }
                    }
                }
            }
        }

        return true;
    }
}
 
Example 17
Project: CustomWorldGen   File: ItemHoe.java   View Source Code Vote up 4 votes
/**
 * Called when a Block is right-clicked with this Item
 */
@SuppressWarnings("incomplete-switch")
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (!playerIn.canPlayerEdit(pos.offset(facing), facing, stack))
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(stack, playerIn, worldIn, pos);
        if (hook != 0) return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;

        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();

        if (facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up()))
        {
            if (block == Blocks.GRASS || block == Blocks.GRASS_PATH)
            {
                this.setBlock(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
                return EnumActionResult.SUCCESS;
            }

            if (block == Blocks.DIRT)
            {
                switch ((BlockDirt.DirtType)iblockstate.getValue(BlockDirt.VARIANT))
                {
                    case DIRT:
                        this.setBlock(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
                        return EnumActionResult.SUCCESS;
                    case COARSE_DIRT:
                        this.setBlock(stack, playerIn, worldIn, pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
                        return EnumActionResult.SUCCESS;
                }
            }
        }

        return EnumActionResult.PASS;
    }
}
 
Example 18
Project: IceMod   File: FlintAndIce.java   View Source Code Vote up 4 votes
/**
 * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
 * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
 */
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
    if (par7 == 0)
    {
        --par5;
    }

    if (par7 == 1)
    {
        ++par5;
    }

    if (par7 == 2)
    {
        --par6;
    }

    if (par7 == 3)
    {
        ++par6;
    }

    if (par7 == 4)
    {
        --par4;
    }

    if (par7 == 5)
    {
        ++par4;
    }

    if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
    {
        return false;
    }
    else
    {
        if (par3World.isAirBlock(par4, par5, par6))
        {
            par3World.playSoundEffect((double)par4 + 0.5D, (double)par5 + 0.5D, (double)par6 + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
            par3World.setBlock(par4, par5, par6, Block.ice.blockID);
        }

        par1ItemStack.damageItem(1, par2EntityPlayer);
        return true;
    }
}
 
Example 19
Project: Backmemed   File: BlockRailBase.java   View Source Code Vote up 4 votes
/**
 * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
 * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
 * block, etc.
 */
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos p_189540_5_)
{
    if (!worldIn.isRemote)
    {
        BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)state.getValue(this.getShapeProperty());
        boolean flag = false;

        if (!worldIn.getBlockState(pos.down()).isFullyOpaque())
        {
            flag = true;
        }

        if (blockrailbase$enumraildirection == BlockRailBase.EnumRailDirection.ASCENDING_EAST && !worldIn.getBlockState(pos.east()).isFullyOpaque())
        {
            flag = true;
        }
        else if (blockrailbase$enumraildirection == BlockRailBase.EnumRailDirection.ASCENDING_WEST && !worldIn.getBlockState(pos.west()).isFullyOpaque())
        {
            flag = true;
        }
        else if (blockrailbase$enumraildirection == BlockRailBase.EnumRailDirection.ASCENDING_NORTH && !worldIn.getBlockState(pos.north()).isFullyOpaque())
        {
            flag = true;
        }
        else if (blockrailbase$enumraildirection == BlockRailBase.EnumRailDirection.ASCENDING_SOUTH && !worldIn.getBlockState(pos.south()).isFullyOpaque())
        {
            flag = true;
        }

        if (flag && !worldIn.isAirBlock(pos))
        {
            this.dropBlockAsItem(worldIn, pos, state, 0);
            worldIn.setBlockToAir(pos);
        }
        else
        {
            this.updateState(state, worldIn, pos, blockIn);
        }
    }
}
 
Example 20
Project: DecompiledMinecraft   File: BlockStaticLiquid.java   View Source Code Vote up 4 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (this.blockMaterial == Material.lava)
    {
        if (worldIn.getGameRules().getBoolean("doFireTick"))
        {
            int i = rand.nextInt(3);

            if (i > 0)
            {
                BlockPos blockpos = pos;

                for (int j = 0; j < i; ++j)
                {
                    blockpos = blockpos.add(rand.nextInt(3) - 1, 1, rand.nextInt(3) - 1);
                    Block block = worldIn.getBlockState(blockpos).getBlock();

                    if (block.blockMaterial == Material.air)
                    {
                        if (this.isSurroundingBlockFlammable(worldIn, blockpos))
                        {
                            worldIn.setBlockState(blockpos, Blocks.fire.getDefaultState());
                            return;
                        }
                    }
                    else if (block.blockMaterial.blocksMovement())
                    {
                        return;
                    }
                }
            }
            else
            {
                for (int k = 0; k < 3; ++k)
                {
                    BlockPos blockpos1 = pos.add(rand.nextInt(3) - 1, 0, rand.nextInt(3) - 1);

                    if (worldIn.isAirBlock(blockpos1.up()) && this.getCanBlockBurn(worldIn, blockpos1))
                    {
                        worldIn.setBlockState(blockpos1.up(), Blocks.fire.getDefaultState());
                    }
                }
            }
        }
    }
}