Package net.glowstone.util
Class Position
java.lang.Object
net.glowstone.util.Position
A static class housing position-related utilities and constants.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.Location
copyLocation
(org.bukkit.Location source, org.bukkit.Location dest) Copy the contents of one Location to another.static org.bukkit.Location
copyPosition
(org.bukkit.Location source, org.bukkit.Location dest) Copy the position contents (x,y,z) of one Location to another.static org.bukkit.block.BlockFace
getDirection
(byte rotation) Get an intercardinal BlockFace from a rotation value, where NORTH is 0.static byte
getDirection
(org.bukkit.block.BlockFace rotation) Gets the byte rotation for an intercardinal BlockFace, where NORTH is 0.static int
getIntHeadYaw
(float headYaw) Gets an integer approximation of the head-yaw rotation between 0 and 255.static int
getIntPitch
(org.bukkit.Location loc) Gets an integer approximation of the pitch between 0 and 255.static int
getIntYaw
(org.bukkit.Location loc) Gets an integer approximation of the yaw between 0 and 255.static org.bukkit.util.BlockVector
getPosition
(long position) Decodes the block vector from a serialized position value.static long
getPosition
(org.bukkit.util.BlockVector vector) Gets the serialized position value for a block vector.static boolean
hasMoved
(org.bukkit.Location first, org.bukkit.Location second) Gets whether there has been a position change between the two Locations.static boolean
hasRotated
(org.bukkit.Location first, org.bukkit.Location second) Gets whether there has been a rotation change between the two Locations.
-
Field Details
-
ROTATIONS
Common Rotation values used blocks such as Signs, Skulls, and Banners. The order relates to the data/tag that is applied to the block on placing.
-
-
Method Details
-
getIntYaw
public static int getIntYaw(org.bukkit.Location loc) Gets an integer approximation of the yaw between 0 and 255.- Parameters:
loc
- The location to get the value from.- Returns:
- An integer approximation of the yaw.
-
getIntPitch
public static int getIntPitch(org.bukkit.Location loc) Gets an integer approximation of the pitch between 0 and 255.- Parameters:
loc
- The location to get the value from.- Returns:
- An integer approximation of the yaw.
-
getIntHeadYaw
public static int getIntHeadYaw(float headYaw) Gets an integer approximation of the head-yaw rotation between 0 and 255.- Parameters:
headYaw
- the head-yaw rotation value.- Returns:
- An integer approximation of the head-yaw rotation value.
-
hasMoved
public static boolean hasMoved(org.bukkit.Location first, org.bukkit.Location second) Gets whether there has been a position change between the two Locations.- Parameters:
first
- The initial location.second
- The final location.- Returns:
- A boolean.
-
hasRotated
public static boolean hasRotated(org.bukkit.Location first, org.bukkit.Location second) Gets whether there has been a rotation change between the two Locations.- Parameters:
first
- The initial location.second
- The final location.- Returns:
- A boolean.
-
copyLocation
public static org.bukkit.Location copyLocation(org.bukkit.Location source, org.bukkit.Location dest) Copy the contents of one Location to another.- Parameters:
source
- The Location to read from.dest
- The Location to modify. May be null.- Returns:
- The dest parameter, modified if not null.
-
copyPosition
public static org.bukkit.Location copyPosition(org.bukkit.Location source, org.bukkit.Location dest) Copy the position contents (x,y,z) of one Location to another.- Parameters:
source
- The Location to read the x, y and z values from.dest
- The Location to modify the x, y and z values. May be null.- Returns:
- The dest parameter, modified if not null.
-
getDirection
public static org.bukkit.block.BlockFace getDirection(byte rotation) Get an intercardinal BlockFace from a rotation value, where NORTH is 0.- Parameters:
rotation
- byte value rotation to get- Returns:
- intercardinal BlockFace
- Throws:
IndexOutOfBoundsException
- If the value is less than 0 or greater than 15
-
getDirection
public static byte getDirection(org.bukkit.block.BlockFace rotation) Gets the byte rotation for an intercardinal BlockFace, where NORTH is 0.- Parameters:
rotation
- Rotation to get- Returns:
- byte data value for the given rotation, or -1 if rotation is SELF or null
-
getPosition
public static long getPosition(org.bukkit.util.BlockVector vector) Gets the serialized position value for a block vector.- Parameters:
vector
- the block vector to serialize- Returns:
- the serialized position value
-
getPosition
public static org.bukkit.util.BlockVector getPosition(long position) Decodes the block vector from a serialized position value.- Parameters:
position
- the position to decode- Returns:
- the decoded block vector
-