In the real-world, the custom is that North is our primary reference direction. Once we know which direction is North, our mental map falls in to place: when we face North, we know that right is East, behind is South and left is West. So to find ourselves, all we have to do is find North. Finding North has progressed from using the stars through the compass to today’s GPS system.
In Minecraft, East is like real-world North. if you think of yourself as facing East, South is to the right, North behind and West is left. So, all we need to do is find East to know where we are. Another reason to find East, is that relative to the player’s position, East is positive X and South is positive Z, making the Eastsouth quadrant the area of (positive-X, positive-Z) coordinates from where the player stands. Using (positive-X, positive-Z) coordinates often makes moving and building easier to visualize.
So which direction is East? An easy way is to plant a sunflower.
When looking at the back of the sunflower, the player is facing East, South is to the right, West is behind and North is to the left. Of course, when facing the sunflower, the player is facing West. Why do Minecraft sunflowers always face East? Imponderable. But, When I am building, I don’t want sunflowers scattered throughout my world. But, when I am building, I don’t want sunflowers scattered throughout my world.
To point North, I use something more subtle that doesn’t get in the way of my structure. In some cases, I use a couple of blocks placed under the player’s feed to point East. I use the gold block to make the “origin,” my usual name for the initial positon of the player. The blue block (lapis lazuli) is east of origin. I use these blocks as anchors for testing my mental map against the actions of my program. For example, when using the Builder to build a fence, I like to start at origin, move east, turn right, and so on, back to origin.
But, is the blue block pointing East from origin? Test it with a sunflower. The blue block is pointing the same direction as the sunflower, so East it is.
The East pointer code is implemented as a function because I use it in many different programs. Such routines are called “utilities” and are part of every programmers bag of tricks.
The function starts with a say block, which notifies the user that the function is running. Next, iIf the variable origin has not been set, it is set to the X and Z of the player world position with Y where the player’s feet are (Y = 4) in a flat world. For debugging purposes, a say block prints origin coordinates to the Command window. The gold block is placed under the original positon of the player’s feed with the blue block one block to the east.
A run command launches the function debugging. The function is designed so that origin can be a global variable that is set before the function is called. In this case the once origin has been set, the player can be an another location and can move while the function executes.
This function is used frequently in programs documented in this blog, for example, Builder Fence.
Get the Code
The code is shared at https://makecode.com/_FxX9fCYx0iUL where it can be downloaded and run in MakeCode for Minecraft.