# 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.

![](https://3012238209-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3CiKZGX91xk3wTXNDkac%2Fuploads%2FBMpUj4qCPBzOlXKeoXh4%2FSimpleGraph_ManimCE_v0.15.0.png?alt=media\&token=b8e62d03-7d2b-42f2-a0ba-848f3c815991)

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](https://felix-naumann.gitbook.io/comprehensive-minecraft-vectors-tutorial/understanding-the-origin).

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.

![](https://3012238209-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3CiKZGX91xk3wTXNDkac%2Fuploads%2FKjquneByuuqrRUJSEKfP%2FSimple3DGraph_ManimCE_v0.15.0.png?alt=media\&token=d73fb08b-227d-4d06-bb11-ed505004f9a6)

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](https://3012238209-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3CiKZGX91xk3wTXNDkac%2Fuploads%2FOt01VR3gNbJKIe2asAkB%2F2022-03-08_22.39.31.png?alt=media\&token=f6394557-5732-4019-b19f-3746b05abff3)

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](https://3012238209-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3CiKZGX91xk3wTXNDkac%2Fuploads%2F4cbDjnrqxMa1VhXpdXP9%2F2022-03-08_22.44.58.png?alt=media\&token=fa0cfd3d-e25b-4a08-abd9-e622a81132df)

{% hint style="info" %}
You can find the code for visualising vectors ingame in the [repository](https://github.com/wand555/VectorTutorial).
{% endhint %}

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](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/block/BlockFace.html) in the Spigot repository.

![BlockFace source code](https://3012238209-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3CiKZGX91xk3wTXNDkac%2Fuploads%2F8byLk3eO1HYhsU3Hykqt%2Fblockface%20source.PNG?alt=media\&token=e9720cad-5877-4447-89ca-bc97cf11ad92)

#### 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).

&#x20;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 .](https://3012238209-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3CiKZGX91xk3wTXNDkac%2Fuploads%2FkkwM7UvnKfepfcKuMR89%2FSimpleGraphWithFields_ManimCE_v0.15.0.png?alt=media\&token=3300465c-e1d2-4e3e-a64a-a05a9b949028)
