Java Code Examples for net.minecraft.world.World#destroyBlock()
The following examples show how to use
net.minecraft.world.World#destroyBlock() .
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: TemplateEnderUtilities.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public void placeBlockAtIndex(World world, int index, BlockPos posStart) { if (index < this.blocks.size()) { TemplateEnderUtilities.TemplateBlockInfo blockInfo = this.blocks.get(index); BlockPos pos = transformedBlockPos(this.placement, blockInfo.pos).add(posStart); IBlockState stateNew = blockInfo.blockState; if (this.replaceMode == ReplaceMode.EVERYTHING || (this.replaceMode == ReplaceMode.WITH_NON_AIR && stateNew.getMaterial() != Material.AIR) || world.isAirBlock(pos)) { Mirror mirror = this.placement.getMirror(); Rotation rotation = this.placement.getRotation(); stateNew = stateNew.withMirror(mirror).withRotation(rotation); boolean success = false; if (this.dropOldBlocks) { world.destroyBlock(pos, true); } /* else { // Replace the block temporarily so that the old TE gets cleared for sure BlockUtils.setBlockToAirWithoutSpillingContents(world, pos, 4); } */ // Place the new block success = world.setBlockState(pos, stateNew, 2); if (success && blockInfo.tileEntityData != null) { TileUtils.createAndAddTileEntity(world, pos, blockInfo.tileEntityData, rotation, mirror); } } } }
Example 2
Source File: DebugModeClearGrass.java From AgriCraft with MIT License | 5 votes |
@Override public void debugActionBlockClicked(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { pos = pos.toImmutable(); for (int x = -radius; x < radius; x++) { for (int z = -radius; z < radius; z++) { BlockPos loc = pos.add(x, 0, z); Block block = world.getBlockState(loc).getBlock(); if (block instanceof BlockBush) { world.destroyBlock(loc, false); } } } }
Example 3
Source File: BlockRoutiduct.java From CommunityMod with GNU Lesser General Public License v2.1 | 5 votes |
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY) { if (playerIn.getHeldItem(hand).getItem() instanceof ItemWrench && playerIn.isSneaking()) { worldIn.destroyBlock(pos, true); return true; } return false; }
Example 4
Source File: BlockSurfaceRock.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { if (fromPos.up().equals(pos)) { if (worldIn.getBlockState(fromPos).getBlockFaceShape(worldIn, fromPos, EnumFacing.UP) != BlockFaceShape.SOLID) { worldIn.destroyBlock(pos, true); } } }
Example 5
Source File: BlockWaterHyacinth.java From Production-Line with MIT License | 5 votes |
/** * Called When an Entity Collided with the Block */ @Override 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 6
Source File: BlockContainerPL.java From Production-Line with MIT License | 5 votes |
@Override public void breakBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { TileEntity tileentity = world.getTileEntity(pos); if (tileentity != null && tileentity instanceof IInventory) { Inventories.spill(world, pos, (IInventory) tileentity); world.removeTileEntity(pos); } world.destroyBlock(pos, true); }
Example 7
Source File: BlockThatch.java From TFC2 with GNU General Public License v3.0 | 5 votes |
@Override public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) { if(!world.isRemote && pos.up().equals(fromPos) && world.isAirBlock(pos.down())) { if(world.getBlockState(fromPos).getBlock() instanceof BlockGravity) world.destroyBlock(pos, true); } }
Example 8
Source File: DebugModeTestBlockRange.java From AgriCraft with MIT License | 5 votes |
/** * This method allows the user to test what Block Positions are covered by the BlockRange * iterator. The expected result will be the full cuboid between opposing corner positions. Also * remember that the BlockRange min and max positions aren't necessarily the input positions. * * Usage: Right-click on two blocks to specify the opposite corners. Some blocks should get * replaced with free wool. Be careful. In case of terrible bugs, might destroy or overwrite * unexpected locations! */ @Override public void debugActionBlockClicked(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return; } Optional<BlockPos> startPos = getStartPos(stack); if (!startPos.isPresent()) { // This is the first click. Save 'pos' as the starting coordinate. setStartPos(stack, pos); player.sendMessage(new TextComponentString("Starting corner set: (" + pos.getX() + "," + pos.getY() + "," + pos.getZ() + ")")); player.sendMessage(new TextComponentString("Next right click will set the opposite/ending corner.")); player.sendMessage(new TextComponentString("WARNING: this mode will destroy blocks, be careful.")); } else { // This is the second click. Load the starting coordinate. Use 'pos' as the ending coordinate. Then fill the cuboid with wool. int count = 0; IBlockState wool = Blocks.WOOL.getDefaultState().withProperty(BlockColored.COLOR, EnumDyeColor.BLACK); // // IMPORTANT PART OF THE TEST IS BELOW // BlockRange range = new BlockRange(startPos.get(), pos); for (BlockPos target : range) { // <-- Is the iterator giving a complete set? IBlockState old = world.getBlockState(target); world.destroyBlock(target, true); world.setBlockState(target, wool); world.notifyBlockUpdate(target, old, wool, 2); count += 1; } // // IMPORTANT PART OF THE TEST IS ABOVE // player.sendMessage(new TextComponentString("Volume: " + range.getVolume())); player.sendMessage(new TextComponentString("Replaced: " + count)); player.sendMessage(new TextComponentString("Coverage: " + (range.getVolume() == count ? "Complete" : "INCOMPLETE"))); setStartPos(stack, null); } }
Example 9
Source File: BlockCertusTank.java From ExtraCells1 with MIT License | 4 votes |
@Override public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer entityplayer, int blockID, float offsetX, float offsetY, float offsetZ) { ItemStack current = entityplayer.inventory.getCurrentItem(); if (entityplayer.isSneaking() && current == null) { dropBlockAsItem_do(worldObj, x, y, z, getDropWithNBT(worldObj, x, y, z)); worldObj.destroyBlock(x, y, z, false); return true; } if (current != null) { FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current); TileEntityCertusTank tank = (TileEntityCertusTank) worldObj.getBlockTileEntity(x, y, z); if (liquid != null) { int amountFilled = tank.fill(ForgeDirection.UNKNOWN, liquid, true); if (amountFilled != 0 && !entityplayer.capabilities.isCreativeMode) { if (current.stackSize > 1) { entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1; entityplayer.inventory.addItemStackToInventory(current.getItem().getContainerItemStack(current)); } else { entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = current.getItem().getContainerItemStack(current); } } return true; // Handle empty containers } else { FluidStack available = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid; if (available != null) { ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current); liquid = FluidContainerRegistry.getFluidForFilledItem(filled); if (liquid != null) { if (!entityplayer.capabilities.isCreativeMode) { if (current.stackSize > 1) { if (!entityplayer.inventory.addItemStackToInventory(filled)) { tank.fill(ForgeDirection.UNKNOWN, new FluidStack(liquid, liquid.amount), true); return false; } else { entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1; } } else { entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = filled; } } tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true); return true; } } } } return false; }
Example 10
Source File: EntityAIHarvestTofuFarmland.java From TofuCraftReload with MIT License | 4 votes |
/** * Keep ticking a continuous task that has already been started */ public void updateTask() { super.updateTask(); this.villager.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.villager.getVerticalFaceSpeed()); if (this.getIsAboveDestination()) { World world = this.villager.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.villager.getVillagerInventory(); for (int i = 0; i < inventorybasic.getSizeInventory(); ++i) { ItemStack itemstack = inventorybasic.getStackInSlot(i); boolean flag = false; if (!itemstack.isEmpty()) { 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; } else if (itemstack.getItem() instanceof net.minecraftforge.common.IPlantable) { if(((net.minecraftforge.common.IPlantable)itemstack.getItem()).getPlantType(world,blockpos) == net.minecraftforge.common.EnumPlantType.Crop) { world.setBlockState(blockpos, ((net.minecraftforge.common.IPlantable)itemstack.getItem()).getPlant(world,blockpos),3); flag = true; } } } if (flag) { itemstack.shrink(1); if (itemstack.isEmpty()) { inventorybasic.setInventorySlotContents(i, ItemStack.EMPTY); } break; } } } this.currentTask = -1; this.runDelay = 10; } }
Example 11
Source File: OpenBlock.java From OpenModsLib with MIT License | 4 votes |
protected void breakBlockIfSideNotSolid(World world, BlockPos blockPos, EnumFacing direction) { if (!isNeighborBlockSolid(world, blockPos, direction)) { world.destroyBlock(blockPos, true); } }
Example 12
Source File: ItemEnderBucket.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
/** * Attempts to place one fluid block in the world, identified by the given FluidStack */ public boolean tryPlaceFluidBlock(World world, BlockPos pos, FluidStack fluidStack) { if (fluidStack == null || fluidStack.getFluid() == null || fluidStack.getFluid().canBePlacedInWorld() == false) { return false; } Block block = fluidStack.getFluid().getBlock(); // We need to convert water and lava to the flowing variant, otherwise we get non-flowing source blocks if (block == Blocks.WATER) { block = Blocks.FLOWING_WATER; } else if (block == Blocks.LAVA) { block = Blocks.FLOWING_LAVA; } IBlockState state = world.getBlockState(pos); Material material = state.getMaterial(); if (world.isAirBlock(pos) == false && material.isSolid()) { return false; } if (world.provider.doesWaterVaporize() && block == Blocks.FLOWING_WATER) { float x = pos.getX(); float y = pos.getY(); float z = pos.getZ(); world.playSound(null, x + 0.5F, y + 0.5F, z + 0.5F, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F); for (int l = 0; l < 8; ++l) { world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, x + Math.random(), y + Math.random(), z + Math.random(), 0.0D, 0.0D, 0.0D); } } else { if (world.isRemote == false && material.isSolid() == false && material.isLiquid() == false) { // Set a replaceable block to air, and drop the items world.destroyBlock(pos, true); } world.setBlockState(pos, block.getDefaultState(), 3); SoundEvent soundevent = block == Blocks.FLOWING_LAVA ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY; world.playSound(null, pos, soundevent, SoundCategory.BLOCKS, 1.0f, 1.0f); } return true; }
Example 13
Source File: ItemPortalScaler.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { // If the player is standing inside a portal, then we try to activate the teleportation in onItemRightClick() if (EntityUtils.isEntityCollidingWithBlockSpace(world, player, Blocks.PORTAL)) { return EnumActionResult.PASS; } Block block = world.getBlockState(pos).getBlock(); // When right clicking on a Nether Portal block, shut down the portal if (block == Blocks.PORTAL) { if (world.isRemote == false && world.isBlockModifiable(player, pos)) { world.destroyBlock(pos, false); } return EnumActionResult.SUCCESS; } if (world.isRemote) { return EnumActionResult.SUCCESS; } ItemStack stack = player.getHeldItem(hand); // When right clicking on Obsidian, try to light a Nether Portal if (block == Blocks.OBSIDIAN && world.isAirBlock(pos.offset(side)) && world.isBlockModifiable(player, pos.offset(side)) && UtilItemModular.useEnderCharge(stack, ENDER_CHARGE_COST_PORTAL_ACTIVATION, true) && Blocks.PORTAL.trySpawnPortal(world, pos.offset(side))) { UtilItemModular.useEnderCharge(stack, ENDER_CHARGE_COST_PORTAL_ACTIVATION, false); world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_BLAZE_SHOOT, SoundCategory.MASTER, 0.8f, 1.0f); return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; }
Example 14
Source File: BlockPlantBamboo.java From Sakura_mod with MIT License | 4 votes |
@Override public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { if (!this.canBlockStay(worldIn, pos)) { worldIn.destroyBlock(pos, true); } }
Example 15
Source File: BlockWindBell.java From Sakura_mod with MIT License | 4 votes |
@Override public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { if (!this.canBlockStay(worldIn, pos)) { worldIn.destroyBlock(pos, true); } }
Example 16
Source File: BlockNoren.java From Sakura_mod with MIT License | 4 votes |
protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state) { if (!this.canBlockStay(worldIn, pos)) { worldIn.destroyBlock(pos, true); } }
Example 17
Source File: BlockBambooShoot.java From Sakura_mod with MIT License | 4 votes |
@Override public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { if (!this.canBlockStay(worldIn, pos)) { worldIn.destroyBlock(pos, true); } }
Example 18
Source File: BlockYubaNoren.java From TofuCraftReload with MIT License | 4 votes |
protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state) { if (!this.canBlockStay(worldIn, pos)) { worldIn.destroyBlock(pos, true); } }
Example 19
Source File: BlockUnderVine.java From TofuCraftReload with MIT License | 4 votes |
protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state) { if (!this.canBlockStay(worldIn, pos)) { worldIn.destroyBlock(pos, true); } }