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

The following are Jave code examples for showing how to use setBlockToAir() 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.
Example 1
Project: BaseClient   File: BlockTorch.java   Source Code and License Vote up 6 votes
protected boolean onNeighborChangeInternal(World worldIn, BlockPos pos, IBlockState state) {
	if (!this.checkForDrop(worldIn, pos, state)) {
		return true;
	} else {
		EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
		EnumFacing.Axis enumfacing$axis = enumfacing.getAxis();
		EnumFacing enumfacing1 = enumfacing.getOpposite();
		boolean flag = false;

		if (enumfacing$axis.isHorizontal() && !worldIn.isBlockNormalCube(pos.offset(enumfacing1), true)) {
			flag = true;
		} else if (enumfacing$axis.isVertical() && !this.canPlaceOn(worldIn, pos.offset(enumfacing1))) {
			flag = true;
		}

		if (flag) {
			this.dropBlockAsItem(worldIn, pos, state, 0);
			worldIn.setBlockToAir(pos);
			return true;
		} else {
			return false;
		}
	}
}
 
Example 2
Project: BaseClient   File: BlockTorch.java   Source Code and License Vote up 6 votes
protected boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
{
    if (state.getBlock() == this && this.canPlaceAt(worldIn, pos, (EnumFacing)state.getValue(FACING)))
    {
        return true;
    }
    else
    {
        if (worldIn.getBlockState(pos).getBlock() == this)
        {
            this.dropBlockAsItem(worldIn, pos, state, 0);
            worldIn.setBlockToAir(pos);
        }

        return false;
    }
}
 
Example 3
Project: DecompiledMinecraft   File: BlockPistonExtension.java   Source Code and License Vote up 6 votes
/**
 * Called when a neighboring block changes.
 */
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
{
    EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
    BlockPos blockpos = pos.offset(enumfacing.getOpposite());
    IBlockState iblockstate = worldIn.getBlockState(blockpos);

    if (iblockstate.getBlock() != Blocks.piston && iblockstate.getBlock() != Blocks.sticky_piston)
    {
        worldIn.setBlockToAir(pos);
    }
    else
    {
        iblockstate.getBlock().onNeighborBlockChange(worldIn, blockpos, iblockstate, neighborBlock);
    }
}
 
Example 4
Project: Backmemed   File: BlockCake.java   Source Code and License Vote up 5 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 (!this.canBlockStay(worldIn, pos))
    {
        worldIn.setBlockToAir(pos);
    }
}
 
Example 5
Project: DecompiledMinecraft   File: BlockSnowBlock.java   Source Code and License Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (worldIn.getLightFor(EnumSkyBlock.BLOCK, pos) > 11)
    {
        this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
        worldIn.setBlockToAir(pos);
    }
}
 
Example 6
Project: ExPetrum   File: BlockBoulderOre.java   Source Code and License Vote up 5 votes
@SuppressWarnings("deprecation")
   @Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
	if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP))
	{
		this.dropBlockAsItem(worldIn, pos, state, 0);
		worldIn.setBlockToAir(pos);
	}
}
 
