Skip to content

BlockPosHelper ​

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

Since1.2.6

A block position with integer world coordinates. Movement methods return new positions and leave this position unchanged; directional methods correspond to offset(String, int).

js
const pos = PositionCommon.createBlockPos(10, 64, -3);  
Chat.log(`start ${pos.getX()}, ${pos.getY()}, ${pos.getZ()}`);  

const up = pos.up();  
const upThree = pos.up(3);  
Chat.log(`${up} and ${upThree}, while pos is still ${pos}`);  

Chat.log(`${pos.north(2)} equals ${pos.offset("north", 2)}`);   // true

Chat.log(pos.toPos3D());

Constructors ​

new BlockPosHelper ​

new BlockPosHelper(BlockPos b)#
Wraps the supplied block position, retaining it as the wrapped value.

Parameters:

  • b: position to wrap
new BlockPosHelper(int x, int y, int z)#
Wraps a newly constructed block position from the supplied block coordinates.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate

Methods ​

distanceTo ​

distanceTo(EntityHelper<?> entity): doubleSince1.8.4#
Returns the Euclidean distance from this block's center to the entity's position.

Parameters:

  • entity: the entity to get the distance to
Returns: the distance in blocks.
distanceTo(BlockPosHelper pos): doubleSince1.8.4#
Returns the Euclidean distance between the two block positions, using their integer coordinates without centering either block.

Parameters:

  • pos: the position to get the distance to
Returns: the distance in blocks.
distanceTo(Pos3D pos): doubleSince1.8.4#
Returns the Euclidean distance from this block position's low corner to a point.

Parameters:

  • pos: the point to measure to
Returns: the distance in blocks.
distanceTo(double x, double y, double z): doubleSince1.8.4#
Returns the Euclidean distance from this block position's low corner to the given point.

Parameters:

  • x: the point's x coordinate
  • y: the point's y coordinate
  • z: the point's z coordinate
Returns: the distance in blocks.

down ​

down(): BlockPosHelperSince1.6.5#
Returns the position one block below this one, equivalent to offset("down").
Returns: the position below this one.
down(int distance): BlockPosHelperSince1.6.5#
Returns a position moved by distance blocks downward; negative values move upward.

Parameters:

  • distance: the signed distance to move
Returns: the resulting position.

east ​

east(): BlockPosHelperSince1.6.5#
Returns the adjacent block to the east (increasing x); equivalent to offset("east").
Returns: the block to the east.
east(int distance): BlockPosHelperSince1.6.5#
Returns a position moved by distance blocks to the east (increasing x).

Parameters:

  • distance: the distance to move east
Returns: the position at the requested signed distance east of this one.

equals ​

equals(Object obj): boolean#
Compares this helper with another helper by their wrapped positions; other object types, including null, are unequal.

Parameters:

  • obj: object to compare
Returns: true if obj is a helper whose wrapped position compares equal

getX ​

getX(): intSince1.2.6#
Returns the x coordinate in blocks.
Returns: the x coordinate.

getY ​

getY(): intSince1.2.6#
Returns the y coordinate in blocks.
Returns: the y coordinate.

getZ ​

getZ(): intSince1.2.6#
Returns the z coordinate in blocks.
Returns: the z coordinate.

hashCode ​

hashCode(): int#
Returns the hash code delegated from the wrapped position.
Returns: the wrapped position's hash code

north ​

north(): BlockPosHelperSince1.6.5#
Returns the position one block north, equivalent to offset("north"). North is toward decreasing z.
Returns: the position to the north.
north(int distance): BlockPosHelperSince1.6.5#
Returns a position moved distance blocks north (toward decreasing z).

Parameters:

  • distance: the distance to move north
Returns: the resulting position.

offset ​

offset(String direction): BlockPosHelperSince1.6.5#
Returns the adjacent position in the named direction. The name must be one of down, up, north, south, west, or east.

Parameters:

  • direction: one of down, up, north, south, west or east.
Returns: the block offset by the given direction.
offset(String direction, int distance): BlockPosHelperSince1.6.5#
Returns a position moved distance blocks in the named direction; negative distances move in the opposite direction. Direction names are the same as for offset(String).

Parameters:

  • direction: one of down, up, north, south, west or east.
  • distance: the distance to move in the given direction
Returns: the position at the requested signed distance in the given direction.
offset(int x, int y, int z): BlockPosHelperSince1.8.4#
Returns the position formed by adding the given coordinate offsets to this position.

Parameters:

  • x: the x offset
  • y: the y offset
  • z: the z offset
Returns: the block offset by the given values.

south ​

south(): BlockPosHelperSince1.6.5#
Returns the adjacent block to the south (increasing z); equivalent to offset("south").
Returns: the block to the south.
south(int distance): BlockPosHelperSince1.6.5#
Returns a position moved by distance blocks to the south (increasing z).

Parameters:

  • distance: the distance to move south
Returns: the position at the requested signed distance south of this one.

toNetherCoords ​

toNetherCoords(): BlockPosHelperSince1.8.4#
Converts coordinates by integer-dividing x and z by eight and leaving y unchanged. Negative coordinates therefore truncate toward zero; this does not locate or verify a portal.
Returns: the block position converted to the respective nether coordinates.

toOverworldCoords ​

toOverworldCoords(): BlockPosHelperSince1.8.4#
Converts this position from Nether to Overworld coordinates by multiplying x and z by eight and leaving y unchanged.
Returns: the converted Overworld position.

toPos3D ​

toPos3D(): Pos3DSince1.8.4#
Returns this position's integer coordinates as a point at the block's low corner.
Returns: this position represented as a Pos3D.

toString ​

toString(): String#
Returns a diagnostic string in the format BlockPosHelper:{"x": %d, "y": %d, "z": %d}, with the coordinate getters' values substituted in x/y/z order.
Returns: the formatted diagnostic string

up ​

up(): BlockPosHelperSince1.6.5#
Returns the position one block above this one, equivalent to offset("up").
Returns: the position above this one.
up(int distance): BlockPosHelperSince1.6.5#
Returns a position moved by distance blocks upward; negative values move downward.

Parameters:

  • distance: the signed distance to move
Returns: the resulting position.

west ​

west(): BlockPosHelperSince1.6.5#
Returns the adjacent block to the west (decreasing x); equivalent to offset("west").
Returns: the block to the west.
west(int distance): BlockPosHelperSince1.6.5#
Returns a position moved by distance blocks to the west (decreasing x).

Parameters:

  • distance: the distance to move west
Returns: the position at the requested signed distance west of this one.