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

The following are Jave code examples for showing how to use destroyBlock() 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: BaseClient   File: EntityRabbit.java   View Source Code Vote up 6 votes
public void updateTask()
{
    super.updateTask();
    this.field_179500_c.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.field_179500_c.getVerticalFaceSpeed());

    if (this.getIsAboveDestination())
    {
        World world = this.field_179500_c.worldObj;
        BlockPos blockpos = this.destinationBlock.up();
        IBlockState iblockstate = world.getBlockState(blockpos);
        Block block = iblockstate.getBlock();

        if (this.field_179499_e && block instanceof BlockCarrot && ((Integer)iblockstate.getValue(BlockCarrot.AGE)).intValue() == 7)
        {
            world.setBlockState(blockpos, Blocks.air.getDefaultState(), 2);
            world.destroyBlock(blockpos, true);
            this.field_179500_c.createEatingParticles();
        }

        this.field_179499_e = false;
        this.runDelay = 10;
    }
}
 
Example 2
Project: CharcoalPit   File: BlockPotteryKiln.java   View Source Code Vote up 6 votes
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
	if(pos.offset(EnumFacing.DOWN).equals(fromPos)&&
			!worldIn.getBlockState(fromPos).isSideSolid(worldIn, fromPos, EnumFacing.UP)){
		worldIn.destroyBlock(pos, true);
		return;
	}
	if(state.getValue(TYPE)==EnumKilnTypes.ACTIVE){
		if(pos.offset(EnumFacing.UP).equals(fromPos)){
			IBlockState fromState=worldIn.getBlockState(fromPos);
			if(fromState.getBlock()==Blocks.FIRE)
				return;
			((TilePotteryKiln)worldIn.getTileEntity(pos)).isValid=false;
		}
		((TilePotteryKiln)worldIn.getTileEntity(pos)).isValid=false;
	}
}
 
Example 3
Project: harshencastle   File: HereticCauldronTop.java   View Source Code Vote up 5 votes
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) {
	if(worldIn.getBlockState(pos.down()).getBlock() instanceof HereticCauldron)
	{
		worldIn.getBlockState(pos.down()).getBlock().onBlockHarvested(worldIn, pos.down(), worldIn.getBlockState(pos.down()), player);
		worldIn.destroyBlock(pos.down(), !player.isCreative());
	}
}
 
Example 4
Project: Backmemed   File: BlockCactus.java   View Source Code 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.destroyBlock(pos, true);
    }
}
 
Example 5
Project: RunicArcana   File: BlockChalkBase.java   View Source Code Vote up 5 votes
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) {
    if(!worldIn.isRemote) {
        if(!worldIn.getBlockState(pos.down()).isOpaqueCube())
        {
            worldIn.destroyBlock(pos,false);
        }
    }
    super.neighborChanged(state, worldIn, pos, blockIn);
}
 
Example 6
Project: Got-Wood   File: BlockBambooLog.java   View Source Code Vote up 5 votes
protected final void checkAndDropBlock(World world, BlockPos pos, IBlockState state) {
	boolean drop = world.getBlockState(pos.down()).getBlock() != this && !world.getBlockState(pos.down()).isNormalCube();
	if (drop && !world.isRemote) {
		world.destroyBlock(pos, true);
		breakBlock(world, pos, state);
	}
}
 
Example 7
Project: CustomWorldGen   File: BlockLilyPad.java   View Source Code Vote up 5 votes
/**
 * Called When an Entity Collided with the Block
 */
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
    super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);

    if (entityIn instanceof EntityBoat)
    {
        worldIn.destroyBlock(new BlockPos(pos), true);
    }
}
 
Example 8
Project: BaseClient   File: EntitySilverfish.java   View Source Code Vote up 5 votes
public void updateTask()
{
    --this.field_179463_b;

    if (this.field_179463_b <= 0)
    {
        World world = this.silverfish.worldObj;
        Random random = this.silverfish.getRNG();
        BlockPos blockpos = new BlockPos(this.silverfish);

        for (int i = 0; i <= 5 && i >= -5; i = i <= 0 ? 1 - i : 0 - i)
        {
            for (int j = 0; j <= 10 && j >= -10; j = j <= 0 ? 1 - j : 0 - j)
            {
                for (int k = 0; k <= 10 && k >= -10; k = k <= 0 ? 1 - k : 0 - k)
                {
                    BlockPos blockpos1 = blockpos.add(j, i, k);
                    IBlockState iblockstate = world.getBlockState(blockpos1);

                    if (iblockstate.getBlock() == Blocks.monster_egg)
                    {
                        if (world.getGameRules().getBoolean("mobGriefing"))
                        {
                            world.destroyBlock(blockpos1, true);
                        }
                        else
                        {
                            world.setBlockState(blockpos1, ((BlockSilverfish.EnumType)iblockstate.getValue(BlockSilverfish.VARIANT)).getModelBlock(), 3);
                        }

                        if (random.nextBoolean())
                        {
                            return;
                        }
                    }
                }
            }
        }
    }
}
 
