Positions

Use Positions as locations in Minecraft @showdialog

Learn how to use the different position blocks. For this tutorial, it’s recommended to be in a flat world. Learn more about positions here.

Positions

Position blocks @showdialog

As Minecraft is a 🌍 3D world 🌍, there are 3 coordinate axis: East/West, Up/Down, and North/South. Positions are a way to use these coordinates to specify a location in the world.

The world position is the distance in blocks from the world’s origin (0, 0, 0).

Position Blocks

Create a variable

Let’s create a variable to hold the world position of our player’s spawn point. Open the ||variables:Variables|| Toolbox drawer and click to Make a Variable. Name this variable “spawnpoint”.

Set player spawn location

Open the ||variables:Variables|| Toolbox drawer and drag the ||variables:set spawnpoint|| block into the ||loops:On Start|| block. From the ||player:Player|| category, drag the ||player:player world position|| block into the ||variables:set spawnpoint|| block.

let spawnpoint = player.position()

Rename chat command

Now that we have saved our player’s spawn point, let’s explore where the origin of the world is. In the ||player:on chat command|| block on the workspace, click to rename this command from “run” to “tporigin”.

player.onChat("tporigin", function () {

})

Teleport to origin

From the ||player:Player|| category, drag out a ||player:teleport to|| block and drop inside the ||player:on chat command|| block. From the ||positions:Positions|| category, drag out a ||positions:world (0, 0, 0)|| position block and drop into the ||player:teleport to|| block replacing the existing position block.

player.onChat("tporigin", function () {
    player.teleport(world(0, 0, 0))
})

Create another On Chat Command

Now let’s code a way to get back! From the ||player:Player|| Toolbox drawer, drag another ||player:on chat command|| block out to the workspace. Name this command “tpback”.

player.onChat("tpback", function () {

})

Teleport back

From the ||player:Player|| category, drag out a ||player:teleport to|| block and drop inside the ||player:on chat command tpback|| block. From the ||variables:Variables|| category, drag out a ||variables:spawnpoint|| variable block and drop into the ||player:teleport to|| block replacing the existing position block.

let spawnpoint = player.position()
player.onChat("tpback", function () {
    player.teleport(spawnpoint)
})

Run your code

Press the 🟩 green 🟩 play button to run your code. Press “t” to open the chat window in Minecraft and type “tporgin” to teleport to the origin of the world at position (0, 0, 0). Then in the chat window, type “tpback” to get back to your spawn point.

You can use World Positions to create different ❌ markers ❌ in the world for where you built a house, found a village or buried some treasure so that you can always find your way back!

Player position @showdialog

Instead of using the world cardinal directions, a player position allows you to specify coordinates to the right/left ⇄, above/below ⇅, and in front/behind the player ⤢.

Player Position

Add Chat Commands

From the ||player:Player|| Toolbox drawer, drag out 2 ||player:on chat command|| blocks to the workspace. Name one “forward” and name the other “left”.

player.onChat("forward", function () {

})
player.onChat("left", function () {

})

Place blocks

From the ||blocks:Blocks|| Toolbox category, drag 2 ||blocks:place|| blocks out to the workspace and drop one each into the ||player:on chat command|| blocks you just created. Use the drop-down menus to select a noticeable block to place (for example, Block of Gold).

player.onChat("forward", function () {
    blocks.place(GOLD_BLOCK, pos(0, 0, 0))
})
player.onChat("left", function () {
    blocks.place(GOLD_BLOCK, pos(0, 0, 0))
})

Player direction

From the ||positions:Positions|| category, drag out 2 ||positions:right(0), above(0), in front(0)|| Player Position blocks and drop one each into the ||blocks:place|| blocks replacing the existing position blocks. In the ||player:on chat command forward|| block, change the position block value of in front to be 2, and in the ||player:on chat command left|| block, change the position block value of right to be -2. You can type a value or use the sliders.

player.onChat("forward", function () {
    blocks.place(GOLD_BLOCK, posCamera(0, 0, 2))
})
player.onChat("left", function () {
    blocks.place(GOLD_BLOCK, posCamera(-2, 0, 0))
})

Run your code

Press the 🟩 green 🟩 play button to run your code. Press “t” to open the chat window in Minecraft and type “forward” to place a block 2 blocks in front of your player, and type “left” to place a block 2 blocks to the left of your player.

Player positions are the easiest way to place objects in the world around your 🧍 player 🧍.

Relative world position @showdialog

Relative world position blocks use coordinates that specify a location 🧭 relative 🧭 to the player in a world. These relative coordinates are denoted by a tilda symbol (~) in front of the value, and they follow the cardinal world axis.

Relative Position

Create a Chat Command

Let’s practice using relative positions with the Fill block. First, let’s create a new chat command. From the ||player:Player|| Toolbox drawer, drag out an ||player:on chat command|| block to the workspace. Name it “fill”.

player.onChat("fill", function () {

})

Use a fill block

From the ||blocks:Blocks|| Toolbox category, drag a ||blocks:fill with|| block out to the workspace and drop it into the ||player:on chat command|| block you just created. In the ||blocks:fill|| block, use the drop-down menu to select a block that we’ll use to fill up an area (for example, Redstone or TNT).

player.onChat("fill", function () {
    blocks.fill(
    REDSTONE_BLOCK,
    pos(0, 0, 0),
    pos(0, 0, 0),
    FillOperation.Replace
    )
})

Use relative positions

The ||blocks:fill|| block uses 2 coordinate positions to determine the area to fill - from the top corner position to the bottom opposite corner position of a cube. Change the from relative position coordinates to (~10, ~0, ~10) and the to relative position coordinates to (~5, ~5, ~5). This will create a fill area of 5 cubic blocks about 5 blocks away from the player.

player.onChat("fill", function () {
    blocks.fill(
    REDSTONE_BLOCK,
    pos(10, 0, 10),
    pos(5, 5, 5),
    FillOperation.Replace
    )
})

Run your code

Press the 🟩 green 🟩 play button to run your code. Press “t” to open the chat window in Minecraft and type “fill” to fill a 5 by 5 cubic area that is 5 blocks away from your player.

⭐ Great job ⭐ learning about the different types of positions in Minecraft! Try experimenting with the different Position blocks to teleport, place and build things in Minecraft!