Skip to content

API reference / @jsprismarine/prismarine / Position

Class: Position ​

Defined in: prismarine/src/world/Position.ts:7

Represents the coordinates of a Vector3 in a given World.

Extends ​

Constructors ​

Constructor ​

new Position(x, y, z, world): Position

Defined in: prismarine/src/world/Position.ts:16

Create a new position

Parameters ​

x ​

number

The x coordinate of the position.

y ​

number

The y coordinate of the position.

z ​

number

The z coordinate of the position.

world ​

World

The world of the position.

Returns ​

Position

The new position.

Overrides ​

Vector3.constructor

Properties ​

ZERO ​

readonly static ZERO: Vector3

Defined in: math/src/Vector3.ts:10

Returns a Vector3 with 0 on all axis.

Inherited from ​

Vector3.ZERO

Methods ​

distanceSquaredTo() ​

distanceSquaredTo(vector): number

Defined in: math/src/Vector3.ts:150

The squared distance to another vector.

Squared, and offered first, because almost every caller compares a distance against another distance - and a comparison of squares gives the same answer without the square root. Prefer this to Vector3.distanceTo wherever the number itself is not shown to anyone.

Parameters ​

vector ​

Vector3

The vector to measure to.

Returns ​

number

The squared distance.

Example ​

typescript
if (a.distanceSquaredTo(b) <= range * range) {
    // within range, with no square root taken
}

Inherited from ​

Vector3.distanceSquaredTo


distanceTo() ​

distanceTo(vector): number

Defined in: math/src/Vector3.ts:166

The distance to another vector.

Parameters ​

vector ​

Vector3

The vector to measure to.

Returns ​

number

The distance.

Example ​

typescript
const meters = player.getPosition().distanceTo(target.getPosition());

Inherited from ​

Vector3.distanceTo


equals() ​

equals(vector): boolean

Defined in: math/src/Vector3.ts:130

Compare an instance of Vector3 with another.

The parameter type matches the base declaration because ahead-of-time compilation only lowers overrides with identical signatures; a plain Vector2 is never equal to a Vector3.

Parameters ​

vector ​

Vector2

The vector to compare to.

Returns ​

boolean

true if they're equal otherwise false.

Inherited from ​

Vector3.equals


floor() ​

floor(): this

Defined in: math/src/Vector3.ts:109

Returns a new Vector3 with each component rounded down to the nearest integer.

Returns ​

this

A new vector with rounded down components.

Inherited from ​

Vector3.floor


getWorld() ​

getWorld(): World

Defined in: prismarine/src/world/Position.ts:64

Get the world of the position.

Returns ​

World

The world of the position.


getX() ​

getX(): number

Defined in: math/src/Vector2.ts:67

Get the x coordinate.

Returns ​

number

The x coordinate's value.

Inherited from ​

Vector3.getX


getY() ​

getY(): number

Defined in: math/src/Vector3.ts:101

Get the y coordinate.

Returns ​

number

The y coordinate's value.

Inherited from ​

Vector3.getY


getZ() ​

getZ(): number

Defined in: math/src/Vector2.ts:75

Get the z coordinate.

Returns ​

number

The z coordinate's value.

Inherited from ​

Vector3.getZ


toString() ​

toString(): string

Defined in: prismarine/src/world/Position.ts:33

Returns ​

string

Overrides ​

Vector3.toString


trunc() ​

trunc(): this

Defined in: math/src/Vector3.ts:117

Returns a new Vector3 with each component truncated to the nearest integer.

Returns ​

this

A new vector with truncated axis.

Inherited from ​

Vector3.trunc


withWorld() ​

withWorld(world): Position

Defined in: prismarine/src/world/Position.ts:73

Returns the same coordinates in another world.

Parameters ​

world ​

World

The world to move to.

Returns ​

Position

A new position; this one is left alone.


withX() ​

withX(x): this

Defined in: math/src/Vector3.ts:67

Returns a copy with a different X coordinate.

Parameters ​

x ​

number

The X coordinate.

Returns ​

this

A new vector; this one is left alone.

Example ​

typescript
const moved = vector.withX(10);

Inherited from ​

Vector3.withX


withY() ​

withY(y): this

Defined in: math/src/Vector3.ts:80

Returns a copy with a different Y coordinate.

Parameters ​

y ​

number

The Y coordinate.

Returns ​

this

A new vector; this one is left alone.

Example ​

typescript
const moved = vector.withY(10);

Inherited from ​

Vector3.withY


withZ() ​

withZ(z): this

Defined in: math/src/Vector3.ts:93

Returns a copy with a different Z coordinate.

Parameters ​

z ​

number

The Z coordinate.

Returns ​

this

A new vector; this one is left alone.

Example ​

typescript
const moved = vector.withZ(10);

Inherited from ​

Vector3.withZ


fromObject() ​

static fromObject(obj): Vector3

Defined in: math/src/Vector3.ts:39

Creates a new Vector3 instance from an object with x, y, and z properties.

Parameters ​

obj ​

The object containing x, y, and z properties.

x ​

number

y ​

number

z ​

number

Returns ​

Vector3

A new Vector3 instance.

Inherited from ​

Vector3.fromObject


fromVector3() ​

static fromVector3(vector, world): Position

Defined in: prismarine/src/world/Position.ts:43

Creates a Position from a Vector3 and a World.

Parameters ​

vector ​

Vector3

The vector to create the position from.

world ​

World

The world of the position.

Returns ​

Position

The new position.