Example 7
Project: Proyecto-DASI   File: ClassroomDecoratorImplementation.java   Source Code and License Vote up 5 votes
private void drawJump(World world, Palette palette)
{
    int platformLeft = (this.left + this.right)/2 - 1;
    int platformFront = (this.front + this.back)/2 - 1;
    int platformBottom = this.below.y;
                
    // only works for a room height of 4 and floor height of 2
    
    if(this.hint){
    	setBlockState(world, new BlockPos(platformLeft, platformBottom - 1, platformFront - 1), palette.hint);
    	setBlockState(world, new BlockPos(platformLeft, platformBottom + 5, platformFront), palette.hint);
    }
    
    setBlockState(world, new BlockPos(platformLeft, platformBottom, platformFront), palette.platform);
    
    setBlockState(world, new BlockPos(platformLeft, platformBottom, platformFront + 1), palette.light);
    
    setBlockState(world, new BlockPos(platformLeft, platformBottom, platformFront + 2), palette.platform);
    setBlockState(world, new BlockPos(platformLeft, platformBottom + 1, platformFront + 2), palette.platform);
    
    setBlockState(world, new BlockPos(platformLeft + 2, platformBottom + 2, platformFront + 2), palette.platform);
    setBlockState(world, new BlockPos(platformLeft + 3, platformBottom + 2, platformFront + 2), palette.floor);
    setBlockState(world, new BlockPos(platformLeft + 3, platformBottom + 3, platformFront + 2), palette.floor);
    setBlockState(world, new BlockPos(platformLeft + 3, platformBottom + 3, platformFront + 3), palette.light, null, Facing.SOUTH, null);
    
    setBlockState(world, new BlockPos(platformLeft + 3, platformBottom + 3, platformFront), palette.floor);
    setBlockState(world, new BlockPos(platformLeft + 3, platformBottom + 3, platformFront - 1), palette.light, null, Facing.NORTH, null);
    setBlockState(world, new BlockPos(platformLeft + 2, platformBottom + 3, platformFront), palette.platform);
    
    world.setBlockToAir(new BlockPos(platformLeft + 1, platformBottom + 5, platformFront));
    setBlockState(world, new BlockPos(platformLeft + 1, platformBottom + 6, platformFront + 1), palette.light);
    
    for(int i = 0; i<3; i++){
        world.setBlockToAir(new BlockPos(platformLeft + i, platformBottom + 4, platformFront + 2));
        world.setBlockToAir(new BlockPos(platformLeft + i, platformBottom + 5, platformFront + 2));
        world.setBlockToAir(new BlockPos(platformLeft + 2, platformBottom + 4, platformFront + 2 - i));
        world.setBlockToAir(new BlockPos(platformLeft + 2, platformBottom + 5, platformFront + 2 - i));
    }
}
 
Example 8
Project: Firma   File: SaplingBlock2.java   Source Code and License Vote up 5 votes
public void growTree(World world, BlockPos bp, Random rand)
{
	IBlockState state = world.getBlockState(bp);
	int meta = this.getMetaFromState(state);
	String name = this.getMetaName(meta);
	world.setBlockToAir(bp);
	FirmaTree worldGen = FirmaBiome.getTreeGen(name);
	if (worldGen != null){
		worldGen.set(FirmaMod.log2.getStateFromMeta(meta), FirmaMod.leaf2.getStateFromMeta(meta));
		worldGen.generate(world, rand, bp);
	}
}
 
Example 9
Project: Backmemed   File: BlockTNT.java   Source Code and License Vote up 5 votes
/**
 * Called after the block is set in the Chunk data, but before the Tile Entity is set
 */
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
    super.onBlockAdded(worldIn, pos, state);

    if (worldIn.isBlockPowered(pos))
    {
        this.onBlockDestroyedByPlayer(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
        worldIn.setBlockToAir(pos);
    }
}
 