Example 9
Project: BaseClient   File: EntitySilverfish.java   View Source Code Vote up 5 votes
public void updateTask()
{
    --this.field_179463_b;

    if (this.field_179463_b <= 0)
    {
        World world = this.silverfish.worldObj;
        Random random = this.silverfish.getRNG();
        BlockPos blockpos = new BlockPos(this.silverfish);

        for (int i = 0; i <= 5 && i >= -5; i = i <= 0 ? 1 - i : 0 - i)
        {
            for (int j = 0; j <= 10 && j >= -10; j = j <= 0 ? 1 - j : 0 - j)
            {
                for (int k = 0; k <= 10 && k >= -10; k = k <= 0 ? 1 - k : 0 - k)
                {
                    BlockPos blockpos1 = blockpos.add(j, i, k);
                    IBlockState iblockstate = world.getBlockState(blockpos1);

                    if (iblockstate.getBlock() == Blocks.monster_egg)
                    {
                        if (world.getGameRules().getBoolean("mobGriefing"))
                        {
                            world.destroyBlock(blockpos1, true);
                        }
                        else
                        {
                            world.setBlockState(blockpos1, ((BlockSilverfish.EnumType)iblockstate.getValue(BlockSilverfish.VARIANT)).getModelBlock(), 3);
                        }

                        if (random.nextBoolean())
                        {
                            return;
                        }
                    }
                }
            }
        }
    }
}
 
Example 10
Project: CustomWorldGen   File: BlockChorusPlant.java   View Source Code Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!this.canSurviveAt(worldIn, pos))
    {
        worldIn.destroyBlock(pos, true);
    }
}
 
Example 11
Project: DecompiledMinecraft   File: BlockCactus.java   View Source Code Vote up 5 votes
/**
 * Called when a neighboring block changes.
 */
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
{
    if (!this.canBlockStay(worldIn, pos))
    {
        worldIn.destroyBlock(pos, true);
    }
}
 
Example 12
Project: Bewitchment   File: BlockCircleGlyph.java   View Source Code Vote up 4 votes
@SuppressWarnings("deprecation")
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
	if (!this.canPlaceBlockAt(worldIn, pos)) worldIn.destroyBlock(pos, false);
}
 
Example 13
Project: CustomWorldGen   File: FluidUtil.java   View Source Code Vote up 4 votes
/**
 * Tries to place a fluid in the world in block form.
 * Makes a fluid emptying sound when successful.
 * Checks if water-like fluids should vaporize like in the nether.
 *
 * Modeled after {@link net.minecraft.item.ItemBucket#tryPlaceContainedLiquid(EntityPlayer, World, BlockPos)}
 *
 * @param player     Player who places the fluid. May be null for blocks like dispensers.
 * @param worldIn    World to place the fluid in
 * @param fluidStack The fluidStack to place.
 * @param pos        The position in the world to place the fluid block
 * @return true if successful
 */
public static boolean tryPlaceFluid(@Nullable EntityPlayer player, World worldIn, FluidStack fluidStack, BlockPos pos)
{
    if (worldIn == null || fluidStack == null || pos == null)
    {
        return false;
    }

    Fluid fluid = fluidStack.getFluid();
    if (fluid == null || !fluid.canBePlacedInWorld())
    {
        return false;
    }

    // check that we can place the fluid at the destination
    IBlockState destBlockState = worldIn.getBlockState(pos);
    Material destMaterial = destBlockState.getMaterial();
    boolean isDestNonSolid = !destMaterial.isSolid();
    boolean isDestReplaceable = destBlockState.getBlock().isReplaceable(worldIn, pos);
    if (!worldIn.isAirBlock(pos) && !isDestNonSolid && !isDestReplaceable)
    {
        return false; // Non-air, solid, unreplacable block. We can't put fluid here.
    }

    if (worldIn.provider.doesWaterVaporize() && fluid.doesVaporize(fluidStack))
    {
        fluid.vaporize(player, worldIn, pos, fluidStack);
    }
    else
    {
        if (!worldIn.isRemote && (isDestNonSolid || isDestReplaceable) && !destMaterial.isLiquid())
        {
            worldIn.destroyBlock(pos, true);
        }

        SoundEvent soundevent = fluid.getEmptySound(fluidStack);
        worldIn.playSound(player, pos, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);

        IBlockState fluidBlockState = fluid.getBlock().getDefaultState();
        worldIn.setBlockState(pos, fluidBlockState, 11);
    }
    return true;
}
 
