Skip to content

DirectionHelper ​

com.jsmacrosce.jsmacros.client.api.helper.world.DirectionHelper

Since1.8.4

A helper for one of Minecraft's six cardinal directions. Directions can be queried for their axis and angles, converted to a one-block vector, or turned; the quarter-turn methods reject vertical directions.

js
// whichever way the player is looking
const player = Player.getPlayer();  
const facing = player.getFacingDirection();  
Chat.log(`${facing.getName()} is on the ${facing.getAxis()} axis at yaw ${facing.getYaw()}`);  

// turning a direction gives a new one, never a change to the old
const behind = facing.getOpposite();  
Chat.log(`${facing.getName()} is ahead, ${behind.getName()} is behind`);  

// and a direction is also the one block step it stands for
const step = facing.getVector();  
Chat.log(`one block that way is ${step.getX()}, ${step.getY()}, ${step.getZ()}`);

Constructors ​

new DirectionHelper ​

new DirectionHelper(Direction base)#
Wraps the supplied direction for helper access.

Parameters:

  • base: the direction to wrap

Methods ​

getAxis ​

getAxis(): StringSince1.8.4#
Returns the axis name (x, y, or z) of this direction.
Returns: the name of the axis this direction is aligned to.

getLeft ​

getLeft(): DirectionHelperSince1.8.4#
Returns the horizontal direction one quarter turn anticlockwise from this one. Vertical directions cannot be turned and cause an IllegalStateException.
Returns: the direction to the left.

getName ​

getName(): StringSince1.8.4#
Returns the lowercase serialized name of this direction, such as north.
Returns: the name of this direction.

getOpposite ​

getOpposite(): DirectionHelperSince1.8.4#
Returns the direction opposite this one, including for vertical directions.
Returns: the opposite direction.

getPitch ​

getPitch(): floatSince1.8.4#
Returns this direction's pitch in degrees: zero for horizontal directions and -90 or 90 for vertical directions.
Returns: the pitch of this direction.

getRight ​

getRight(): DirectionHelperSince1.8.4#
Returns the horizontal direction one quarter turn clockwise from this one. Vertical directions cannot be turned and cause an IllegalStateException.
Returns: the direction to the right.

getVector ​

getVector(): Pos3DSince1.8.4#
Returns this direction's one-block offset: one coordinate is 1 or -1, and the other two are zero.
Returns: the direction as a directional vector.

getYaw ​

getYaw(): floatSince1.8.4#
Returns this direction's yaw in degrees. Vertical directions share a yaw value, so it is meaningful as a heading only for horizontal directions.
Returns: the yaw of this direction.

isHorizontal ​

isHorizontal(): booleanSince1.8.4#
Returns whether this direction is horizontal (aligned with the x or z axis).
Returns: true if this direction is horizontal, false otherwise.

isTowardsPositive ​

isTowardsPositive(): booleanSince1.8.4#
Returns whether this direction points toward increasing coordinates on its axis.
Returns: true if this direction is pointing in a positive direction, false otherwise.

isVertical ​

isVertical(): booleanSince1.8.4#
Returns whether this direction is vertical (aligned with the y axis).
Returns: true if this direction is vertical, false otherwise.

pointsTo ​

pointsTo(double yaw): booleanSince1.8.4#
Tests whether yaw points into this direction's horizontal half-plane. Vertical directions always return false; an exact boundary between directions also returns false.

Parameters:

  • yaw: the yaw to check
Returns: true when the yaw points into this direction's horizontal half-plane; false otherwise.

toString ​

toString(): String#
Returns a diagnostic representation of the wrapped direction.
Returns: a diagnostic representation containing the direction's name, yaw, and pitch