Example 10
Project: Proyecto-DASI   File: ClassroomDecoratorImplementation.java   Source Code and License Vote up 5 votes
private void drawJump(World world, Palette palette)
{
    int platformLeft = (this.left + this.right)/2 - 1;
    int platformFront = (this.front + this.back)/2 - 1;
    int platformBottom = this.below.y;
                
    // only works for a room height of 4 and floor height of 2
    
    if(this.hint){
    	setBlockState(world, new BlockPos(platformLeft, platformBottom - 1, platformFront - 1), palette.hint);
    	setBlockState(world, new BlockPos(platformLeft, platformBottom + 5, platformFront), palette.hint);
    }
    
    setBlockState(world, new BlockPos(platformLeft, platformBottom, platformFront), palette.platform);
    
    setBlockState(world, new BlockPos(platformLeft, platformBottom, platformFront + 1), palette.light);
    
    setBlockState(world, new BlockPos(platformLeft, platformBottom, platformFront + 2), palette.platform);
    setBlockState(world, new BlockPos(platformLeft, platformBottom + 1, platformFront + 2), palette.platform);
    
    setBlockState(world, new BlockPos(platformLeft + 2, platformBottom + 2, platformFront + 2), palette.platform);
    setBlockState(world, new BlockPos(platformLeft + 3, platformBottom + 2, platformFront + 2), palette.floor);
    setBlockState(world, new BlockPos(platformLeft + 3, platformBottom + 3, platformFront + 2), palette.floor);
    setBlockState(world, new BlockPos(platformLeft + 3, platformBottom + 3, platformFront + 3), palette.light, null, Facing.SOUTH, null);
    
    setBlockState(world, new BlockPos(platformLeft + 3, platformBottom + 3, platformFront), palette.floor);
    setBlockState(world, new BlockPos(platformLeft + 3, platformBottom + 3, platformFront - 1), palette.light, null, Facing.NORTH, null);
    setBlockState(world, new BlockPos(platformLeft + 2, platformBottom + 3, platformFront), palette.platform);
    
    world.setBlockToAir(new BlockPos(platformLeft + 1, platformBottom + 5, platformFront));
    setBlockState(world, new BlockPos(platformLeft + 1, platformBottom + 6, platformFront + 1), palette.light);
    
    for(int i = 0; i<3; i++){
        world.setBlockToAir(new BlockPos(platformLeft + i, platformBottom + 4, platformFront + 2));
        world.setBlockToAir(new BlockPos(platformLeft + i, platformBottom + 5, platformFront + 2));
        world.setBlockToAir(new BlockPos(platformLeft + 2, platformBottom + 4, platformFront + 2 - i));
        world.setBlockToAir(new BlockPos(platformLeft + 2, platformBottom + 5, platformFront + 2 - i));
    }
}
 
Example 11
Project: DecompiledMinecraft   File: BlockCarpet.java   Source Code and License Vote up 5 votes
private boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
{
    if (!this.canBlockStay(worldIn, pos))
    {
        this.dropBlockAsItem(worldIn, pos, state, 0);
        worldIn.setBlockToAir(pos);
        return false;
    }
    else
    {
        return true;
    }
}
 
Example 12
Project: BaseClient   File: BlockRedstoneWire.java   Source Code and License Vote up 5 votes
/**
 * Called when a neighboring block changes.
 */
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
	if (!worldIn.isRemote) {
		if (this.canPlaceBlockAt(worldIn, pos)) {
			this.updateSurroundingRedstone(worldIn, pos, state);
		} else {
			this.dropBlockAsItem(worldIn, pos, state, 0);
			worldIn.setBlockToAir(pos);
		}
	}
}
 
Example 13
Project: DecompiledMinecraft   File: BlockTNT.java   Source Code and License Vote up 5 votes
/**
 * Called when a neighboring block changes.
 */
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
{
    if (worldIn.isBlockPowered(pos))
    {
        this.onBlockDestroyedByPlayer(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
        worldIn.setBlockToAir(pos);
    }
}
 
Example 14
Project: BaseClient   File: BlockIce.java   Source Code and License Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (worldIn.getLightFor(EnumSkyBlock.BLOCK, pos) > 11 - this.getLightOpacity())
    {
        if (worldIn.provider.doesWaterVaporize())
        {
            worldIn.setBlockToAir(pos);
        }
        else
        {
            this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
            worldIn.setBlockState(pos, Blocks.water.getDefaultState());
        }
    }
}
 