Example 14
Project: CustomWorldGen   File: ItemBucket.java   View Source Code Vote up 4 votes
public boolean tryPlaceContainedLiquid(@Nullable EntityPlayer player, World worldIn, BlockPos posIn)
{
    if (this.containedBlock == Blocks.AIR)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(posIn);
        Material material = iblockstate.getMaterial();
        boolean flag = !material.isSolid();
        boolean flag1 = iblockstate.getBlock().isReplaceable(worldIn, posIn);

        if (!worldIn.isAirBlock(posIn) && !flag && !flag1)
        {
            return false;
        }
        else
        {
            if (worldIn.provider.doesWaterVaporize() && this.containedBlock == Blocks.FLOWING_WATER)
            {
                int l = posIn.getX();
                int i = posIn.getY();
                int j = posIn.getZ();
                worldIn.playSound(player, posIn, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);

                for (int k = 0; k < 8; ++k)
                {
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)l + Math.random(), (double)i + Math.random(), (double)j + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
                }
            }
            else
            {
                if (!worldIn.isRemote && (flag || flag1) && !material.isLiquid())
                {
                    worldIn.destroyBlock(posIn, true);
                }

                SoundEvent soundevent = this.containedBlock == Blocks.FLOWING_LAVA ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY;
                worldIn.playSound(player, posIn, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
                worldIn.setBlockState(posIn, this.containedBlock.getDefaultState(), 11);
            }

            return true;
        }
    }
}
 
Example 15
Project: BaseClient   File: BlockDoublePlant.java   View Source Code Vote up 4 votes
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
    {
        if (worldIn.getBlockState(pos.down()).getBlock() == this)
        {
            if (!player.capabilities.isCreativeMode)
            {
                IBlockState iblockstate = worldIn.getBlockState(pos.down());
                BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);

                if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
                {
                    worldIn.destroyBlock(pos.down(), true);
                }
                else if (!worldIn.isRemote)
                {
                    if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
                    {
                        this.onHarvest(worldIn, pos, iblockstate, player);
                        worldIn.setBlockToAir(pos.down());
                    }
                    else
                    {
                        worldIn.destroyBlock(pos.down(), true);
                    }
                }
                else
                {
                    worldIn.setBlockToAir(pos.down());
                }
            }
            else
            {
                worldIn.setBlockToAir(pos.down());
            }
        }
    }
    else if (player.capabilities.isCreativeMode && worldIn.getBlockState(pos.up()).getBlock() == this)
    {
        worldIn.setBlockState(pos.up(), Blocks.air.getDefaultState(), 2);
    }

    super.onBlockHarvested(worldIn, pos, state, player);
}
 
Example 16
Project: Backmemed   File: EntityAIHarvestFarmland.java   View Source Code Vote up 4 votes
/**
 * Updates the task
 */
