Package dev.polv.taleapi.world
Class Location
java.lang.Object
dev.polv.taleapi.world.Location
Represents a position in the world with coordinates and optional rotation.
Locations are immutable. All modification methods return a new Location instance.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(double dx, double dy, double dz) Creates a new location by adding the given offsets.doubleCalculates the distance between this location and another.doubledistanceSquared(Location other) Calculates the squared distance between this location and another.booleaninthashCode()floatpitch()toString()withRotation(float yaw, float pitch) Creates a new location with modified rotation.withX(double x) Creates a new location with modified x coordinate.withY(double y) Creates a new location with modified y coordinate.withZ(double z) Creates a new location with modified z coordinate.doublex()doubley()floatyaw()doublez()
-
Constructor Details
-
Location
public Location(double x, double y, double z) Creates a new location with the specified coordinates and no rotation.- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinate
-
Location
public Location(double x, double y, double z, float yaw, float pitch) Creates a new location with the specified coordinates and rotation.- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinateyaw- the yaw rotation (horizontal, 0-360)pitch- the pitch rotation (vertical, -90 to 90)
-
-
Method Details
-
x
public double x()- Returns:
- the x coordinate
-
y
public double y()- Returns:
- the y coordinate
-
z
public double z()- Returns:
- the z coordinate
-
yaw
public float yaw()- Returns:
- the yaw rotation (horizontal angle)
-
pitch
public float pitch()- Returns:
- the pitch rotation (vertical angle)
-
withX
Creates a new location with modified x coordinate.- Parameters:
x- the new x coordinate- Returns:
- a new Location with the modified value
-
withY
Creates a new location with modified y coordinate.- Parameters:
y- the new y coordinate- Returns:
- a new Location with the modified value
-
withZ
Creates a new location with modified z coordinate.- Parameters:
z- the new z coordinate- Returns:
- a new Location with the modified value
-
withRotation
Creates a new location with modified rotation.- Parameters:
yaw- the new yaw rotationpitch- the new pitch rotation- Returns:
- a new Location with the modified values
-
add
Creates a new location by adding the given offsets.- Parameters:
dx- the x offsetdy- the y offsetdz- the z offset- Returns:
- a new Location with the offsets applied
-
distance
Calculates the distance between this location and another.- Parameters:
other- the other location- Returns:
- the distance between the two locations
-
distanceSquared
Calculates the squared distance between this location and another.This is faster than
distance(Location)as it avoids the square root. Useful for distance comparisons.- Parameters:
other- the other location- Returns:
- the squared distance between the two locations
-
equals
-
hashCode
public int hashCode() -
toString
-