Enum Class Direction

java.lang.Object
java.lang.Enum<Direction>
org.spongepowered.api.util.Direction
All Implemented Interfaces:
Serializable, Comparable<Direction>, Constable

public enum Direction extends Enum<Direction>
Represent the 16 main and secondary cardinal directions plus up and down. With the following assumptions:
  • NORTH targeting towards -Z
  • EAST targeting towards +X
  • SOUTH targeting towards +Z
  • WEST targeting towards -X
  • UP targeting towards +Y
  • DOWN targeting towards -Y
  • Enum Constant Details

    • NORTH

      public static final Direction NORTH
    • NORTH_NORTHEAST

      public static final Direction NORTH_NORTHEAST
    • NORTHEAST

      public static final Direction NORTHEAST
    • EAST_NORTHEAST

      public static final Direction EAST_NORTHEAST
    • EAST

      public static final Direction EAST
    • EAST_SOUTHEAST

      public static final Direction EAST_SOUTHEAST
    • SOUTHEAST

      public static final Direction SOUTHEAST
    • SOUTH_SOUTHEAST

      public static final Direction SOUTH_SOUTHEAST
    • SOUTH

      public static final Direction SOUTH
    • SOUTH_SOUTHWEST

      public static final Direction SOUTH_SOUTHWEST
    • SOUTHWEST

      public static final Direction SOUTHWEST
    • WEST_SOUTHWEST

      public static final Direction WEST_SOUTHWEST
    • WEST

      public static final Direction WEST
    • WEST_NORTHWEST

      public static final Direction WEST_NORTHWEST
    • NORTHWEST

      public static final Direction NORTHWEST
    • NORTH_NORTHWEST

      public static final Direction NORTH_NORTHWEST
    • UP

      public static final Direction UP
    • DOWN

      public static final Direction DOWN
    • NONE

      public static final Direction NONE
  • Method Details

    • values

      public static Direction[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Direction valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • closest

      public static Direction closest(Vector3d vector)
      Gets the closest direction from the given vector. If the vector is the 0-Vector, this method returns NONE. If the vector has the same horizontal and vertical length, a horizontal direction will be returned. If the vector is halfway between two directions the clockwise next will be selected.
      Parameters:
      vector - The vector to convert to a direction
      Returns:
      The closest horizontal direction.
    • closest

      public static Direction closest(Vector3d vector, Direction.Division smallestDivision)
      Gets the closest direction from the given vector. If the vector is the 0-Vector, this method returns NONE. If the vector has the same horizontal and vertical length, a horizontal direction will be returned. If the vector is halfway between two directions the clockwise next will be selected.
      Parameters:
      vector - The vector to convert to a direction
      smallestDivision - The smallest compass division that can be returned
      Returns:
      The closest horizontal direction.
    • closestHorizontal

      public static Direction closestHorizontal(Vector3d vector)
      Gets the closest horizontal direction from the given vector. If the vector is the 0-Vector (ignoring y), this method returns NONE. If the vector is halfway between two directions the clockwise next will be selected.
      Parameters:
      vector - The vector to convert to a direction
      Returns:
      The closest horizontal direction.
    • closestHorizontal

      public static Direction closestHorizontal(Vector3d vector, Direction.Division smallestDivision)
      Gets the closest horizontal direction from the given vector. If the vector is the 0-Vector (ignoring y), this method returns NONE. If the vector is halfway between two directions the clockwise next will be selected.
      Parameters:
      vector - The vector to convert to a direction
      smallestDivision - The smallest compass division that can be returned
      Returns:
      The closest horizontal direction.
    • fromAxis

      public static Direction fromAxis(Axis axis)
      Gets the direction associated with the given axis.
      Parameters:
      axis - The axis
      Returns:
      The direction
    • fromAxis

      public static Direction fromAxis(Axis axis, AxisDirection direction)
      Gets the direction of the axis along the given AxisDirection.
      Parameters:
      axis - The axis
      direction - The direction along the axis
      Returns:
      The direction
    • opposite

      public Direction opposite()
      Gets the opposite direction i.e. 180 degrees from this direction.
      Returns:
      The opposite direction
    • isOpposite

      public boolean isOpposite(Direction d)
      Returns whether the given direction is opposite this.
      Parameters:
      d - Direction to test
      Returns:
      True if it is opposite
    • isCardinal

      public boolean isCardinal()
      Return true if the direction is of a cardinal direction (north, west east, and south).

      This evaluates as false for directions that have a non-zero Y-component.

      Returns:
      True if cardinal
    • isOrdinal

      public boolean isOrdinal()
      Return true if the direction is of an ordinal direction (northwest, southwest, southeast, northeast).
      Returns:
      True if ordinal
    • isSecondaryOrdinal

      public boolean isSecondaryOrdinal()
      Return true if the direction is of a secondary ordinal direction (north-northwest, north-northeast, south-southwest, etc.).
      Returns:
      True if secondary ordinal
    • isUpright

      public boolean isUpright()
      Return whether Y component is non-zero.
      Returns:
      True if the Y component is non-zero
    • asOffset

      public Vector3d asOffset()
      Returns the direction as a unit offset vector. This vector is also suitable as a unit direction vector.
      Returns:
      The direction as an offset
    • asBlockOffset

      public Vector3i asBlockOffset()
      Returns the direction as a block offset vector. For secondary ordinals the results are approximated to the nearest block.

      The difference between this offset and asOffset() is that a block offset has unit components instead of unit length.

      Returns:
      The direction as a block offset