Example 15
Project: BaseClient   File: BlockDragonEgg.java   Source Code and License Vote up 5 votes
private void teleport(World worldIn, BlockPos pos)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);

    if (iblockstate.getBlock() == this)
    {
        for (int i = 0; i < 1000; ++i)
        {
            BlockPos blockpos = pos.add(worldIn.rand.nextInt(16) - worldIn.rand.nextInt(16), worldIn.rand.nextInt(8) - worldIn.rand.nextInt(8), worldIn.rand.nextInt(16) - worldIn.rand.nextInt(16));

            if (worldIn.getBlockState(blockpos).getBlock().blockMaterial == Material.air)
            {
                if (worldIn.isRemote)
                {
                    for (int j = 0; j < 128; ++j)
                    {
                        double d0 = worldIn.rand.nextDouble();
                        float f = (worldIn.rand.nextFloat() - 0.5F) * 0.2F;
                        float f1 = (worldIn.rand.nextFloat() - 0.5F) * 0.2F;
                        float f2 = (worldIn.rand.nextFloat() - 0.5F) * 0.2F;
                        double d1 = (double)blockpos.getX() + (double)(pos.getX() - blockpos.getX()) * d0 + (worldIn.rand.nextDouble() - 0.5D) * 1.0D + 0.5D;
                        double d2 = (double)blockpos.getY() + (double)(pos.getY() - blockpos.getY()) * d0 + worldIn.rand.nextDouble() * 1.0D - 0.5D;
                        double d3 = (double)blockpos.getZ() + (double)(pos.getZ() - blockpos.getZ()) * d0 + (worldIn.rand.nextDouble() - 0.5D) * 1.0D + 0.5D;
                        worldIn.spawnParticle(EnumParticleTypes.PORTAL, d1, d2, d3, (double)f, (double)f1, (double)f2, new int[0]);
                    }
                }
                else
                {
                    worldIn.setBlockState(blockpos, iblockstate, 2);
                    worldIn.setBlockToAir(pos);
                }

                return;
            }
        }
    }
}
 
Example 16
Project: DecompiledMinecraft   File: BlockTNT.java   Source Code and License Vote up 5 votes
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
    super.onBlockAdded(worldIn, pos, state);

    if (worldIn.isBlockPowered(pos))
    {
        this.onBlockDestroyedByPlayer(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
        worldIn.setBlockToAir(pos);
    }
}
 
Example 17
Project: CustomWorldGen   File: BlockFluidFinite.java   Source Code and License Vote up 5 votes
@Override
public FluidStack drain(World world, BlockPos pos, boolean doDrain)
{
    final FluidStack fluidStack = new FluidStack(getFluid(), MathHelper.floor_float(getQuantaPercentage(world, pos) * Fluid.BUCKET_VOLUME));

    if (doDrain)
    {
        world.setBlockToAir(pos);
    }

    return fluidStack;
}
 
Example 18
Project: BaseClient   File: ItemBucket.java   Source Code and License Vote up 4 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    boolean flag = this.isFull == Blocks.air;
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, flag);

    if (movingobjectposition == null)
    {
        return itemStackIn;
    }
    else
    {
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
        {
            BlockPos blockpos = movingobjectposition.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos))
            {
                return itemStackIn;
            }

            if (flag)
            {
                if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn))
                {
                    return itemStackIn;
                }

                IBlockState iblockstate = worldIn.getBlockState(blockpos);
                Material material = iblockstate.getBlock().getMaterial();

                if (material == Material.water && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    worldIn.setBlockToAir(blockpos);
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return this.fillBucket(itemStackIn, playerIn, Items.water_bucket);
                }

                if (material == Material.lava && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    worldIn.setBlockToAir(blockpos);
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return this.fillBucket(itemStackIn, playerIn, Items.lava_bucket);
                }
            }
            else
            {
                if (this.isFull == Blocks.air)
                {
                    return new ItemStack(Items.bucket);
                }

                BlockPos blockpos1 = blockpos.offset(movingobjectposition.sideHit);

                if (!playerIn.canPlayerEdit(blockpos1, movingobjectposition.sideHit, itemStackIn))
                {
                    return itemStackIn;
                }

                if (this.tryPlaceContainedLiquid(worldIn, blockpos1) && !playerIn.capabilities.isCreativeMode)
                {
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return new ItemStack(Items.bucket);
                }
            }
        }

        return itemStackIn;
    }
}
 
