Class BlockArrayClipboard

java.lang.Object
com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard
All Implemented Interfaces:
Clipboard, Extent, InputExtent, OutputExtent, Closeable, Flushable, AutoCloseable, Iterable<BlockVector3>

public class BlockArrayClipboard extends Object implements Clipboard
Stores block data as a multi-dimensional array of BlockStates and other data as lists or maps. Clipboard may need to be flushed before use if using clipboard-on-disk.
  • Constructor Details

  • Method Details

    • getRegion

      public Region getRegion()
      Description copied from interface: Clipboard
      Get the bounding region of this extent.

      Implementations should return a copy of the region.

      Specified by:
      getRegion in interface Clipboard
      Returns:
      the bounding region
    • getOrigin

      public BlockVector3 getOrigin()
      Description copied from interface: Clipboard
      Get the origin point from which the copy was made from.
      Specified by:
      getOrigin in interface Clipboard
      Returns:
      the origin
    • setOrigin

      public void setOrigin(BlockVector3 origin)
      Description copied from interface: Clipboard
      Set the origin point from which the copy was made from.
      Specified by:
      setOrigin in interface Clipboard
      Parameters:
      origin - the origin
    • 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
    • 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 an immutable snapshot of the block at the given location.
      Specified by:
      getFullBlock in interface InputExtent
      Parameters:
      position - position of the block
      Returns:
      the block
    • setBlock

      public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException
      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:
      WorldEditException - thrown on an error
    • setTile

      public boolean setTile(int x, int y, int z, CompoundTag tag)
      Specified by:
      setTile in interface OutputExtent
    • setTile

      public boolean setTile(BlockVector3 position, CompoundTag tag)
    • setBlock

      public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException
      Specified by:
      setBlock in interface OutputExtent
      Throws:
      WorldEditException
    • hasBiomes

      public boolean hasBiomes()
      Description copied from interface: Clipboard
      Returns true if the clipboard has biome data. This can be checked since InputExtent.getBiome(BlockVector2) strongly suggests returning BiomeTypes.OCEAN instead of null if biomes aren't present. However, it might not be desired to set areas to ocean if the clipboard is defaulting to ocean, instead of having biomes explicitly set.
      Specified by:
      hasBiomes in interface Clipboard
      Returns:
      true if the clipboard has biome data set
    • 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
      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
      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
    • 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
    • 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
    • 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
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      uuid - the unique identifier of the entity
    • getBlock

      public BlockState getBlock(int x, int y, int z)
      Specified by:
      getBlock in interface InputExtent
    • getFullBlock

      public BaseBlock getFullBlock(int x, int y, int z)
      Specified by:
      getFullBlock in interface InputExtent
    • getBiomeType

      public BiomeType getBiomeType(int x, int y, int z)
      Specified by:
      getBiomeType in interface InputExtent
    • iterator

      @Nonnull public Iterator<BlockVector3> iterator()
      Specified by:
      iterator in interface Clipboard
      Specified by:
      iterator in interface Iterable<BlockVector3>
    • iterator2d

      public Iterator<BlockVector2> iterator2d()
      Specified by:
      iterator2d in interface Clipboard
    • iterator

      public Iterator<BlockVector3> iterator(Order order)
      Specified by:
      iterator in interface Clipboard
    • getDimensions

      public BlockVector3 getDimensions()
      Description copied from interface: Clipboard
      Get the dimensions of the copy, which is at minimum (1, 1, 1).
      Specified by:
      getDimensions in interface Clipboard
      Returns:
      the dimensions
    • removeEntity

      public void removeEntity(Entity entity)
      Description copied from interface: Clipboard
      Remove entity from clipboard.
      Specified by:
      removeEntity in interface Clipboard
    • getParent

      public Clipboard getParent()
    • close

      public void close()
      Description copied from interface: Clipboard
      Close the clipboard. May not allow further reading of the clipboard if saved on disk.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Clipboard
      Specified by:
      close in interface Closeable
    • flush

      public void flush()
      Description copied from interface: Clipboard
      Flush the clipboard if appropriate. Only does something if using clipboard-on-disk. Blocking method and ensures all data is saved to disk for any further operation with the clipboard.
      Specified by:
      flush in interface Clipboard
      Specified by:
      flush in interface Flushable