DirectionHelper
com.jsmacrosce.jsmacros.client.api.helper.world.DirectionHelper
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
Methods
getAxis
getLeft
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
getOpposite
Returns the direction opposite this one, including for vertical directions.
Returns: the opposite direction.
getPitch
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
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
getYaw
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
Returns whether this direction is horizontal (aligned with the
x or z axis).Returns:
true if this direction is horizontal, false otherwise.isTowardsPositive
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
Returns whether this direction is vertical (aligned with the
y axis).Returns:
true if this direction is vertical, false otherwise.pointsTo
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.