Example 19
Project: DecompiledMinecraft   File: BlockPistonBase.java   Source Code and License Vote up 4 votes
private boolean doMove(World worldIn, BlockPos pos, EnumFacing direction, boolean extending)
{
    if (!extending)
    {
        worldIn.setBlockToAir(pos.offset(direction));
    }

    BlockPistonStructureHelper blockpistonstructurehelper = new BlockPistonStructureHelper(worldIn, pos, direction, extending);
    List<BlockPos> list = blockpistonstructurehelper.getBlocksToMove();
    List<BlockPos> list1 = blockpistonstructurehelper.getBlocksToDestroy();

    if (!blockpistonstructurehelper.canMove())
    {
        return false;
    }
    else
    {
        int i = list.size() + list1.size();
        Block[] ablock = new Block[i];
        EnumFacing enumfacing = extending ? direction : direction.getOpposite();

        for (int j = list1.size() - 1; j >= 0; --j)
        {
            BlockPos blockpos = (BlockPos)list1.get(j);
            Block block = worldIn.getBlockState(blockpos).getBlock();
            block.dropBlockAsItem(worldIn, blockpos, worldIn.getBlockState(blockpos), 0);
            worldIn.setBlockToAir(blockpos);
            --i;
            ablock[i] = block;
        }

        for (int k = list.size() - 1; k >= 0; --k)
        {
            BlockPos blockpos2 = (BlockPos)list.get(k);
            IBlockState iblockstate = worldIn.getBlockState(blockpos2);
            Block block1 = iblockstate.getBlock();
            block1.getMetaFromState(iblockstate);
            worldIn.setBlockToAir(blockpos2);
            blockpos2 = blockpos2.offset(enumfacing);
            worldIn.setBlockState(blockpos2, Blocks.piston_extension.getDefaultState().withProperty(FACING, direction), 4);
            worldIn.setTileEntity(blockpos2, BlockPistonMoving.newTileEntity(iblockstate, direction, extending, false));
            --i;
            ablock[i] = block1;
        }

        BlockPos blockpos1 = pos.offset(direction);

        if (extending)
        {
            BlockPistonExtension.EnumPistonType blockpistonextension$enumpistontype = this.isSticky ? BlockPistonExtension.EnumPistonType.STICKY : BlockPistonExtension.EnumPistonType.DEFAULT;
            IBlockState iblockstate1 = Blocks.piston_head.getDefaultState().withProperty(BlockPistonExtension.FACING, direction).withProperty(BlockPistonExtension.TYPE, blockpistonextension$enumpistontype);
            IBlockState iblockstate2 = Blocks.piston_extension.getDefaultState().withProperty(BlockPistonMoving.FACING, direction).withProperty(BlockPistonMoving.TYPE, this.isSticky ? BlockPistonExtension.EnumPistonType.STICKY : BlockPistonExtension.EnumPistonType.DEFAULT);
            worldIn.setBlockState(blockpos1, iblockstate2, 4);
            worldIn.setTileEntity(blockpos1, BlockPistonMoving.newTileEntity(iblockstate1, direction, true, false));
        }

        for (int l = list1.size() - 1; l >= 0; --l)
        {
            worldIn.notifyNeighborsOfStateChange((BlockPos)list1.get(l), ablock[i++]);
        }

        for (int i1 = list.size() - 1; i1 >= 0; --i1)
        {
            worldIn.notifyNeighborsOfStateChange((BlockPos)list.get(i1), ablock[i++]);
        }

        if (extending)
        {
            worldIn.notifyNeighborsOfStateChange(blockpos1, Blocks.piston_head);
            worldIn.notifyNeighborsOfStateChange(pos, this);
        }

        return true;
    }
}
 
Example 20
Project: Backmemed   File: BlockLeaves.java   Source Code and License Vote up 4 votes
private void destroy(World worldIn, BlockPos pos)
{
    this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
    worldIn.setBlockToAir(pos);
}