Package net.minestom.server.utils
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
-
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 ofposition
.void
copy(Vector position)
Sets the x/y/z field of this position to the value ofposition
.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)
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 aBlockPosition
.java.lang.String
toString()
Vector
toVector()
Converts this position to aVector
.
-
Constructor Details
-
Method Details
-
add
Adds offsets to the current position.- Parameters:
x
- the X offsety
- the Y offsetz
- the Z offset- Returns:
- the same object position
-
add
Adds a position to the current position.- Parameters:
position
- the position to add to this- Returns:
- the same object position
-
subtract
Removes offsets to the current position.- Parameters:
x
- the X offsety
- the Y offsetz
- the Z offset- Returns:
- the same object position
-
getDistance
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
andposition
-
getDistanceSquared
Gets the square distance to another position.- Parameters:
position
- the second position- Returns:
- the squared distance between
this
andposition
-
getDirection
Gets a unit-vector pointing in the direction that this Location is facing. -
setDirection
-
copy
Sets the x/y/z field of this position to the value ofposition
.- Parameters:
position
- the vector to copy the values from
-
copy
Sets the x/y/z field of this position to the value ofposition
.- Parameters:
position
- the position to copy the values from
-
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 classjava.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
Checks it two positions are similar (x/y/z).- Parameters:
position
- the position to compare- Returns:
- true if the two positions are similar
-
hasSimilarView
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 classjava.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
Converts this position to aBlockPosition
.- Returns:
- the converted
BlockPosition
-
toVector
Converts this position to aVector
.- Returns:
- the converted
Vector
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-