Record Class Pos
java.lang.Object
java.lang.Record
net.minestom.server.coordinate.Pos
- Record Components:
x- the X coordinatey- the Y coordinatez- the Z coordinateyaw- the yaw (rotation around vertical axis) in degrees (-180, 180]pitch- the pitch (rotation around lateral axis) in degrees [-90, 90]
- All Implemented Interfaces:
Point
public record Pos(double x, double y, double z, float yaw, float pitch)
extends Record
implements Point
Represents a 3D position with double-precision coordinates and viewing direction.
Combines Vec with yaw and pitch angles, making it suitable for entities
and cameras that need both location and orientation.
View angles are automatically normalized.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA functional interface representing an operation on the components of aPos. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatThe epsilon used to compare two views (yaw/pitch) if applicable.static final PosFields inherited from interface Point
EPSILON, REGION_SIZE, SECTION_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionPos(double x, double y, double z) Creates a position with the given coordinates (x/y/z) and default view (yaw/pitch = 0).Pos(double x, double y, double z, float yaw, float pitch) Creates an instance of aPosrecord class.Deprecated.Deprecated.UsePoint.asPos()instead withwithView(float, float) -
Method Summary
Modifier and TypeMethodDescriptionabs()Represents this point with all coordinates as their absolute values.absView()Returns the absolute value of the view (yaw/pitch).add(double value) Creates a new point by adding the provided value to this point coordinates for all XYZ.add(double x, double y, double z) Creates a new point by adding the provided values to this point coordinates.Creates a new point by adding another point coordinates to this point coordinates.apply(Pos.Operator operator) Returns a new position based on this position fields.asPos()Deprecated.asPos(float yaw, float pitch) Deprecated.Calculates the cross product of this point with another.Gets a unit-vector pointing in the direction that this Location is facing.div(double value) Creates a new point by dividing the provided value to this point coordinates for all XYZ.div(double x, double y, double z) Creates a new point by dividing the provided values to this point coordinates.Creates a new point by dividing another point coordinates to this point coordinates.final booleanIndicates whether some other object is "equal to" this one.facing()static floatfixPitch(float pitch) Fixes a pitch value that is not between -90.0f and 90.0f So for example, -135.0f becomes -90.0f and 225.0f becomes 90.0fstatic floatfixYaw(float yaw) Fixes a yaw value that is not between -180.0f (exclusive) and 180.0f (inclusive).static PosDeprecated, for removal: This API element is subject to removal in a future version.usePoint.asPos()insteadfinal inthashCode()Returns a hash code value for this object.Calculates a linear interpolation between this point with another point (x/y/z).Calculates a linear interpolation between this position's view and another position's view (yaw/pitch).max(double value) Gets a point representing the maximum values between this point and the provided value for all coordinates.max(double x, double y, double z) Gets a point representing the maximum values between this point and the provided coordinates (x/y/z).Gets a point representing the maximum values between this point and the provided one (x/y/z).min(double value) Gets a point representing the minimum values between this point and the provided value for all coordinates.min(double x, double y, double z) Gets a point representing the minimum values between this point and the provided coordinates (x/y/z).Gets a point representing the minimum values between this point and the provided one (x/y/z).mul(double value) Creates a new point by multiplying the provided value to this point coordinates for all XYZ.mul(double x, double y, double z) Creates a new point by multiplying the provided values to this point coordinates.Creates a new point by multiplying another point coordinates to this point coordinates.neg()Represents this point with all coordinates negated.negView()Negates the view (yaw/pitch) of this position.Converts this point to a unit point (a point with length of 1).floatpitch()Returns the value of thepitchrecord component.Creates a new point relative to this point based on the provided block face.booleansameView(float yaw, float pitch) Checks if the yaw and pitch are the same as the given ones.booleanChecks if two positions have a similar view (yaw/pitch).booleansimilarView(float yaw, float pitch) Checks if the yaw and pitch are approximately the same as the given ones.booleansimilarView(float yaw, float pitch, float epsilon) Checks if the yaw and pitch are approximately the same as the given ones.booleansimilarView(Pos position) Checks if two positions have approximately similar views (yaw/pitch).booleansimilarView(Pos position, float epsilon) Checks if two positions have approximately similar views (yaw/pitch).sub(double value) Creates a new point by subtracting the provided value to this point coordinates for all XYZ.sub(double x, double y, double z) Creates a new point by subtracting the provided values to this point coordinates.Creates a new point by subtracting another point coordinates to this point coordinates.final StringtoString()Returns a string representation of this record class.withCoord(double x, double y, double z) Changes the 3 coordinates of this position (x/y/z).Changes the coordinates to match the provided point.withDirection(Point point) Sets the yaw and pitch to point in the direction of the point.withLookAt(Point point) Changes the view to look at a specific point.withPitch(float pitch) Changes the pitch of this position.withPitch(DoubleUnaryOperator operator) Applies an operator to the pitch of this position.withView(float yaw, float pitch) Changes the view of this position (yaw/pitch).Changes the view to match the provided position.withX(double x) Creates a point with the specified X coordinate.withX(DoubleUnaryOperator operator) Creates a point with a modified X coordinate based on its value.withY(double y) Creates a point with the specified Y coordinate.withY(DoubleUnaryOperator operator) Creates a point with a modified Y coordinate based on its value.withYaw(float yaw) Changes the yaw of this position.withYaw(DoubleUnaryOperator operator) Applies an operator to the yaw of this position.withZ(double z) Creates a point with the specified Z coordinate.withZ(DoubleUnaryOperator operator) Creates a point with a modified Z coordinate based on its value.doublex()Returns the value of thexrecord component.doubley()Returns the value of theyrecord component.floatyaw()Returns the value of theyawrecord component.doublez()Returns the value of thezrecord component.Methods inherited from interface Point
angle, asBlockVec, asVec, blockX, blockY, blockZ, chunkX, chunkZ, distance, distance, distanceSquared, distanceSquared, dot, isNormalized, isZero, length, lengthSquared, regionX, regionZ, sameBlock, sameBlock, sameChunk, samePoint, samePoint, samePoint, samePoint, section, sectionX, sectionY, sectionZ, similarPoint, similarPoint
-
Field Details
-
ZERO
-
VIEW_EPSILON
public static final float VIEW_EPSILONThe epsilon used to compare two views (yaw/pitch) if applicable.- See Also:
-
-
Constructor Details
-
Pos
public Pos(double x, double y, double z, float yaw, float pitch) Creates an instance of aPosrecord class. -
Pos
public Pos(double x, double y, double z) Creates a position with the given coordinates (x/y/z) and default view (yaw/pitch = 0).- Parameters:
x- the X coordinatey- the Y coordinatez- the Z coordinate
-
Pos
Deprecated.UsePoint.asPos()instead withwithView(float, float)Creates a position from a point with the given view (yaw/pitch).- Parameters:
point- the point containing the coordinates (x/y/z)yaw- the yawpitch- the pitch
-
Pos
Deprecated.UsePoint.asPos()insteadCreates a position from a point with the default view (yaw/pitch = 0).- Parameters:
point- the point containing the coordinates (x/y/z)
-
-
Method Details
-
fromPoint
Deprecated, for removal: This API element is subject to removal in a future version.usePoint.asPos()instead- Parameters:
point- the point to convert- Returns:
- the converted position
-
fixPitch
public static float fixPitch(float pitch) Fixes a pitch value that is not between -90.0f and 90.0f So for example, -135.0f becomes -90.0f and 225.0f becomes 90.0f- Parameters:
pitch- The possible "wrong" pitch- Returns:
- a fixed pitch in the range [-90.0f, 90.0f]
-
fixYaw
public static float fixYaw(float yaw) Fixes a yaw value that is not between -180.0f (exclusive) and 180.0f (inclusive). Wraps the yaw to the nearest equivalent angle in this range. For example, -1355.0f becomes 85.0f and 225.0f becomes -135.0f.- Parameters:
yaw- The possible "wrong" yaw- Returns:
- a fixed yaw in the range (-180.0f, 180.0f]
-
withCoord
-
withCoord
-
withView
-
withView
-
withDirection
-
withYaw
-
withYaw
Applies an operator to the yaw of this position.- Parameters:
operator- the operator to apply to the yaw- Returns:
- a new position
-
withPitch
-
withLookAt
-
withPitch
Applies an operator to the pitch of this position.- Parameters:
operator- the operator to apply to the pitch- Returns:
- a new position
-
sameView
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
-
sameView
public boolean sameView(float yaw, float pitch) Checks if the yaw and pitch are the same as the given ones.- Parameters:
yaw- the yawpitch- the pitch- Returns:
- true if the yaw and pitch are the same
-
similarView
public boolean similarView(float yaw, float pitch, float epsilon) Checks if the yaw and pitch are approximately the same as the given ones.- Parameters:
yaw- the yawpitch- the pitchepsilon- the maximum difference to consider the values equal- Returns:
- true if the yaw and pitch are approximately the same
-
similarView
Checks if two positions have approximately similar views (yaw/pitch).- Parameters:
position- the position to compareepsilon- the maximum difference to consider the values equal- Returns:
- true if the two positions have a similar view
-
similarView
Checks if two positions have approximately similar views (yaw/pitch).Uses
VIEW_EPSILONas epsilon.- Parameters:
position- the position to compare- Returns:
- true if the two positions have a similar view
-
similarView
public boolean similarView(float yaw, float pitch) Checks if the yaw and pitch are approximately the same as the given ones.Uses
VIEW_EPSILONas epsilon.- Parameters:
yaw- the yawpitch- the pitch- Returns:
- true if the yaw and pitch are approximately the same
-
direction
-
facing
-
apply
Returns a new position based on this position fields.- Parameters:
operator- the operator deconstructing this object and providing a new position- Returns:
- the new position
-
withX
Description copied from interface:PointCreates a point with a modified X coordinate based on its value. -
withX
-
withY
Description copied from interface:PointCreates a point with a modified Y coordinate based on its value. -
withY
-
withZ
Description copied from interface:PointCreates a point with a modified Z coordinate based on its value. -
withZ
-
add
Description copied from interface:PointCreates a new point by adding the provided values to this point coordinates. -
add
Description copied from interface:PointCreates a new point by adding another point coordinates to this point coordinates. -
add
-
sub
Description copied from interface:PointCreates a new point by subtracting the provided values to this point coordinates. -
sub
Description copied from interface:PointCreates a new point by subtracting another point coordinates to this point coordinates. -
sub
Description copied from interface:PointCreates a new point by subtracting the provided value to this point coordinates for all XYZ. -
mul
Description copied from interface:PointCreates a new point by multiplying the provided values to this point coordinates. -
mul
Description copied from interface:PointCreates a new point by multiplying another point coordinates to this point coordinates. -
mul
Description copied from interface:PointCreates a new point by multiplying the provided value to this point coordinates for all XYZ. -
div
Description copied from interface:PointCreates a new point by dividing the provided values to this point coordinates.Warning: division by zero will not error.
-
div
Description copied from interface:PointCreates a new point by dividing another point coordinates to this point coordinates.Warning: division by zero will not error.
-
div
Description copied from interface:PointCreates a new point by dividing the provided value to this point coordinates for all XYZ.Warning: division by zero will not error.
-
relative
-
asPos
-
asPos
Deprecated.Equivalent towithView(float, float)as this is already aPos.Marked as deprecated to warn against redundant usage.
-
normalize
-
cross
Description copied from interface:PointCalculates the cross product of this point with another. The cross product is defined as:- x = y1 * z2 - y2 * z1
- y = z1 * x2 - z2 * x1
- z = x1 * y2 - x2 * y1
-
lerp
Description copied from interface:PointCalculates a linear interpolation between this point with another point (x/y/z). -
lerpView
Calculates a linear interpolation between this position's view and another position's view (yaw/pitch). The coordinates (x/y/z) remain unchanged.- Parameters:
pos- the other positionalpha- the alpha value, must be between 0.0 and 1.0- Returns:
- a new position with interpolated view
-
neg
-
negView
-
abs
-
absView
-
min
Description copied from interface:PointGets a point representing the minimum values between this point and the provided one (x/y/z). -
min
Description copied from interface:PointGets a point representing the minimum values between this point and the provided coordinates (x/y/z). -
min
Description copied from interface:PointGets a point representing the minimum values between this point and the provided value for all coordinates. -
max
Description copied from interface:PointGets a point representing the maximum values between this point and the provided one (x/y/z). -
max
Description copied from interface:PointGets a point representing the maximum values between this point and the provided coordinates (x/y/z). -
max
Description copied from interface:PointGets a point representing the maximum values between this point and the provided value for all coordinates. -
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
x
-
y
-
z
-
yaw
-
pitch
-
Point.asPos()instead