public void updateTask()
{
    super.updateTask();
    this.theVillager.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.theVillager.getVerticalFaceSpeed());

    if (this.getIsAboveDestination())
    {
        World world = this.theVillager.world;
        BlockPos blockpos = this.destinationBlock.up();
        IBlockState iblockstate = world.getBlockState(blockpos);
        Block block = iblockstate.getBlock();

        if (this.currentTask == 0 && block instanceof BlockCrops && ((BlockCrops)block).isMaxAge(iblockstate))
        {
            world.destroyBlock(blockpos, true);
        }
        else if (this.currentTask == 1 && iblockstate.getMaterial() == Material.AIR)
        {
            InventoryBasic inventorybasic = this.theVillager.getVillagerInventory();

            for (int i = 0; i < inventorybasic.getSizeInventory(); ++i)
            {
                ItemStack itemstack = inventorybasic.getStackInSlot(i);
                boolean flag = false;

                if (!itemstack.func_190926_b())
                {
                    if (itemstack.getItem() == Items.WHEAT_SEEDS)
                    {
                        world.setBlockState(blockpos, Blocks.WHEAT.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.POTATO)
                    {
                        world.setBlockState(blockpos, Blocks.POTATOES.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.CARROT)
                    {
                        world.setBlockState(blockpos, Blocks.CARROTS.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.BEETROOT_SEEDS)
                    {
                        world.setBlockState(blockpos, Blocks.BEETROOTS.getDefaultState(), 3);
                        flag = true;
                    }
                }

                if (flag)
                {
                    itemstack.func_190918_g(1);

                    if (itemstack.func_190926_b())
                    {
                        inventorybasic.setInventorySlotContents(i, ItemStack.field_190927_a);
                    }

                    break;
                }
            }
        }

        this.currentTask = -1;
        this.runDelay = 10;
    }
}
 
Example 17
Project: Backmemed   File: ItemBucket.java   View Source Code Vote up 4 votes
public boolean tryPlaceContainedLiquid(@Nullable EntityPlayer player, World worldIn, BlockPos posIn)
{
    if (this.containedBlock == Blocks.AIR)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(posIn);
        Material material = iblockstate.getMaterial();
        boolean flag = !material.isSolid();
        boolean flag1 = iblockstate.getBlock().isReplaceable(worldIn, posIn);

        if (!worldIn.isAirBlock(posIn) && !flag && !flag1)
        {
            return false;
        }
        else
        {
            if (worldIn.provider.doesWaterVaporize() && this.containedBlock == Blocks.FLOWING_WATER)
            {
                int l = posIn.getX();
                int i = posIn.getY();
                int j = posIn.getZ();
                worldIn.playSound(player, posIn, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);

                for (int k = 0; k < 8; ++k)
                {
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)l + Math.random(), (double)i + Math.random(), (double)j + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
                }
            }
            else
            {
                if (!worldIn.isRemote && (flag || flag1) && !material.isLiquid())
                {
                    worldIn.destroyBlock(posIn, true);
                }

                SoundEvent soundevent = this.containedBlock == Blocks.FLOWING_LAVA ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY;
                worldIn.playSound(player, posIn, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
                worldIn.setBlockState(posIn, this.containedBlock.getDefaultState(), 11);
            }

            return true;
        }
    }
}
 
Example 18
Project: CustomWorldGen   File: BlockDoublePlant.java   View Source Code Vote up 4 votes
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
    {
        if (worldIn.getBlockState(pos.down()).getBlock() == this)
        {
            if (player.capabilities.isCreativeMode)
            {
                worldIn.setBlockToAir(pos.down());
            }
            else
            {
                IBlockState iblockstate = worldIn.getBlockState(pos.down());
                BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);

                if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
                {
                    worldIn.destroyBlock(pos.down(), true);
                }
                else if (worldIn.isRemote)
                {
                    worldIn.setBlockToAir(pos.down());
                }
                else if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() == Items.SHEARS)
                {
                    this.onHarvest(worldIn, pos, iblockstate, player);
                    worldIn.setBlockToAir(pos.down());
                }
                else
                {
                    worldIn.destroyBlock(pos.down(), true);
                }
            }
        }
    }
    else if (worldIn.getBlockState(pos.up()).getBlock() == this)
    {
        worldIn.setBlockState(pos.up(), Blocks.AIR.getDefaultState(), 2);
    }

    super.onBlockHarvested(worldIn, pos, state, player);
}
 
Example 19
Project: DecompiledMinecraft   File: ItemBucket.java   View Source Code Vote up 4 votes
public boolean tryPlaceContainedLiquid(World worldIn, BlockPos pos)
{
    if (this.isFull == Blocks.air)
    {
        return false;
    }
    else
    {
        Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
        boolean flag = !material.isSolid();

        if (!worldIn.isAirBlock(pos) && !flag)
        {
            return false;
        }
        else
        {
            if (worldIn.provider.doesWaterVaporize() && this.isFull == Blocks.flowing_water)
            {
                int i = pos.getX();
                int j = pos.getY();
                int k = pos.getZ();
                worldIn.playSoundEffect((double)((float)i + 0.5F), (double)((float)j + 0.5F), (double)((float)k + 0.5F), "random.fizz", 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);

                for (int l = 0; l < 8; ++l)
                {
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)i + Math.random(), (double)j + Math.random(), (double)k + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
                }
            }
            else
            {
                if (!worldIn.isRemote && flag && !material.isLiquid())
                {
                    worldIn.destroyBlock(pos, true);
                }

                worldIn.setBlockState(pos, this.isFull.getDefaultState(), 3);
            }

            return true;
        }
    }
}
 
Example 20
Project: DecompiledMinecraft   File: BlockDoublePlant.java   View Source Code Vote up 4 votes
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
    {
        if (worldIn.getBlockState(pos.down()).getBlock() == this)
        {
            if (!player.capabilities.isCreativeMode)
            {
                IBlockState iblockstate = worldIn.getBlockState(pos.down());
                BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);

                if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
                {
                    worldIn.destroyBlock(pos.down(), true);
                }
                else if (!worldIn.isRemote)
                {
                    if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
                    {
                        this.onHarvest(worldIn, pos, iblockstate, player);
                        worldIn.setBlockToAir(pos.down());
                    }
                    else
                    {
                        worldIn.destroyBlock(pos.down(), true);
                    }
                }
                else
                {
                    worldIn.setBlockToAir(pos.down());
                }
            }
            else
            {
                worldIn.setBlockToAir(pos.down());
            }
        }
    }
    else if (player.capabilities.isCreativeMode && worldIn.getBlockState(pos.up()).getBlock() == this)
    {
        worldIn.setBlockState(pos.up(), Blocks.air.getDefaultState(), 2);
    }

    super.onBlockHarvested(worldIn, pos, state, player);
}