Class EditSession

java.lang.Object
com.sk89q.worldedit.EditSession
All Implemented Interfaces:
Extent, InputExtent, OutputExtent, AutoCloseable

public class EditSession extends Object implements Extent, AutoCloseable
An Extent that handles history, BlockBags, change limits, block re-ordering, and much more. Most operations in WorldEdit use this class.

Most of the actual functionality is implemented with a number of other Extents that are chained together. For example, history is logged using the ChangeSetExtent.

  • Field Details

    • world

      protected final World world
  • Method Details

    • enableStandardMode

      public void enableStandardMode()
      Turns on specific features for a normal WorldEdit session, such as chunk batching.
    • setReorderMode

      @Deprecated public void setReorderMode(EditSession.ReorderMode reorderMode)
      Deprecated.
      Sets the EditSession.ReorderMode of this EditSession, and flushes the session.
      Parameters:
      reorderMode - The reorder mode
    • getReorderMode

      @Deprecated public EditSession.ReorderMode getReorderMode()
      Deprecated.
      Get the reorder mode.
      Returns:
      the reorder mode
    • getWorld

      public World getWorld()
      Get the world.
      Returns:
      the world
    • getChangeSet

      public ChangeSet getChangeSet()
      Get the underlying ChangeSet.
      Returns:
      the change set
    • getBlockChangeLimit

      public int getBlockChangeLimit()
      Get the maximum number of blocks that can be changed. -1 will be returned if it the limit disabled.
      Returns:
      the limit (>= 0) or -1 for no limit
    • setBlockChangeLimit

      public void setBlockChangeLimit(int limit)
      Set the maximum number of blocks that can be changed.
      Parameters:
      limit - the limit (>= 0) or -1 for no limit
    • isQueueEnabled

      @Deprecated public boolean isQueueEnabled()
      Deprecated.
      Returns queue status.
      Returns:
      whether the queue is enabled
    • enableQueue

      @Deprecated public void enableQueue()
      Deprecated.
      There is no specific replacement, instead enable what you want specifically.
      Queue certain types of block for better reproduction of those blocks.
    • disableQueue

      @Deprecated public void disableQueue()
      Deprecated.
      Use disableBuffering() instead.
      Disable the queue. This will flush the session.
    • getMask

      public Mask getMask()
      Get the mask.
      Returns:
      mask, may be null
    • setMask

      public void setMask(Mask mask)
      Set a mask.
      Parameters:
      mask - mask or null
    • getSurvivalExtent

      public SurvivalModeExtent getSurvivalExtent()
      Returns:
      the survival simulation extent
    • setFastMode

      @Deprecated public void setFastMode(boolean enabled)
      Deprecated.
      Set whether fast mode is enabled.

      Fast mode may skip lighting checks or adjacent block notification.

      Parameters:
      enabled - true to enable
    • setSideEffectApplier

      public void setSideEffectApplier(SideEffectSet sideEffectSet)
      Set which block updates should occur.
      Parameters:
      sideEffectSet - side effects to enable
    • hasFastMode

      @Deprecated public boolean hasFastMode()
      Deprecated.
      Return fast mode status.

      Fast mode may skip lighting checks or adjacent block notification.

      Returns:
      true if enabled
    • getSideEffectApplier

      public SideEffectSet getSideEffectApplier()
    • getBlockBag

      public BlockBag getBlockBag()
      Get the BlockBag is used.
      Returns:
      a block bag or null
    • setBlockBag

      public void setBlockBag(BlockBag blockBag)
      Set a BlockBag to use.
      Parameters:
      blockBag - the block bag to set, or null to use none
    • popMissingBlocks

      public Map<BlockType,Integer> popMissingBlocks()
      Gets the list of missing blocks and clears the list for the next operation.
      Returns:
      a map of missing blocks
    • isBatchingChunks

      public boolean isBatchingChunks()
      Returns chunk batching status.
      Returns:
      whether chunk batching is enabled
    • setBatchingChunks

      public void setBatchingChunks(boolean batchingChunks)
      Enable or disable chunk batching. Disabling will flush the session.
      Parameters:
      batchingChunks - true to enable, false to disable
    • isBufferingEnabled

      public boolean isBufferingEnabled()
      Check if this session has any buffering extents enabled.
      Returns:
      true if any extents are buffering
    • disableBuffering

      public void disableBuffering()
      Disable all buffering extents.
      See Also:
    • isTickingWatchdog

      public boolean isTickingWatchdog()
      Check if this session will tick the watchdog.
      Returns:
      true if any watchdog extent is enabled
    • setTickingWatchdog

      public void setTickingWatchdog(boolean active)
      Set all watchdog extents to the given mode.
    • getBlockChangeCount

      public int getBlockChangeCount()
      Get the number of blocks changed, including repeated block changes.

      This number may not be accurate.

      Returns:
      the number of block changes
    • fullySupports3DBiomes

      public boolean fullySupports3DBiomes()
      Description copied from interface: OutputExtent
      Check if this extent fully supports 3D biomes.

      If false, the extent only visually reads biomes from y = 0. The biomes will still be set in 3D, but the client will only see the one at y = 0. It is up to the caller to determine if they want to set that biome instead, or simply warn the actor.

      Specified by:
      fullySupports3DBiomes in interface OutputExtent
      Returns:
      if the extent fully supports 3D biomes
    • getBiome

      public BiomeType getBiome(BlockVector3 position)
      Description copied from interface: InputExtent
      Get the biome at the given location.

      If there is no biome available, then the ocean biome should be returned.

      As implementation varies per Minecraft version, this may not exactly get this positions biome. On versions prior to 1.15, this will get the entire column. On later versions it will get the 4x4x4 cube's biome.

      Specified by:
      getBiome in interface InputExtent
      Parameters:
      position - the (x, y, z) location to check the biome at
      Returns:
      the biome at the location
    • setBiome

      public boolean setBiome(BlockVector3 position, BiomeType biome)
      Description copied from interface: OutputExtent
      Set the biome.

      As implementation varies per Minecraft version, this may set more than this position's biome. On versions prior to 1.15, this will set the entire column. On later versions it will set the 4x4x4 cube.

      Specified by:
      setBiome in interface OutputExtent
      Parameters:
      position - the (x, y, z) location to set the biome at
      biome - the biome to set to
      Returns:
      true if the biome was successfully set (return value may not be accurate)
    • getBlock

      public BlockState getBlock(BlockVector3 position)
      Description copied from interface: InputExtent
      Get a snapshot of the block at the given location.

      If the given position is out of the bounds of the extent, then the behavior is undefined (an air block could be returned). However, null should not be returned.

      The returned block is immutable and is a snapshot of the block at the time of call. It has no position attached to it, so it could be reused in Patterns and so on.

      Specified by:
      getBlock in interface InputExtent
      Parameters:
      position - position of the block
      Returns:
      the block
    • getFullBlock

      public BaseBlock getFullBlock(BlockVector3 position)
      Description copied from interface: InputExtent
      Get a immutable snapshot of the block at the given location.
      Specified by:
      getFullBlock in interface InputExtent
      Parameters:
      position - position of the block
      Returns:
      the block
    • getHighestTerrainBlock

      public int getHighestTerrainBlock(int x, int z, int minY, int maxY)
      Returns the highest solid 'terrain' block.
      Parameters:
      x - the X coordinate
      z - the Z coordinate
      minY - minimal height
      maxY - maximal height
      Returns:
      height of highest block found or 'minY'
    • getHighestTerrainBlock

      public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter)
      Returns the highest solid 'terrain' block.
      Parameters:
      x - the X coordinate
      z - the Z coordinate
      minY - minimal height
      maxY - maximal height
      filter - a mask of blocks to consider, or null to consider any solid (movement-blocking) block
      Returns:
      height of highest block found or 'minY'
    • setBlock

      public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, EditSession.Stage stage) throws WorldEditException
      Set a block, bypassing both history and block re-ordering.
      Parameters:
      position - the position to set the block at
      block - the block
      stage - the level
      Returns:
      whether the block changed
      Throws:
      WorldEditException - thrown on a set error
    • rawSetBlock

      public <B extends BlockStateHolder<B>> boolean rawSetBlock(BlockVector3 position, B block)
      Set a block, bypassing both history and block re-ordering.
      Parameters:
      position - the position to set the block at
      block - the block
      Returns:
      whether the block changed
    • smartSetBlock

      public <B extends BlockStateHolder<B>> boolean smartSetBlock(BlockVector3 position, B block)
      Set a block, bypassing history but still utilizing block re-ordering.
      Parameters:
      position - the position to set the block at
      block - the block
      Returns:
      whether the block changed
    • setBlock

      public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws MaxChangedBlocksException
      Description copied from interface: OutputExtent
      Change the block at the given location to the given block. The operation may not tie the given BlockStateHolder to the world, so future changes to the BlockStateHolder do not affect the world until this method is called again.

      The return value of this method indicates whether the change was probably successful. It may not be successful if, for example, the location is out of the bounds of the extent. It may be unsuccessful if the block passed is the same as the one in the world. However, the return value is only an estimation and it may be incorrect, but it could be used to count, for example, the approximate number of changes.

      Specified by:
      setBlock in interface OutputExtent
      Parameters:
      position - position of the block
      block - block to set
      Returns:
      true if the block was successfully set (return value may not be accurate)
      Throws:
      MaxChangedBlocksException
    • setBlock

      public boolean setBlock(BlockVector3 position, Pattern pattern) throws MaxChangedBlocksException
      Sets the block at a position, subject to both history and block re-ordering.
      Parameters:
      position - the position
      pattern - a pattern to use
      Returns:
      Whether the block changed -- not entirely dependable
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • createEntity

      @Nullable public Entity createEntity(Location location, BaseEntity entity)
      Description copied from interface: Extent
      Create an entity at the given location.
      Specified by:
      createEntity in interface Extent
      Parameters:
      location - the location
      entity - the entity
      Returns:
      a reference to the created entity, or null if the entity could not be created
    • undo

      public void undo(EditSession editSession)
      Restores all blocks to their initial state.
      Parameters:
      editSession - a new EditSession to perform the undo in
    • redo

      public void redo(EditSession editSession)
      Sets to new state.
      Parameters:
      editSession - a new EditSession to perform the redo in
    • isTrackingHistory

      public boolean isTrackingHistory()
      Gets whether this EditSession will track history.
      Returns:
      whether history is tracked
    • setTrackingHistory

      public void setTrackingHistory(boolean trackHistory)
      Sets whether this EditSession will track history.
      Parameters:
      trackHistory - whether to track history
    • size

      public int size()
      Get the number of changed blocks.
      Returns:
      the number of changes
    • getMinimumPoint

      public BlockVector3 getMinimumPoint()
      Description copied from interface: Extent
      Get the minimum point in the extent.

      If the extent is unbounded, then a large (negative) value may be returned.

      Specified by:
      getMinimumPoint in interface Extent
      Returns:
      the minimum point
    • getMaximumPoint

      public BlockVector3 getMaximumPoint()
      Description copied from interface: Extent
      Get the maximum point in the extent.

      If the extent is unbounded, then a large (positive) value may be returned.

      Specified by:
      getMaximumPoint in interface Extent
      Returns:
      the maximum point
    • getEntities

      public List<? extends Entity> getEntities(Region region)
      Description copied from interface: Extent
      Get a list of all entities within the given region.

      If the extent is not wholly loaded (i.e. a world being simulated in the game will not have every chunk loaded), then this list may not be incomplete.

      Specified by:
      getEntities in interface Extent
      Parameters:
      region - the region in which entities must be contained
      Returns:
      a list of entities
    • getEntities

      public List<? extends Entity> getEntities()
      Description copied from interface: Extent
      Get a list of all entities.

      If the extent is not wholly loaded (i.e. a world being simulated in the game will not have every chunk loaded), then this list may not be incomplete.

      Specified by:
      getEntities in interface Extent
      Returns:
      a list of entities
    • close

      public void close()
      Closing an EditSession flushes its buffers to the world, and performs other cleanup tasks.
      Specified by:
      close in interface AutoCloseable
    • flushSession

      @Deprecated public void flushSession()
      Deprecated.
      Replace with close() for proper cleanup behavior.
      Communicate to the EditSession that all block changes are complete, and that it should apply them to the world.
    • commit

      @Nullable public Operation commit()
      Description copied from interface: OutputExtent
      Return an Operation that should be called to tie up loose ends (such as to commit changes in a buffer).
      Specified by:
      commit in interface OutputExtent
      Returns:
      an operation or null if there is none to execute
    • countBlocks

      public int countBlocks(Region region, Set<BaseBlock> searchBlocks)
      Count the number of blocks of a list of types in a region.
      Parameters:
      region - the region
      searchBlocks - the list of blocks to search
      Returns:
      the number of blocks that matched the block
    • countBlocks

      public int countBlocks(Region region, Mask searchMask)
      Count the number of blocks of a list of types in a region.
      Parameters:
      region - the region
      searchMask - mask to match
      Returns:
      the number of blocks that matched the mask
    • fillXZ

      public <B extends BlockStateHolder<B>> int fillXZ(BlockVector3 origin, B block, double radius, int depth, boolean recursive) throws MaxChangedBlocksException
      Fills an area recursively in the X/Z directions.
      Parameters:
      origin - the location to start from
      block - the block to fill with
      radius - the radius of the spherical area to fill
      depth - the maximum depth, starting from the origin
      recursive - whether a breadth-first search should be performed
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • fillXZ

      public int fillXZ(BlockVector3 origin, Pattern pattern, double radius, int depth, boolean recursive) throws MaxChangedBlocksException
      Fills an area recursively in the X/Z directions.
      Parameters:
      origin - the origin to start the fill from
      pattern - the pattern to fill with
      radius - the radius of the spherical area to fill, with 0 as the smallest radius
      depth - the maximum depth, starting from the origin, with 1 as the smallest depth
      recursive - whether a breadth-first search should be performed
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • removeAbove

      public int removeAbove(BlockVector3 position, int apothem, int height) throws MaxChangedBlocksException
      Remove a cuboid above the given position with a given apothem and a given height.
      Parameters:
      position - base position
      apothem - an apothem of the cuboid (on the XZ plane), where the minimum is 1
      height - the height of the cuboid, where the minimum is 1
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • removeBelow

      public int removeBelow(BlockVector3 position, int apothem, int height) throws MaxChangedBlocksException
      Remove a cuboid below the given position with a given apothem and a given height.
      Parameters:
      position - base position
      apothem - an apothem of the cuboid (on the XZ plane), where the minimum is 1
      height - the height of the cuboid, where the minimum is 1
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • removeNear

      public int removeNear(BlockVector3 position, Mask mask, int apothem) throws MaxChangedBlocksException
      Remove blocks of a certain type nearby a given position.
      Parameters:
      position - center position of cuboid
      mask - the mask to match
      apothem - an apothem of the cuboid, where the minimum is 1
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • setBlocks

      public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException
      Sets all the blocks inside a region to a given block type.
      Parameters:
      region - the region
      block - the block
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • setBlocks

      public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException
      Sets all the blocks inside a region to a given pattern.
      Parameters:
      region - the region
      pattern - the pattern that provides the replacement block
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • replaceBlocks

      public <B extends BlockStateHolder<B>> int replaceBlocks(Region region, Set<BaseBlock> filter, B replacement) throws MaxChangedBlocksException
      Replaces all the blocks matching a given filter, within a given region, to a block returned by a given pattern.
      Parameters:
      region - the region to replace the blocks within
      filter - a list of block types to match, or null to use ExistingBlockMask
      replacement - the replacement block
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • replaceBlocks

      public int replaceBlocks(Region region, Set<BaseBlock> filter, Pattern pattern) throws MaxChangedBlocksException
      Replaces all the blocks matching a given filter, within a given region, to a block returned by a given pattern.
      Parameters:
      region - the region to replace the blocks within
      filter - a list of block types to match, or null to use ExistingBlockMask
      pattern - the pattern that provides the new blocks
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • replaceBlocks

      public int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException
      Replaces all the blocks matching a given mask, within a given region, to a block returned by a given pattern.
      Parameters:
      region - the region to replace the blocks within
      mask - the mask that blocks must match
      pattern - the pattern that provides the new blocks
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • center

      public int center(Region region, Pattern pattern) throws MaxChangedBlocksException
      Sets the blocks at the center of the given region to the given pattern. If the center sits between two blocks on a certain axis, then two blocks will be placed to mark the center.
      Parameters:
      region - the region to find the center of
      pattern - the replacement pattern
      Returns:
      the number of blocks placed
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeCuboidFaces

      @Deprecated public <B extends BlockStateHolder<B>> int makeCuboidFaces(Region region, B block) throws MaxChangedBlocksException
      Make the faces of the given region as if it was a CuboidRegion.
      Parameters:
      region - the region
      block - the block to place
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeCuboidFaces

      public int makeCuboidFaces(Region region, Pattern pattern) throws MaxChangedBlocksException
      Make the faces of the given region as if it was a CuboidRegion.
      Parameters:
      region - the region
      pattern - the pattern to place
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeFaces

      public int makeFaces(Region region, Pattern pattern) throws MaxChangedBlocksException
      Make the faces of the given region. The method by which the faces are found may be inefficient, because there may not be an efficient implementation supported for that specific shape.
      Parameters:
      region - the region
      pattern - the pattern to place
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeCuboidWalls

      public <B extends BlockStateHolder<B>> int makeCuboidWalls(Region region, B block) throws MaxChangedBlocksException
      Make the walls (all faces but those parallel to the X-Z plane) of the given region as if it was a CuboidRegion.
      Parameters:
      region - the region
      block - the block to place
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeCuboidWalls

      public int makeCuboidWalls(Region region, Pattern pattern) throws MaxChangedBlocksException
      Make the walls (all faces but those parallel to the X-Z plane) of the given region as if it was a CuboidRegion.
      Parameters:
      region - the region
      pattern - the pattern to place
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeWalls

      public int makeWalls(Region region, Pattern pattern) throws MaxChangedBlocksException
      Make the walls of the given region. The method by which the walls are found may be inefficient, because there may not be an efficient implementation supported for that specific shape.
      Parameters:
      region - the region
      pattern - the pattern to place
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • overlayCuboidBlocks

      @Deprecated public <B extends BlockStateHolder<B>> int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException
      Places a layer of blocks on top of ground blocks in the given region (as if it were a cuboid).
      Parameters:
      region - the region
      block - the placed block
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • overlayCuboidBlocks

      public int overlayCuboidBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException
      Places a layer of blocks on top of ground blocks in the given region (as if it were a cuboid).
      Parameters:
      region - the region
      pattern - the placed block pattern
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • naturalizeCuboidBlocks

      public int naturalizeCuboidBlocks(Region region) throws MaxChangedBlocksException
      Turns the first 3 layers into dirt/grass and the bottom layers into rock, like a natural Minecraft mountain.
      Parameters:
      region - the region to affect
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • stackCuboidRegion

      public int stackCuboidRegion(Region region, BlockVector3 dir, int count, boolean copyAir) throws MaxChangedBlocksException
      Stack a cuboid region. For compatibility, entities are copied by biomes are not. Use stackCuboidRegion(Region, BlockVector3, int, boolean, boolean, Mask) to fine tune.
      Parameters:
      region - the region to stack
      dir - the direction to stack
      count - the number of times to stack
      copyAir - true to also copy air blocks
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • stackCuboidRegion

      public int stackCuboidRegion(Region region, BlockVector3 offset, int count, boolean copyEntities, boolean copyBiomes, Mask mask) throws MaxChangedBlocksException
      Stack a cuboid region.
      Parameters:
      region - the region to stack
      offset - how far to move the contents each stack
      count - the number of times to stack
      copyEntities - true to copy entities
      copyBiomes - true to copy biomes
      mask - source mask for the operation (only matching blocks are copied)
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • stackRegionBlockUnits

      public int stackRegionBlockUnits(Region region, BlockVector3 offset, int count, boolean copyEntities, boolean copyBiomes, Mask mask) throws MaxChangedBlocksException, RegionOperationException
      Stack a region using block units.
      Parameters:
      region - the region to stack
      offset - how far to move the contents each stack in block units
      count - the number of times to stack
      copyEntities - true to copy entities
      copyBiomes - true to copy biomes
      mask - source mask for the operation (only matching blocks are copied)
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
      RegionOperationException - thrown if the region operation is invalid
    • moveRegion

      public int moveRegion(Region region, BlockVector3 offset, int multiplier, boolean copyAir, Pattern replacement) throws MaxChangedBlocksException
      Move the blocks in a region a certain direction.
      Parameters:
      region - the region to move
      offset - the offset
      multiplier - the number to multiply the offset by
      copyAir - true to copy air blocks
      replacement - the replacement pattern to fill in after moving, or null to use air
      Returns:
      number of blocks moved
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • moveRegion

      public int moveRegion(Region region, BlockVector3 offset, int multiplier, boolean moveEntities, boolean copyBiomes, Mask mask, Pattern replacement) throws MaxChangedBlocksException
      Move the blocks in a region a certain direction.
      Parameters:
      region - the region to move
      offset - the offset
      multiplier - the number to multiply the offset by
      moveEntities - true to move entities
      copyBiomes - true to copy biomes (source biome is unchanged)
      mask - source mask for the operation (only matching blocks are moved)
      replacement - the replacement pattern to fill in after moving, or null to use air
      Returns:
      number of blocks moved
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
      IllegalArgumentException - thrown if the region is not a flat region, but copyBiomes is true
    • moveCuboidRegion

      public int moveCuboidRegion(Region region, BlockVector3 dir, int distance, boolean copyAir, Pattern replacement) throws MaxChangedBlocksException
      Move the blocks in a region a certain direction.
      Parameters:
      region - the region to move
      dir - the direction
      distance - the distance to move
      copyAir - true to copy air blocks
      replacement - the replacement pattern to fill in after moving, or null to use air
      Returns:
      number of blocks moved
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • drainArea

      public int drainArea(BlockVector3 origin, double radius) throws MaxChangedBlocksException
      Drain nearby pools of water or lava.
      Parameters:
      origin - the origin to drain from, which will search a 3x3 area
      radius - the radius of the removal, where a value should be 0 or greater
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • drainArea

      public int drainArea(BlockVector3 origin, double radius, boolean waterlogged) throws MaxChangedBlocksException
      Drain nearby pools of water or lava, optionally removed waterlogged states from blocks.
      Parameters:
      origin - the origin to drain from, which will search a 3x3 area
      radius - the radius of the removal, where a value should be 0 or greater
      waterlogged - true to make waterlogged blocks non-waterlogged as well
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • fixLiquid

      public int fixLiquid(BlockVector3 origin, double radius, BlockType fluid) throws MaxChangedBlocksException
      Fix liquids so that they turn into stationary blocks and extend outward.
      Parameters:
      origin - the original position
      radius - the radius to fix
      fluid - the type of the fluid
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeCylinder

      public int makeCylinder(BlockVector3 pos, Pattern block, double radius, int height, boolean filled) throws MaxChangedBlocksException
      Makes a cylinder.
      Parameters:
      pos - Center of the cylinder
      block - The block pattern to use
      radius - The cylinder's radius
      height - The cylinder's up/down extent. If negative, extend downward.
      filled - If false, only a shell will be generated.
      Returns:
      number of blocks changed
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeCylinder

      public int makeCylinder(BlockVector3 pos, Pattern block, double radiusX, double radiusZ, int height, boolean filled) throws MaxChangedBlocksException
      Makes a cylinder.
      Parameters:
      pos - Center of the cylinder
      block - The block pattern to use
      radiusX - The cylinder's largest north/south extent
      radiusZ - The cylinder's largest east/west extent
      height - The cylinder's up/down extent. If negative, extend downward.
      filled - If false, only a shell will be generated.
      Returns:
      number of blocks changed
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeCone

      public int makeCone(BlockVector3 pos, Pattern block, double radiusX, double radiusZ, int height, boolean filled, double thickness) throws MaxChangedBlocksException
      Makes a cone.
      Parameters:
      pos - Center of the cone
      block - The block pattern to use
      radiusX - The cone's largest north/south extent
      radiusZ - The cone's largest east/west extent
      height - The cone's up/down extent. If negative, extend downward.
      filled - If false, only a shell will be generated.
      thickness - The cone's wall thickness, if it's hollow.
      Returns:
      number of blocks changed
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeSphere

      public int makeSphere(BlockVector3 pos, Pattern block, double radius, boolean filled) throws MaxChangedBlocksException
      Makes a sphere.
      Parameters:
      pos - Center of the sphere or ellipsoid
      block - The block pattern to use
      radius - The sphere's radius
      filled - If false, only a shell will be generated.
      Returns:
      number of blocks changed
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeSphere

      public int makeSphere(BlockVector3 pos, Pattern block, double radiusX, double radiusY, double radiusZ, boolean filled) throws MaxChangedBlocksException
      Makes a sphere or ellipsoid.
      Parameters:
      pos - Center of the sphere or ellipsoid
      block - The block pattern to use
      radiusX - The sphere/ellipsoid's largest north/south extent
      radiusY - The sphere/ellipsoid's largest up/down extent
      radiusZ - The sphere/ellipsoid's largest east/west extent
      filled - If false, only a shell will be generated.
      Returns:
      number of blocks changed
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makePyramid

      public int makePyramid(BlockVector3 position, Pattern block, int size, boolean filled) throws MaxChangedBlocksException
      Makes a pyramid.
      Parameters:
      position - a position
      block - a block
      size - size of pyramid
      filled - true if filled
      Returns:
      number of blocks changed
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • thaw

      @Deprecated public int thaw(BlockVector3 position, double radius) throws MaxChangedBlocksException
      Thaw blocks in a radius.
      Parameters:
      position - the position
      radius - the radius
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • thaw

      public int thaw(BlockVector3 position, double radius, int height) throws MaxChangedBlocksException
      Thaw blocks in a cylinder.
      Parameters:
      position - the position
      radius - the radius
      height - the height (upwards and downwards)
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • simulateSnow

      @Deprecated public int simulateSnow(BlockVector3 position, double radius) throws MaxChangedBlocksException
      Make snow in a radius.
      Parameters:
      position - a position
      radius - a radius
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • simulateSnow

      public int simulateSnow(BlockVector3 position, double radius, int height) throws MaxChangedBlocksException
      Make snow in a cylinder.
      Parameters:
      position - a position
      radius - a radius
      height - the height (upwards and downwards)
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • simulateSnow

      public int simulateSnow(FlatRegion region, boolean stack) throws MaxChangedBlocksException
      Make snow in a region.
      Parameters:
      region - the region to simulate snow in
      stack - whether it should stack existing snow
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • green

      @Deprecated public int green(BlockVector3 position, double radius, boolean onlyNormalDirt) throws MaxChangedBlocksException
      Make dirt green.
      Parameters:
      position - a position
      radius - a radius
      onlyNormalDirt - only affect normal dirt (all default properties)
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • green

      public int green(BlockVector3 position, double radius, int height, boolean onlyNormalDirt) throws MaxChangedBlocksException
      Make dirt green in a cylinder.
      Parameters:
      position - the position
      radius - the radius
      height - the height
      onlyNormalDirt - only affect normal dirt (all default properties)
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makePumpkinPatches

      public int makePumpkinPatches(BlockVector3 position, int apothem) throws MaxChangedBlocksException
      Makes pumpkin patches randomly in an area around the given position.
      Parameters:
      position - the base position
      apothem - the apothem of the (square) area
      Returns:
      number of patches created
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeForest

      public int makeForest(BlockVector3 basePosition, int size, double density, TreeGenerator.TreeType treeType) throws MaxChangedBlocksException
      Makes a forest.
      Parameters:
      basePosition - a position
      size - a size
      density - between 0 and 1, inclusive
      treeType - the tree type
      Returns:
      number of trees created
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeForest

      public int makeForest(Region region, double density, TreeGenerator.TreeType treeType) throws MaxChangedBlocksException
      Makes a forest.
      Parameters:
      region - the region to generate trees in
      density - between 0 and 1, inclusive
      treeType - the tree type
      Returns:
      number of trees created
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • getBlockDistribution

      public List<Countable<BlockState>> getBlockDistribution(Region region, boolean separateStates)
      Get the block distribution inside a region.
      Parameters:
      region - a region
      Returns:
      the results
    • makeShape

      public int makeShape(Region region, Vector3 zero, Vector3 unit, Pattern pattern, String expressionString, boolean hollow) throws ExpressionException, MaxChangedBlocksException
      Generate a shape for the given expression.
      Parameters:
      region - the region to generate the shape in
      zero - the coordinate origin for x/y/z variables
      unit - the scale of the x/y/z/ variables
      pattern - the default material to make the shape from
      expressionString - the expression defining the shape
      hollow - whether the shape should be hollow
      Returns:
      number of blocks changed
      Throws:
      ExpressionException - if there is a problem with the expression
      MaxChangedBlocksException - if the maximum block change limit is exceeded
    • makeShape

      public int makeShape(Region region, Vector3 zero, Vector3 unit, Pattern pattern, String expressionString, boolean hollow, int timeout) throws ExpressionException, MaxChangedBlocksException
      Generate a shape for the given expression.
      Parameters:
      region - the region to generate the shape in
      zero - the coordinate origin for x/y/z variables
      unit - the scale of the x/y/z/ variables
      pattern - the default material to make the shape from
      expressionString - the expression defining the shape
      hollow - whether the shape should be hollow
      timeout - the time, in milliseconds, to wait for each expression evaluation before halting it. -1 to disable
      Returns:
      number of blocks changed
      Throws:
      ExpressionException - if there is a problem with the expression
      MaxChangedBlocksException - if the maximum block change limit is exceeded
    • makeShape

      public int makeShape(Region region, Vector3 zero, Vector3 unit, Pattern pattern, Expression expression, boolean hollow, int timeout) throws ExpressionException, MaxChangedBlocksException
      Internal version of makeShape(Region, Vector3, Vector3, Pattern, String, boolean, int).

      The Expression class is subject to change. Expressions should be provided via the string overload.

      Throws:
      ExpressionException
      MaxChangedBlocksException
    • deformRegion

      public int deformRegion(Region region, Vector3 zero, Vector3 unit, String expressionString) throws ExpressionException, MaxChangedBlocksException
      Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled) to an expression, and then sets the block to the block given by the resulting values of the variables, if they have changed.
      Parameters:
      region - the region to deform
      zero - the origin of the coordinate system
      unit - the scale of the coordinate system
      expressionString - the expression to evaluate for each block
      Returns:
      number of blocks changed
      Throws:
      ExpressionException - thrown on invalid expression input
      MaxChangedBlocksException - thrown if too many blocks are changed
    • deformRegion

      public int deformRegion(Region region, Vector3 zero, Vector3 unit, String expressionString, int timeout) throws ExpressionException, MaxChangedBlocksException
      Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled) to an expression, and then sets the block to the block given by the resulting values of the variables, if they have changed.
      Parameters:
      region - the region to deform
      zero - the origin of the coordinate system
      unit - the scale of the coordinate system
      expressionString - the expression to evaluate for each block
      timeout - maximum time for the expression to evaluate for each block. -1 for unlimited.
      Returns:
      number of blocks changed
      Throws:
      ExpressionException - thrown on invalid expression input
      MaxChangedBlocksException - thrown if too many blocks are changed
    • deformRegion

      public int deformRegion(Region region, Vector3 zero, Vector3 unit, Expression expression, int timeout) throws ExpressionException, MaxChangedBlocksException
      Internal version of deformRegion(Region, Vector3, Vector3, String, int).

      The Expression class is subject to change. Expressions should be provided via the string overload.

      Throws:
      ExpressionException
      MaxChangedBlocksException
    • hollowOutRegion

      public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws MaxChangedBlocksException
      Hollows out the region (Semi-well-defined for non-cuboid selections).
      Parameters:
      region - the region to hollow out.
      thickness - the thickness of the shell to leave (manhattan distance)
      pattern - The block pattern to use
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • drawLine

      public int drawLine(Pattern pattern, BlockVector3 pos1, BlockVector3 pos2, double radius, boolean filled) throws MaxChangedBlocksException
      Draws a line (out of blocks) between two vectors.
      Parameters:
      pattern - The block pattern used to draw the line.
      pos1 - One of the points that define the line.
      pos2 - The other point that defines the line.
      radius - The radius (thickness) of the line.
      filled - If false, only a shell will be generated.
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
      See Also:
    • drawLine

      public int drawLine(Pattern pattern, List<BlockVector3> vectors, double radius, boolean filled) throws MaxChangedBlocksException
      Draws a line (out of blocks) between two or more vectors.
      Parameters:
      pattern - The block pattern used to draw the line.
      vectors - the list of vectors to draw the line between
      radius - The radius (thickness) of the line.
      filled - If false, only a shell will be generated.
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • drawSpline

      public int drawSpline(Pattern pattern, List<BlockVector3> nodevectors, double tension, double bias, double continuity, double quality, double radius, boolean filled) throws MaxChangedBlocksException
      Draws a spline (out of blocks) between specified vectors.
      Parameters:
      pattern - The block pattern used to draw the spline.
      nodevectors - The list of vectors to draw through.
      tension - The tension of every node.
      bias - The bias of every node.
      continuity - The continuity of every node.
      quality - The quality of the spline. Must be greater than 0.
      radius - The radius (thickness) of the spline.
      filled - If false, only a shell will be generated.
      Returns:
      number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • makeBiomeShape

      public int makeBiomeShape(Region region, Vector3 zero, Vector3 unit, BiomeType biomeType, String expressionString, boolean hollow) throws ExpressionException
      Throws:
      ExpressionException
    • makeBiomeShape

      public int makeBiomeShape(Region region, Vector3 zero, Vector3 unit, BiomeType biomeType, String expressionString, boolean hollow, int timeout) throws ExpressionException
      Throws:
      ExpressionException
    • morph

      public int morph(BlockVector3 position, double brushSize, int minErodeFaces, int numErodeIterations, int minDilateFaces, int numDilateIterations) throws MaxChangedBlocksException
      Throws:
      MaxChangedBlocksException