Class Position

java.lang.Object
net.minestom.server.utils.Position

public class Position
extends java.lang.Object
Represents a position. The instance is not contained.
  • Constructor Summary

    Constructors 
    Constructor Description
    Position()  
    Position​(float x, float y, float z)  
    Position​(float x, float y, float z, float yaw, float pitch)  
  • Method Summary

    Modifier and Type Method Description
    Position add​(float x, float y, float z)
    Adds offsets to the current position.
    Position add​(Position position)
    Adds a position to the current position.
    Position copy()
    Copies this position object with the same values.
    void copy​(Position position)
    Sets the x/y/z field of this position to the value of position.
    void copy​(Vector position)
    Sets the x/y/z field of this position to the value of position.
    boolean equals​(java.lang.Object o)
    Gets if the two objects are position and have the same values.
    Vector getDirection()
    Gets a unit-vector pointing in the direction that this Location is facing.
    float getDistance​(Position position)
    Gets the distance between 2 positions.
    float getDistanceSquared​(Position position)
    Gets the square distance to another position.
    float getPitch()
    Gets the position pitch.
    float getX()
    Gets the position X.
    float getY()
    Gets the position Y.
    float getYaw()
    Gets the position yaw.
    float getZ()
    Gets the position Z.
    int hashCode()  
    boolean hasSimilarView​(Position position)
    Checks if two positions have a similar view (yaw/pitch).
    boolean isSimilar​(Position position)
    Checks it two positions are similar (x/y/z).
    Position setDirection​(Vector vector)
    Sets the yaw and pitch to point in the direction of the vector.
    void setPitch​(float pitch)
    Changes the position pitch.
    void setX​(float x)
    Changes the position X.
    void setY​(float y)
    Changes the position Y.
    void setYaw​(float yaw)
    Changes the position yaw.
    void setZ​(float z)
    Changes the position Z.
    Position subtract​(float x, float y, float z)
    Removes offsets to the current position.
    BlockPosition toBlockPosition()
    Converts this position to a BlockPosition.
    java.lang.String toString()  
    Vector toVector()
    Converts this position to a Vector.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Position

      public Position​(float x, float y, float z, float yaw, float pitch)
    • Position

      public Position​(float x, float y, float z)
    • Position

      public Position()
  • Method Details

    • add

      public Position add​(float x, float y, float z)
      Adds offsets to the current position.
      Parameters:
      x - the X offset
      y - the Y offset
      z - the Z offset
      Returns:
      the same object position
    • add

      public Position add​(Position position)
      Adds a position to the current position.
      Parameters:
      position - the position to add to this
      Returns:
      the same object position
    • subtract

      public Position subtract​(float x, float y, float z)
      Removes offsets to the current position.
      Parameters:
      x - the X offset
      y - the Y offset
      z - the Z offset
      Returns:
      the same object position
    • getDistance

      public float getDistance​(Position position)
      Gets the distance between 2 positions. In cases where performance matters, getDistanceSquared(Position) should be used as it does not perform the expensive Math.sqrt method.
      Parameters:
      position - the second position
      Returns:
      the distance between this and position
    • getDistanceSquared

      public float getDistanceSquared​(Position position)
      Gets the square distance to another position.
      Parameters:
      position - the second position
      Returns:
      the squared distance between this and position
    • getDirection

      public Vector getDirection()
      Gets a unit-vector pointing in the direction that this Location is facing.
      Returns:
      a vector pointing the direction of this location's pitch and yaw
    • setDirection

      public Position setDirection​(Vector vector)
      Sets the yaw and pitch to point in the direction of the vector.
    • copy

      public void copy​(Vector position)
      Sets the x/y/z field of this position to the value of position.
      Parameters:
      position - the vector to copy the values from
    • copy

      public void copy​(Position position)
      Sets the x/y/z field of this position to the value of position.
      Parameters:
      position - the position to copy the values from
    • copy

      public Position copy()
      Copies this position object with the same values.
      Returns:
      a new Position object with the same coordinates
    • equals

      public boolean equals​(java.lang.Object o)
      Gets if the two objects are position and have the same values.
      Overrides:
      equals in class java.lang.Object
      Parameters:
      o - the position to check the equality
      Returns:
      true if the two objects are position with the same values, false otherwise
    • isSimilar

      public boolean isSimilar​(Position position)
      Checks it two positions are similar (x/y/z).
      Parameters:
      position - the position to compare
      Returns:
      true if the two positions are similar
    • hasSimilarView

      public boolean hasSimilarView​(Position position)
      Checks if two positions have a similar view (yaw/pitch).
      Parameters:
      position - the position to compare
      Returns:
      true if the two positions have the same view
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • getX

      public float getX()
      Gets the position X.
      Returns:
      the position X
    • setX

      public void setX​(float x)
      Changes the position X.
      Parameters:
      x - the new position X
    • getY

      public float getY()
      Gets the position Y.
      Returns:
      the position Y
    • setY

      public void setY​(float y)
      Changes the position Y.
      Parameters:
      y - the new position Y
    • getZ

      public float getZ()
      Gets the position Z.
      Returns:
      the position Z
    • setZ

      public void setZ​(float z)
      Changes the position Z.
      Parameters:
      z - the new position Z
    • getYaw

      public float getYaw()
      Gets the position yaw.
      Returns:
      the yaw
    • setYaw

      public void setYaw​(float yaw)
      Changes the position yaw.
      Parameters:
      yaw - the new yaw
    • getPitch

      public float getPitch()
      Gets the position pitch.
      Returns:
      the pitch
    • setPitch

      public void setPitch​(float pitch)
      Changes the position pitch.
      Parameters:
      pitch - the new pitch
    • toBlockPosition

      public BlockPosition toBlockPosition()
      Converts this position to a BlockPosition.
      Returns:
      the converted BlockPosition
    • toVector

      public Vector toVector()
      Converts this position to a Vector.
      Returns:
      the converted Vector
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object