Vectors in Minecraft

This tutorial assumes you have basic knowledge of vectors and coordinate systems. Don't worry if you're not experienced in 3D. 2D will be fine as a starting point. Now a short refresher on to make an even playing field.

The Basics

This is a plain old 2D coordinate system with a vector we should all be familiar with from middle grade.

As you can see the first number 4 corresponds to the value on the x axis and the second number 2 corresponds to the value on the y axis. Also the vector starts at the origin (0, 0) . This is always the case in Minecraft. Every vector you obtain or create will have it's starting point at the origin. More on that on the next page.

But as we all know Minecraft is 3D, so lets look at that. Unlike 2D where we humans agreed some time ago that the x axis is horizontal and the y axis is vertical, in 3D the standards differ some times. Minecraft, like many other games, just extend the 2D coordinate system with a z axis pointing towards the camera. Notice how the x and z axis appear swapped.

We can confirm that by going into minecraft and pressing F3 . The little coordinate system at the crosshair is exactly what we see in the image above.

Coordinate system shown in debug mode

It is important to get a feel for that because understanding it will help when debugging your code.

We can also visualize the coordinate system and vector in an artifical way ingame. Often times this will help us understand the what the code does.

Ingame coordinate system

You can find the code for visualising vectors ingame in the repository.

Of course the axis are not to scale. It's scaled up massively in order to be able to be seen.

Standards defined by Minecraft

Cardinal Directions

You may have heard about the cardinal directions in Minecraft. They're defined the following way:

  • North -> Towards negative z

  • East -> Towards positive x

  • West -> Towards negative x

  • South -> Towards positive z

We also see that by looking at the source of BlockFace in the Spigot repository.

BlockFace source code

Exact Coordinates and Block Coordinates

As you probably already know each block is minecraft is 1x1x1 big. This translates into a coordinate system nicely. However the integer numbers always refer to the bottom right edge of a block, not the center. So a block at (3,2,2) will have its origin exactly there and will have the opposite edge at exactly (4,3,3) . Another way to think about this is to assume that the location vector of a block always extends out by 1 into the positive direction on each axis (including the y axis, which is not shown in the example below).

If we look from the top down in Minecraft we essentially get a 2D plane on the xz-axes. If we remove the y coordinate from the example above we get (3,2) which corresponds to the orange marked square (=> block in Minecraft).

View from above on the x and z axes. Orange marked square corresponds to the block at v\vec{v}.

Last updated