Java Coding Class: X Y Z coordinates

Updated: Aug 7, 2021

Hi everyone! Recently a lot of people in my class have been asking me "how do I do this command but in a different place?" or something like that. Every command in minecraft that allows you to change the position of something uses X Y Z coordinates. Sometimes commands don't make it obvious. For example in the summon command you can choose where to summon the entity, but it's not obvious where you can choose to set it's location. The X Y Z system is based around a 3D environment, and is able to pinpoint any location on a 3D scale, no matter how small the object is. That is why the X Y Z system is so abundant in minecraft commands. This is something that is taught in plane geometry, and it is a little bit confusing but eventually you will get the hang of it.

Each letter represents an axis, or 'line'.


The X axis represents East/West. A positive value increases the position to the East. A negative value increases the position to the West.

The Y axis represents up/down. A positive value increases the position up. A negative value increases the position down.

The Z axis represents South/North. A positive value increases the position to the South. A negative value increases your position to the North.





For example, if I put the numbers 23 54 -34 into a command, that would mean the position is 23 blocks East, 54 blocks up, and 34 blocks North. You can also use decimals, so for example,

23.4 54.7 -34.2


This is called an Absolute coordinate. That means it is all numbers, so this is the absolute location in the entire infinite minecraft world. There are three types of coordinates: Absolute, Relative, and Local, the hardest.


Before we get into Relative coordinates, we need to find out how to view your location, or point on the X Y Z axis.

You can find all this on your F3 menu. You can open this by pressing:


Windows:

F3 on your keyboard.

If that does not work, hold fn and then press F3.


Mac:

F3 on your keyboard.

If that does not work, hold fn and press F3.

If that does not work, hold command and press F3.

If that does not work, hold command, hold fn, and press F3.


This will bring up the debug menu. It should look something like this:


(you can close the menu by pressing the keys you pressed to activate it)

There will be a lot of things ranging from blocks to your processor and CPU, but I highlighted everything that is important.


TIP: your location is always where your feet are. When you look at your location in the debug menu it is always the location of your feet.


Whenever we are using X Y Z coordinates, we rarely want to use decimals. That is why it is always good to make sure you are getting your locations not in decimal form but in block form for commands like /fill or /setblock.


Now that we have learned Absolute coordinates, we can now get into Relative coordinates.

Relative coordinates are based on your location, or the location of the command block you are executing a command from.

Relative coordinates use tilde symbols (~) to locate points, and each one revolves around your location. A base relative coordinate looks like this: ~ ~ ~

Just like Absolute coordinates, each tilde represents a letter from X Y Z.

~ ~ ~ means your location or the location of the command block you are executing it from, but we can change that. If I put ~ ~1 ~ as an absolute coordinate, this means 1 block above the location in which we are executing the command. If I do ~-2 ~23 ~6 that means 2 blocks west, 23 blocks upward, and 6 blocks South, all starting from the point of origin, which is your feet or the exact location of the command block you are executing the command from.


That's pretty much it for Relative coordinates, so on to the hardest: Local coordinates.

This is pretty different from the other ones, and it uses Caret notation (^)

Instead of X Y Z, it's Xlocal, Ylocal, and Zlocal. Like Relative coordinates, this revolves around the location of where the command is being executed.


Xlocal with a positive value is left, and a negative value is right.

Ylocal is up and down, with a positive value up and a negative value down.

Zlocal is where the player is facing, with a positive value forward and a negative value backward.


For example, running the command /tp ^ ^ ^5 will teleport the player five blocks forward in the direction the player is facing. If the player faces a different direction, it will still send them the direction they are facing. You can also make them go backwards if you put this in: ^ ^ ^-5

Similar to Zlocal, Xlocal makes you go into a direction that depends on where you are facing.

A positive value will send you left, while a negative value is right. So if I do ^-3 ^ ^4, this will send me 4 blocks in the direction I am facing and 3 blocks right from where I am facing.


Thats it for Local coordinates. Any time there is a place in a command where you can put in X Y Z coordinates, you can put any of these 3 types of X Y Z coordinates in. You can also mix and match them as well! For example, 64 ~3 ^5 works. This would be at 64 in the X coordinate, 3 blocks upward relative to my feet or the command block it is being executed in, and in replace of the Z coordinate it is 5 blocks in front of where I am facing.


Congratulations! You just learned all there is to X Y Z coordinates in minecraft. If you have any questions, feel free to ask me on slack or in class! I hope you learned something while reading this, and have fun making commands in minecraft! ~ Benny