Interface Area

All Superinterfaces:
Iterable<BlockVec>
All Known Subinterfaces:
Area.Cuboid, Area.Line, Area.Single, Area.Sphere

@Experimental public sealed interface Area extends Iterable<BlockVec> permits Area.Single, Area.Line, Area.Cuboid, Area.Sphere
Represents a collection of aligned block coordinates in a 3D space.

If switched over, consider a fallback to the iterator as more implementations may be added in the future.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    An area containing all blocks inside an inclusive cuboid.
    static interface 
    An area containing blocks traced by a line between two block coordinates.
    static interface 
    An area containing exactly one block.
    static interface 
    An area containing all blocks within a radius of a center block.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the number of blocks contained in this area.
    default Area.Cuboid
    Returns the bounding box of this area.
    box(Point center, Point size)
    Creates a cuboid centered around center with the given size on each axis.
    boolean
    contains(int x, int y, int z)
    Checks whether this area contains the given block coordinate.
    default boolean
    contains(Point point)
    Checks whether this area contains the block coordinate of point.
    cube(Point center, int size)
    Creates a cuboid centered around center with the same size on each axis.
    cuboid(Point min, Point max)
    Creates a cuboid area from two corners.
    static Area.Line
    line(Point start, Point end)
    Creates a line area between two block coordinates.
    default Area
    offset(int x, int y, int z)
    Returns this area translated by the given block offset.
    default Area
    offset(Point offset)
    Returns this area translated by the block coordinates of offset.
    section(int sectionX, int sectionY, int sectionZ)
    Creates a cuboid containing all blocks in the given section.
    single(int x, int y, int z)
    Creates an area containing a single block.
    single(Point point)
    Creates an area containing a single block.
    sphere(Point center, int radius)
    Creates a sphere area from a center and non-negative radius.
    Splits this area into multiple cuboids which do not cross section boundaries.

    Methods inherited from interface Iterable

    forEach, iterator, spliterator
  • Method Details

    • offset

      default Area offset(int x, int y, int z)
      Returns this area translated by the given block offset.
      Parameters:
      x - the X block offset
      y - the Y block offset
      z - the Z block offset
      Returns:
      the translated area
    • offset

      default Area offset(Point offset)
      Returns this area translated by the block coordinates of offset.
      Parameters:
      offset - the offset point
      Returns:
      the translated area
    • bound

      default Area.Cuboid bound()
      Returns the bounding box of this area.
      Returns:
      a cuboid representing the bounding box with the lowest and highest points
    • contains

      boolean contains(int x, int y, int z)
      Checks whether this area contains the given block coordinate.
      Parameters:
      x - the block X coordinate
      y - the block Y coordinate
      z - the block Z coordinate
      Returns:
      true if the block coordinate is contained in this area
    • contains

      default boolean contains(Point point)
      Checks whether this area contains the block coordinate of point.
      Parameters:
      point - the point to convert to a block coordinate
      Returns:
      true if the block coordinate is contained in this area
    • blockCount

      long blockCount()
      Returns the number of blocks contained in this area.

      Counting a sphere requires scanning its bounding box and may be expensive for large radii.

      Returns:
      the contained block count
    • split

      List<Area.Cuboid> split()
      Splits this area into multiple cuboids which do not cross section boundaries.

      Single sections may have multiple cuboids if the section-local portion is not a perfect cuboid.

      Returns:
      list of sub-cuboids covering exactly this area
    • single

      static Area.Single single(Point point)
      Creates an area containing a single block.
      Parameters:
      point - the point to convert to a block coordinate
      Returns:
      a single-block area
    • single

      static Area.Single single(int x, int y, int z)
      Creates an area containing a single block.
      Parameters:
      x - the block X coordinate
      y - the block Y coordinate
      z - the block Z coordinate
      Returns:
      a single-block area
    • line

      static Area.Line line(Point start, Point end)
      Creates a line area between two block coordinates.
      Parameters:
      start - the start point to convert to a block coordinate
      end - the end point to convert to a block coordinate
      Returns:
      a line area
    • cuboid

      static Area.Cuboid cuboid(Point min, Point max)
      Creates a cuboid area from two corners. The corners may be supplied in any order.
      Parameters:
      min - one corner to convert to a block coordinate
      max - the other corner to convert to a block coordinate
      Returns:
      a cuboid area with ordered minimum and maximum coordinates
    • cube

      static Area.Cuboid cube(Point center, int size)
      Creates a cuboid centered around center with the same size on each axis.

      Since the bounds are inclusive block coordinates, even sizes include the center block and extend size / 2 blocks in each direction. The size is a coordinate span, not the final number of blocks.

      Parameters:
      center - the center point to convert to a block coordinate
      size - the size used for each axis
      Returns:
      a cuboid area
      Throws:
      IllegalArgumentException - if size is negative
    • box

      static Area.Cuboid box(Point center, Point size)
      Creates a cuboid centered around center with the given size on each axis.

      Since the bounds are inclusive block coordinates, even sizes include the center block and extend half of the size in each direction. The size is a coordinate span, not the final number of blocks.

      Parameters:
      center - the center point to convert to a block coordinate
      size - the size point, converted through its coordinates
      Returns:
      a cuboid area
      Throws:
      IllegalArgumentException - if any size component is negative
    • section

      static Area.Cuboid section(int sectionX, int sectionY, int sectionZ)
      Creates a cuboid containing all blocks in the given section.
      Parameters:
      sectionX - the section X coordinate
      sectionY - the section Y coordinate
      sectionZ - the section Z coordinate
      Returns:
      a 16x16x16 section cuboid
    • sphere

      static Area.Sphere sphere(Point center, int radius)
      Creates a sphere area from a center and non-negative radius.
      Parameters:
      center - the center point to convert to a block coordinate
      radius - the radius in blocks
      Returns:
      a sphere area
      Throws:
      IllegalArgumentException - if radius is negative