Class EditSession

All Implemented Interfaces:
Extent, InputExtent, OutputExtent, AutoCloseable

public class EditSession extends PassthroughExtent implements 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

    • getLimit

      public FaweLimit getLimit()
      The limit for this specific edit (blocks etc).
      Returns:
      The limit
    • resetLimit

      public void resetLimit()
    • getLimitUsed

      public FaweLimit getLimitUsed()
      Returns a new limit representing how much of this edit's limit has been used so far.
      Returns:
      Limit remaining
    • getLimitLeft

      public FaweLimit getLimitLeft()
      Returns the remaining limits.
      Returns:
      remaining limits
    • getRegionExtent

      public FaweRegionExtent getRegionExtent()
      Returns the RegionExtent that will restrict an edit, or null.
      Returns:
      FaweRegionExtent (may be null)
    • getBypassAll

      public Extent getBypassAll()
    • getBypassHistory

      public Extent getBypassHistory()
    • setExtent

      public void setExtent(AbstractDelegateExtent extent)
    • getActor

      @Nullable public Actor getActor()
      Get the Actor or null.
      Returns:
      the actor
    • enableStandardMode

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

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

      public EditSession.ReorderMode getReorderMode()
      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
    • setRawChangeSet

      public void setRawChangeSet(@Nullable AbstractChangeSet set)
      Set the ChangeSet without hooking into any recording mechanism or triggering any actions.
      Used internally to set the ChangeSet during completion to record custom changes which aren't normally recorded
      Parameters:
      set - The ChangeSet to set
    • getBlockChangeLimit

      @Deprecated public long getBlockChangeLimit()
      Deprecated.
      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
      See Also:
    • setBlockChangeLimit

      public void setBlockChangeLimit(long 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.
      Use getReorderMode() with MULTI_STAGE instead.
      Returns queue status.
      Specified by:
      isQueueEnabled in interface Extent
      Overrides:
      isQueueEnabled in class PassthroughExtent
      Returns:
      whether the queue is enabled
    • enableQueue

      @Deprecated public void enableQueue()
      Deprecated.
      Use setReorderMode(ReorderMode) with MULTI_STAGE instead.
      Queue certain types of block for better reproduction of those blocks. Uses EditSession.ReorderMode.MULTI_STAGE.
      Specified by:
      enableQueue in interface Extent
      Overrides:
      enableQueue in class PassthroughExtent
    • disableQueue

      @Deprecated public void disableQueue()
      Deprecated.
      Disable the queue. This will close the queue.
      Specified by:
      disableQueue in interface Extent
      Overrides:
      disableQueue in class PassthroughExtent
    • getMask

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

      public Mask getSourceMask()
      Get the source mask.
      Returns:
      source mask, may be null
    • getAllowedRegions

      @Nullable public Region[] getAllowedRegions()
    • addTransform

      public void addTransform(ResettableExtent transform)
    • getTransform

      @Nullable public ResettableExtent getTransform()
    • setSourceMask

      public void setSourceMask(Mask mask)
      Set a mask.
      Parameters:
      mask - mask or null
    • addSourceMask

      public void addSourceMask(Mask mask)
    • setMask

      public void setMask(@Nullable Mask mask)
      Set a mask. Combines with any existing masks, set null to clear existing masks.
      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
    • getSideEffectApplier

      public SideEffectSet getSideEffectApplier()
    • disableHistory

      @Deprecated public void disableHistory(boolean disableHistory)
      Deprecated.
      Disable history (or re-enable)
      Parameters:
      disableHistory - whether to enable or disable.
    • hasFastMode

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

      Fast mode may skip lighting checks or adjacent block notification.

      Returns:
      true if enabled
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class AbstractDelegateExtent
    • 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
    • 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
      Overrides:
      fullySupports3DBiomes in class AbstractDelegateExtent
      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
      Overrides:
      getBiome in class AbstractDelegateExtent
      Parameters:
      position - the (x, y, z) location to check the biome at
      Returns:
      the biome at the location
      See Also:
    • 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
      Overrides:
      setBiome in class PassthroughExtent
      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)
    • setBiome

      public boolean setBiome(int x, int y, int z, BiomeType biome)
      Specified by:
      setBiome in interface OutputExtent
      Overrides:
      setBiome in class AbstractDelegateExtent
    • getHighestTerrainBlock

      public int getHighestTerrainBlock(int x, int z, int minY, int maxY)
      Returns the highest solid 'terrain' block.
      Specified by:
      getHighestTerrainBlock in interface Extent
      Overrides:
      getHighestTerrainBlock in class PassthroughExtent
      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.
      Specified by:
      getHighestTerrainBlock in interface Extent
      Overrides:
      getHighestTerrainBlock in class PassthroughExtent
      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'
    • getBlockType

      public BlockType getBlockType(int x, int y, int z)
    • setBlock

      @Deprecated public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, EditSession.Stage stage) throws WorldEditException
      Deprecated.
      Deprecated as may perform differently in FAWE.
      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

      @Deprecated public <B extends BlockStateHolder<B>> boolean rawSetBlock(BlockVector3 position, B block)
      Deprecated.
      Deprecated as may perform differently in FAWE.
      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

      @Deprecated public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws MaxChangedBlocksException
      Deprecated.
      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
      Overrides:
      setBlock in class PassthroughExtent
      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 <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block)
      Specified by:
      setBlock in interface OutputExtent
      Overrides:
      setBlock in class AbstractDelegateExtent
    • setBlock

      public boolean setBlock(int x, int y, int z, Pattern pattern)
      Sets the block at a position, subject to both history and block re-ordering.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      pattern - a pattern to use
      Returns:
      Whether the block changed -- not entirely dependable
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • 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
    • setBlocks

      public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException
      Description copied from interface: Extent
      Sets all the blocks inside a region to a given block type.
      Specified by:
      setBlocks in interface Extent
      Overrides:
      setBlocks in class PassthroughExtent
      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
      Description copied from interface: Extent
      Sets all the blocks inside a region to a given pattern.
      Specified by:
      setBlocks in interface Extent
      Overrides:
      setBlocks in class PassthroughExtent
      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
    • setBlocks

      public int setBlocks(Set<BlockVector3> vset, Pattern pattern)
      Specified by:
      setBlocks in interface Extent
      Overrides:
      setBlocks in class PassthroughExtent
    • undo

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

      public void setBlocks(ChangeSet changeSet, ChangeSetExecutor.Type type)
    • redo

      public void redo(EditSession editSession)
      Sets to new state.
      Parameters:
      editSession - a new EditSession to perform the redo in
    • 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
      Overrides:
      getMinimumPoint in class AbstractDelegateExtent
      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
      Overrides:
      getMaximumPoint in class AbstractDelegateExtent
      Returns:
      the maximum point
    • setSize

      public void setSize(int size)
    • 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.
    • flushQueue

      public void flushQueue()
      Finish off the queue.
    • fall

      public <B extends BlockStateHolder<B>> int fall(Region region, boolean fullHeight, B replace)
    • replaceBlocks

      public <B extends BlockStateHolder<B>> int replaceBlocks(Region region, Set<BaseBlock> filter, B replacement) throws MaxChangedBlocksException
      Description copied from interface: Extent
      Replaces all the blocks matching a given filter, within a given region, to a block returned by a given pattern.
      Specified by:
      replaceBlocks in interface Extent
      Overrides:
      replaceBlocks in class PassthroughExtent
      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
      Description copied from interface: Extent
      Replaces all the blocks matching a given filter, within a given region, to a block returned by a given pattern.
      Specified by:
      replaceBlocks in interface Extent
      Overrides:
      replaceBlocks in class PassthroughExtent
      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
      Description copied from interface: Extent
      Replaces all the blocks matching a given mask, within a given region, to a block returned by a given pattern.
      Specified by:
      replaceBlocks in interface Extent
      Overrides:
      replaceBlocks in class PassthroughExtent
      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
    • fillDirection

      public int fillDirection(BlockVector3 origin, Pattern pattern, double radius, int depth, BlockVector3 direction) throws MaxChangedBlocksException
      Fills an area recursively in the X/Z directions.
      Parameters:
      origin - the location to start from
      pattern - the block to fill with
      radius - the radius of the spherical area to fill
      depth - the maximum depth, starting from the origin
      direction - the direction to fill
      Returns:
      the number of blocks affected
      Throws:
      MaxChangedBlocksException - thrown if too many blocks are changed
    • 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
    • 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.
      Specified by:
      center in interface Extent
      Overrides:
      center in class PassthroughExtent
      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. Is directional.
      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, boolean moveEntities, boolean copyBiomes, Pattern replacement) throws MaxChangedBlocksException
      Move the blocks in a region a certain direction.
      Parameters:
      region - the region to move
      offset - the offset. Is directional.
      multiplier - the number to multiply the offset by
      copyAir - true to copy air blocks
      moveEntities - true to move entities
      copyBiomes - true to copy biomes
      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. Is directional.
      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
    • drainArea

      public int drainArea(BlockVector3 origin, double radius, boolean waterlogged, boolean plants) 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
      plants - true to remove underwater plants
      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
    • makeHollowCylinder

      public int makeHollowCylinder(BlockVector3 pos, Pattern block, double radiusX, double radiusZ, int height, double thickness) throws MaxChangedBlocksException
      Throws:
      MaxChangedBlocksException
    • makeCylinder

      public int makeCylinder(BlockVector3 pos, Pattern block, double radiusX, double radiusZ, int height, double thickness, boolean filled) throws MaxChangedBlocksException
      Throws:
      MaxChangedBlocksException
    • 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
    • moveRegion

      public int moveRegion(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
    • makeCircle

      public int makeCircle(BlockVector3 pos, Pattern block, double radiusX, double radiusY, double radiusZ, boolean filled, Vector3 normal) throws MaxChangedBlocksException
      Throws:
      MaxChangedBlocksException
    • 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
    • makePumpkinPatches

      public int makePumpkinPatches(BlockVector3 position, int apothem, double density) throws MaxChangedBlocksException
      Throws:
      MaxChangedBlocksException
    • 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
    • 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, Mask mask)
      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
      Throws:
      MaxChangedBlocksException
    • drawLine

      public int drawLine(Pattern pattern, BlockVector3 pos1, BlockVector3 pos2, double radius, boolean filled, boolean flat) 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
    • getStretched

      public static Set<BlockVector3> getStretched(Set<BlockVector3> vset, double radius)
    • getOutline

      public Set<BlockVector3> getOutline(Set<BlockVector3> vset)
    • getHollowed

      public Set<BlockVector3> getHollowed(Set<BlockVector3> vset)
    • 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
    • regenerate

      public boolean regenerate(Region region)
    • regenerate

      public boolean regenerate(Region region, EditSession session)
    • regenerate

      public boolean regenerate(Region region, BiomeType biome, Long seed)
    • 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
      Overrides:
      getEntities in class AbstractDelegateExtent
      Returns:
      a list of entities
    • 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
      Overrides:
      getEntities in class AbstractDelegateExtent
      Parameters:
      region - the region in which entities must be contained
      Returns:
      a list of entities
    • createEntity

      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
      Overrides:
      createEntity in class AbstractDelegateExtent
      Parameters:
      location - the location
      entity - the entity
      Returns:
      a reference to the created entity, or null if the entity could not be created
    • createEntity

      public Entity createEntity(Location location, BaseEntity entity, UUID uuid)
      Description copied from interface: Extent
      Create an entity at the given location, forcing a UUID onto the entity Only use if you are aware of the consequences of forcing a UUID to an entity.
      Specified by:
      createEntity in interface Extent
      Overrides:
      createEntity in class AbstractDelegateExtent
      Parameters:
      location - the location
      entity - the entity
      uuid - UUID to force the entity to have
      Returns:
      a reference to the created entity, or null if the entity could not be created
    • removeEntity

      public void removeEntity(int x, int y, int z, UUID uuid)
      Description copied from interface: Extent
      Create an entity at the given location.
      Specified by:
      removeEntity in interface Extent
      Overrides:
      removeEntity in class AbstractDelegateExtent
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      uuid - the unique identifier of the entity
    • generate

      public void generate(Region region, GenBase gen) throws WorldEditException
      Specified by:
      generate in interface Extent
      Overrides:
      generate in class PassthroughExtent
      Throws:
      WorldEditException
    • addSchems

      public void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity, boolean rotate) throws WorldEditException
      Specified by:
      addSchems in interface Extent
      Overrides:
      addSchems in class PassthroughExtent
      Throws:
      WorldEditException
    • addOre

      public void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException
      Specified by:
      addOre in interface Extent
      Overrides:
      addOre in class PassthroughExtent
      Throws:
      WorldEditException
    • lazyCopy

      public Clipboard lazyCopy(Region region)
      Description copied from interface: Extent
      Lazily copy a region
      Specified by:
      lazyCopy in interface Extent
      Overrides:
      lazyCopy in class PassthroughExtent
      Parameters:
      region -
      Returns:
    • makeBlob

      public int makeBlob(BlockVector3 position, Pattern pattern, double size, double frequency, double amplitude, Vector3 radius, double sphericity)
      Makes a distorted sphere.
      Parameters:
      position - Center of blob
      pattern - pattern to use
      size - overall size of the blob
      frequency - distortion amount (0 to 1)
      amplitude - distortion amplitude (0 to 1)
      radius - radii to multiply x/y/z by
      sphericity - how spherical to make the blob. 1 = very spherical, 0 = not
      Returns:
      changes