Skip to content

PositionCommon ​

com.jsmacrosce.jsmacros.client.api.library.impl.FPositionCommon

Since1.6.3

Creates 2D and 3D positions and segments, plus block positions and look-direction vectors.
Positions retain double coordinates; block positions use integer block coordinates. A vector stores its start and end positions, while a position stores one point.

js
// a point in the world, at double precision, so this is half a block along x
const here = PositionCommon.createPos(0.5, 64, 0.5);  
// the block that point is inside of, which is the one the block lookups want
const block = PositionCommon.createBlockPos(0, 64, 0);  
const at = World.getBlock(block);  
if (at !== null) {
  Chat.log(`in ${block.getX()}, ${block.getY()}, ${block.getZ()}: ${at.getName()}`);  
}

// a segment between two points, which can report its own length
const span = PositionCommon.createVec(0, 64, 0, 3, 64, 4);  
Chat.log(`that is ${span.getMagnitude()} blocks away`);  

// a flat pair, for anything that is only two axes like a GUI or a map
const corner = PositionCommon.createPos(0, 0);  
const otherCorner = PositionCommon.createPos(3, 4);

Accessible in scripts via the global PositionCommon variable.

Methods ​

createBlockPos ​

createBlockPos(int x, int y, int z): BlockPosHelperSince1.8.4#
Creates a block position from integer block coordinates. Unlike createPos(double, double, double), this names a whole block rather than a point that may lie within one. For a fractional point, FWorld.getBlock(Pos3D) floors each coordinate to find its containing block.

Parameters:

  • x: the block's x coordinate
  • y: the block's y coordinate
  • z: the block's z coordinate
Returns: the block position at those coordinates

createLookingVector ​

createLookingVector(EntityHelper<?> entity): Vec3DSince1.8.4#
Returns the entity's look direction as a segment from the origin. The end coordinates are the entity's raw look-angle vector; no normalization is performed. For the angles themselves rather than a direction, createLookingVector(double, double) takes them as arguments.
const player = Player.getPlayer();
if (player !== null) {
  const look = PositionCommon.createLookingVector(player);
  // the endpoint is the player's raw look-angle vector
  const fiveBlocksOut = look.getEnd().scale(5);
  Chat.log(`${fiveBlocksOut} is straight ahead`);
}

Parameters:

  • entity: the entity to read the look direction off
Returns: the entity's raw look-angle vector from the origin
createLookingVector(double yaw, double pitch): Vec3DSince1.8.4#
Returns the direction for the supplied yaw and pitch as a segment from the origin. Arguments are in yaw-then-pitch order, both in degrees; vanilla's conversion takes them in pitch-then-yaw order. The returned endpoint is the direction vector produced by that conversion.
// the same two angles a player is looking with, in the same order
const player = Player.getPlayer();
if (player !== null) {
  const look = PositionCommon.createLookingVector(player.getYaw(), player.getPitch());
  // one block out is the direction itself, ten blocks out is a point in the world
  const ahead = look.getEnd().scale(10);
  Chat.log(`ten blocks ahead is ${ahead}`);
  // and read the angles straight back off the segment that was built from them
  Chat.log(`yaw ${look.getYaw()}, pitch ${look.getPitch()}`);
}

Parameters:

  • yaw: the horizontal angle in degrees, where positive is south and it grows clockwise
  • pitch: the vertical angle in degrees, where negative looks up
Returns: the vector produced by converting the given angles, from the origin

createPos ​

createPos(double x, double y, double z): Pos3DSince1.6.3#
Creates a 3D position from double-precision coordinates.

Parameters:

  • x: the x coordinate of the point
  • y: the y coordinate of the point
  • z: the z coordinate of the point
Returns: a new three dimensional position at those coordinates
createPos(double x, double y): Pos2DSince1.6.3#
Creates a 2D position from its x and y coordinates. Unlike createPos(double, double, double), this position has no z coordinate.

Parameters:

  • x: the x coordinate of the point
  • y: the y coordinate of the point
Returns: a new two dimensional position at those coordinates

createVec ​

createVec(double x1, double y1, double z1, double x2, double y2, double z2): Vec3DSince1.6.3#
Creates a 3D segment from its start coordinates to its end coordinates. The two triples are the start and the end of the segment, not a minimum and a maximum, so the two ends can be given in either order and reversing them gives a vector running the other way. This is the three dimensional form; createVec(double, double, double, double) is the flat one.
// a segment from one corner of a build to the opposite corner
const diagonal = PositionCommon.createVec(0, 64, 0, 3, 67, 4);
// what the game would call the angles of that direction
Chat.log(`yaw ${diagonal.getYaw()}, pitch ${diagonal.getPitch()}`);
// and how far it is, which is what a reach check wants
Chat.log(`${diagonal.getMagnitude()} blocks`);

Parameters:

  • x1: the x coordinate of the start of the segment
  • y1: the y coordinate of the start of the segment
  • z1: the z coordinate of the start of the segment
  • x2: the x coordinate of the end of the segment
  • y2: the y coordinate of the end of the segment
  • z2: the z coordinate of the end of the segment
Returns: a new three dimensional vector running from the first point to the second
createVec(double x1, double y1, double x2, double y2): Vec2DSince1.6.3#
Creates a 2D segment from its start coordinates to its end coordinates. The two coordinate pairs are the start and end; there is no z coordinate.

Parameters:

  • x1: the x coordinate of the start of the segment
  • y1: the y coordinate of the start of the segment
  • x2: the x coordinate of the end of the segment
  • y2: the y coordinate of the end of the segment
Returns: a new two dimensional vector running from the first point to the second