Minestom wiki
Search…
Coordinates

Overview

All coordinates classes in Minestom are immutables (like a lot of others), Point being the common interface, and the implementations Pos and Vec.
Vec is a containing for the x, y & z coordinates, adding a few vector methods. Pos contains the 3 coordinates + yaw/pitch for the view. Point should be used when the type does not matter.

Immutability performance

Some may express concern about the performance penalty of using immutable classes for math. Here is our reasoning:
  • Immutability give us the guarantee that coordinate objects can be reused, reducing allocation
  • Scalar replacement may happen in some specific situation (builder mode)
  • Primitive objects will ultimately arrive, removing the concern altogether and improving performance compared to the mutable equivalent

API

Initialization

All coordinates can be created using their respective constructors
1
Vec vec1 = new Vec(3, 0, 1); // [3;0;1] -> x;y;z
2
Vec vec2 = new Vec(1, 1); // [1;0;1]
3
Vec vec3 = new Vec(5); // [5;5;5]
4
5
Pos pos1 = new Pos(1,2,3,4,5); // [1;2;3;4;5] -> x;y;z;yaw;pitch
6
Pos pos2 = new Pos(1,2,3); // [1;2;3;0;0]
7
Pos pos3 = new Pos(new Vec(1)); // [1;1;1;0;0]
8
Pos pos4 = new Pos(new Vec(1),2,3); // [1;1;1;2;3]
Copied!

Vec

1
Vec vec = new Vec(1, 2, 1);
2
vec = vec.add(0, 5, 0) // add 5 y
3
.apply(Vec.Operator.FLOOR) // floor all coordinates
4
.neg() // -x -y -z
5
.withX(x -> x * 2); // double x
Copied!

Pos

Very similar to Vec.
1
Pos pos = new Pos(0, 0, 0);
2
pos = pos.withView(50, 90)
3
.add(0, 5, 0)
4
.mul(5);
Copied!

Block coordinates

1
Point point = new Vec(1);
2
final int blockX = point.blockX();
3
final int blockY = point.blockY();
4
final int blockZ = point.blockZ();
Copied!
Last modified 3mo ago