Interface Position

All Known Subinterfaces:
BlockPosition, FinePosition, Location

public sealed interface Position permits BlockPosition, FinePosition
An immutable set of X, Y and Z coordinates.
Since:
0.1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    block(int x, int y, int z)
    Creates a block position at the given coordinates.
    default int
    Gets the X coordinate of the block containing this position.
    default int
    Gets the Y coordinate of the block containing this position.
    default int
    Gets the Z coordinate of the block containing this position.
    default ChunkPos
    Gets the position of the chunk containing this position.
    default int
    Gets the X coordinate of the chunk containing this position.
    default int
    Gets the Z coordinate of the chunk containing this position.
    default double
    Computes the squared distance between this position and another.
    fine(double x, double y, double z)
    Creates a fine position at the given coordinates.
    default int
    Gets the X coordinate of this position relative to the chunk containing it.
    default int
    Gets the Z coordinate of this position relative to the chunk containing it.
    offset(double x, double y, double z)
    Moves this position along all three axes.
    offset(int x, int y, int z)
    Moves this position along all three axes by a whole number of blocks.
    offsetX(double x)
    Moves this position along the X axis.
    offsetX(int x)
    Moves this position along the X axis by a whole number of blocks.
    offsetY(double y)
    Moves this position along the Y axis.
    offsetY(int y)
    Moves this position along the Y axis by a whole number of blocks.
    offsetZ(double z)
    Moves this position along the Z axis.
    offsetZ(int z)
    Moves this position along the Z axis by a whole number of blocks.
    Moves this position by one block in the direction of the given face.
    relative(BlockFace face, int distance)
    Moves this position by the defined distance in the direction of the given face.
    Places this position in a world.
    with(double x, double y, double z)
    Copies this position with different coordinates.
    with(int x, int y, int z)
    Copies this position with different whole coordinates.
    withX(double x)
    Copies this position with a different X coordinate.
    withX(int x)
    Copies this position with a different whole X coordinate.
    withY(double y)
    Copies this position with a different Y coordinate.
    withY(int y)
    Copies this position with a different whole Y coordinate.
    withZ(double z)
    Copies this position with a different Z coordinate.
    withZ(int z)
    Copies this position with a different whole Z coordinate.
    double
    x()
    Gets the X coordinate of this position.
    double
    y()
    Gets the Y coordinate of this position.
    double
    z()
    Gets the Z coordinate of this position.
  • Method Details

    • fine

      @Contract(value="_, _, _ -> new", pure=true) static FinePosition fine(double x, double y, double z)
      Creates a fine position at the given coordinates.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      z - the Z coordinate
      Returns:
      a new fine position at the given coordinates
      Since:
      0.1.0
    • block

      @Contract(value="_, _, _ -> new", pure=true) static BlockPosition block(int x, int y, int z)
      Creates a block position at the given coordinates.
      Parameters:
      x - the block X coordinate
      y - the block Y coordinate
      z - the block Z coordinate
      Returns:
      a new block position at the given coordinates
      Since:
      0.1.0
    • x

      @Contract(pure=true) double x()
      Gets the X coordinate of this position.
      Returns:
      the X coordinate
      Since:
      0.1.0
    • y

      @Contract(pure=true) double y()
      Gets the Y coordinate of this position.
      Returns:
      the Y coordinate
      Since:
      0.1.0
    • z

      @Contract(pure=true) double z()
      Gets the Z coordinate of this position.
      Returns:
      the Z coordinate
      Since:
      0.1.0
    • relative

      @Contract(value="_, _ -> new", pure=true) Position relative(BlockFace face, int distance)
      Moves this position by the defined distance in the direction of the given face.
      Parameters:
      face - the direction to move towards
      distance - the offset distance
      Returns:
      a new position moved by one block towards the given face
      Since:
      0.1.0
    • relative

      @Contract(value="_ -> new", pure=true) Position relative(BlockFace face)
      Moves this position by one block in the direction of the given face.
      Parameters:
      face - the direction to move towards
      Returns:
      a new position moved by one block towards the given face
      Since:
      0.1.0
      See Also:
    • offsetX

      @Contract(value="_ -> new", pure=true) FinePosition offsetX(double x)
      Moves this position along the X axis.
      Parameters:
      x - the amount to add to the X coordinate
      Returns:
      a new position with the given amount added to the X coordinate
      Since:
      0.1.0
    • offsetY

      @Contract(value="_ -> new", pure=true) FinePosition offsetY(double y)
      Moves this position along the Y axis.
      Parameters:
      y - the amount to add to the Y coordinate
      Returns:
      a new position with the given amount added to the Y coordinate
      Since:
      0.1.0
    • offsetZ

      @Contract(value="_ -> new", pure=true) FinePosition offsetZ(double z)
      Moves this position along the Z axis.
      Parameters:
      z - the amount to add to the Z coordinate
      Returns:
      a new position with the given amount added to the Z coordinate
      Since:
      0.1.0
    • offset

      @Contract(value="_, _, _ -> new", pure=true) FinePosition offset(double x, double y, double z)
      Moves this position along all three axes.
      Parameters:
      x - the amount to add to the X coordinate
      y - the amount to add to the Y coordinate
      z - the amount to add to the Z coordinate
      Returns:
      a new position with the given amounts added to each coordinate
      Since:
      0.1.0
    • offsetX

      @Contract(value="_ -> new", pure=true) Position offsetX(int x)
      Moves this position along the X axis by a whole number of blocks.
      Parameters:
      x - the amount to add to the X coordinate
      Returns:
      a new position of the same kind with the given amount added to the X coordinate
      Since:
      0.1.0
    • offsetY

      @Contract(value="_ -> new", pure=true) Position offsetY(int y)
      Moves this position along the Y axis by a whole number of blocks.
      Parameters:
      y - the amount to add to the Y coordinate
      Returns:
      a new position of the same kind with the given amount added to the Y coordinate
      Since:
      0.1.0
    • offsetZ

      @Contract(value="_ -> new", pure=true) Position offsetZ(int z)
      Moves this position along the Z axis by a whole number of blocks.
      Parameters:
      z - the amount to add to the Z coordinate
      Returns:
      a new position of the same kind with the given amount added to the Z coordinate
      Since:
      0.1.0
    • offset

      @Contract(value="_, _, _ -> new", pure=true) Position offset(int x, int y, int z)
      Moves this position along all three axes by a whole number of blocks.
      Parameters:
      x - the amount to add to the X coordinate
      y - the amount to add to the Y coordinate
      z - the amount to add to the Z coordinate
      Returns:
      a new position of the same kind with the given amounts added to each coordinate
      Since:
      0.1.0
    • withX

      @Contract(value="_ -> new", pure=true) FinePosition withX(double x)
      Copies this position with a different X coordinate.
      Parameters:
      x - the new X coordinate
      Returns:
      a new position with the X coordinate replaced
      Since:
      0.1.0
    • withY

      @Contract(value="_ -> new", pure=true) FinePosition withY(double y)
      Copies this position with a different Y coordinate.
      Parameters:
      y - the new Y coordinate
      Returns:
      a new position with the Y coordinate replaced
      Since:
      0.1.0
    • withZ

      @Contract(value="_ -> new", pure=true) FinePosition withZ(double z)
      Copies this position with a different Z coordinate.
      Parameters:
      z - the new Z coordinate
      Returns:
      a new position with the Z coordinate replaced
      Since:
      0.1.0
    • with

      @Contract(value="_, _, _ -> new", pure=true) FinePosition with(double x, double y, double z)
      Copies this position with different coordinates.
      Parameters:
      x - the new X coordinate
      y - the new Y coordinate
      z - the new Z coordinate
      Returns:
      a new position with all coordinates replaced
      Since:
      0.1.0
    • withX

      @Contract(value="_ -> new", pure=true) Position withX(int x)
      Copies this position with a different whole X coordinate.
      Parameters:
      x - the new X coordinate
      Returns:
      a new position of the same kind with the X coordinate replaced
      Since:
      0.1.0
    • withY

      @Contract(value="_ -> new", pure=true) Position withY(int y)
      Copies this position with a different whole Y coordinate.
      Parameters:
      y - the new Y coordinate
      Returns:
      a new position of the same kind with the Y coordinate replaced
      Since:
      0.1.0
    • withZ

      @Contract(value="_ -> new", pure=true) Position withZ(int z)
      Copies this position with a different whole Z coordinate.
      Parameters:
      z - the new Z coordinate
      Returns:
      a new position of the same kind with the Z coordinate replaced
      Since:
      0.1.0
    • with

      @Contract(value="_, _, _ -> new", pure=true) Position with(int x, int y, int z)
      Copies this position with different whole coordinates.
      Parameters:
      x - the new X coordinate
      y - the new Y coordinate
      z - the new Z coordinate
      Returns:
      a new position of the same kind with all coordinates replaced
      Since:
      0.1.0
    • blockX

      @Contract(pure=true) default int blockX()
      Gets the X coordinate of the block containing this position.
      Returns:
      the X coordinate of the block holding this position, rounded towards negative infinity
      Since:
      0.1.0
    • blockY

      @Contract(pure=true) default int blockY()
      Gets the Y coordinate of the block containing this position.
      Returns:
      the Y coordinate of the block holding this position, rounded towards negative infinity
      Since:
      0.1.0
    • blockZ

      @Contract(pure=true) default int blockZ()
      Gets the Z coordinate of the block containing this position.
      Returns:
      the Z coordinate of the block holding this position, rounded towards negative infinity
      Since:
      0.1.0
    • chunk

      @Contract(value=" -> new", pure=true) default ChunkPos chunk()
      Gets the position of the chunk containing this position.
      Returns:
      the position of the chunk holding this block
      Since:
      0.1.0
    • chunkX

      @Contract(pure=true) default int chunkX()
      Gets the X coordinate of the chunk containing this position.
      Returns:
      the X coordinate of the chunk holding this block
      Since:
      0.1.0
    • chunkZ

      @Contract(pure=true) default int chunkZ()
      Gets the Z coordinate of the chunk containing this position.
      Returns:
      the Z coordinate of the chunk holding this block
      Since:
      0.1.0
    • localX

      @Contract(pure=true) default int localX()
      Gets the X coordinate of this position relative to the chunk containing it.
      Returns:
      the X coordinate of this block inside its chunk, 0 to 15
      Since:
      0.1.0
    • localZ

      @Contract(pure=true) default int localZ()
      Gets the Z coordinate of this position relative to the chunk containing it.
      Returns:
      the Z coordinate of this block inside its chunk, 0 to 15
      Since:
      0.1.0
    • distanceSquared

      @Contract(pure=true) default double distanceSquared(Position other)
      Computes the squared distance between this position and another.
      Parameters:
      other - the position to measure the distance to
      Returns:
      the squared euclidean distance between this position and another
      Since:
      0.1.0
    • toLocation

      @Contract(value="_ -> new", pure=true) Location toLocation(World world)
      Places this position in a world.
      Parameters:
      world - the world of the location
      Returns:
      a new location at these coordinates in the given world
      Since:
      0.1.0