Rainbow Beacon

Create colorful World markers! @showdialog

Beacons are useful markers in a Minecraft world to help you find your house or spawn point again. Let’s make a rainbow colored beacon with code!

Rainbow Beacon

Create an array of blocks

The first thing we’ll do is create an array of colored blocks. An array is a list of things.

Click on the Advanced section of the Toolbox to expand. From the ||arrays:Arrays|| category, drag a ||arrays:set list to array of (0) (1)|| block out to the workspace and drop into the ||loops:on start|| block.

Click on the ||variables:list|| drop-down and select Rename variable… Type in rainbow as the name of our array.

let rainbow = [0, 1]

Populate array

From the ||blocks:Blocks|| Toolbox drawer, drag out 2 of the ||blocks:grass block|| blocks and drop them into the ||arrays:set rainbow to array of|| block replacing the 0 and 1.

Then click on the ||blocks:grass block|| drop-down menus to select different colored blocks (like red and orange concrete).

let rainbow = [RED_CONCRETE, ORANGE_CONCRETE]

Add more blocks

In the ||arrays:set rainbow to array of|| block, click on the plus (+) icon several times to expand the array to include more blocks. Select different colored blocks to make up a rainbow!

let rainbow = [
RED_CONCRETE,
ORANGE_CONCRETE,
YELLOW_CONCRETE,
LIME_CONCRETE,
LIGHT_BLUE_CONCRETE,
PURPLE_CONCRETE
]

Change On Chat Command

Change the ||player:on chat command|| block on the workspace from “run” to “beacon”.

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

})

Set location variable

Now let’s set a location to start building our beacon.

Open the ||variables:Variables|| Toolbox drawer, and click to Make a Variable. Name this variable location.

Now from the ||variables:Variables|| category, drag a ||variables:set location to|| block out and drop into the ||player:on chat command|| block.

player.onChat("beacon", function () {
    location = 0
})
let location = 0

Set location to player’s position

From the ||player:Player|| category, drag the ||player:player world position|| block into the ||variables:set location|| block replacing the 0. This will set the location to the player’s position in the world.

player.onChat("beacon", function () {
    location = player.position()
})
let location: Position = null

Loop through array

Now let’s loop through our rainbow array of blocks. Open the ||loops:Loops|| Toolbox drawer, and drag a ||loops:for element value of list|| block out into the ||player:on chat command|| block. In this block, click on the ||variables:list|| drop-down and select ||variables:rainbow||.

player.onChat("beacon", function () {
    location = player.position()
    for (let value of rainbow) {

    }
})
let location: Position = null
let rainbow: number[] = []

Place a block from rainbow array

From the ||blocks:Blocks|| Toolbox drawer, drag a ||blocks:place block at|| block into the ||loops:for element value of rainbow|| block.

Then drag the ||variables:value|| block out of the ||loops:for element value of rainbow|| block and into the ||blocks:place block at|| block replacing the grass block. This will place a block from our rainbow array.

player.onChat("beacon", function () {
    location = player.position()
    for (let value of rainbow) {
        blocks.place(value, pos(0, 0, 0))
    }
})
let location: Position = null
let rainbow: number[] = []

Place the block at the location

We need to make sure we’re building the beacon at the correct spot. Open the ||variables:Variables|| Toolbox drawer, drag a ||variables:location|| block out and drop into the ||blocks:place value at|| block replacing the relative player coordinate block.

player.onChat("beacon", function () {
    location = player.position()
    for (let value of rainbow) {
        blocks.place(value, location)
    }
})
let location: Position = null
let rainbow: number[] = []

Reset the location coordinate

After each block we place, we want to place the subsequent block on top of that one. So we need update the location coordinate.

From the ||variables:Variables|| category, drag another ||variables:set|| variable block out and drop inside our ||loops:for element value of rainbow|| block just after the ||blocks:place value at location|| block.

Click on the variable drop-down and select the ||variables:location|| variable.

From the ||positions:Positions|| category, drag an ||positions:add positions|| block out and drop into the ||variables:set location|| block replacing the 0.

player.onChat("beacon", function () {
    location = player.position()
    for (let value of rainbow) {
        blocks.place(value, location)
        location = positions.add(
        pos(0, 0, 0),
        pos(0, 0, 0)
        )
    }
})
let location: Position = null
let rainbow: number[] = []

Add positions

Increment the current location coordinate by 1 block up. To do that, open the ||variables:Variables|| Toolbox drawer, drag a ||variables:location|| block out and drop into the first field of the ||positions:add positions|| block. Then in the second position field, type a 1 in the middle (y) coordinate - this represents 1 block up.

player.onChat("beacon", function () {
    location = player.position()
    for (let value of rainbow) {
        blocks.place(value, location)
        location = positions.add(
        location,
        pos(0, 1, 0)
        )
    }
})
let location: Position = null
let rainbow: number[] = []

Test your code

Let’s try out our code and see what happens. Press the green Play button to run our code in the game. Move your player to a place on the ground, press T to open the chat window and type in beacon. What happens?

Build it higher!

Pretty cool! 🟥🟧🟨🟩🟦🟪 We built a tower of rainbow blocks at our player’s position!

But it’s a bit short. For a beacon to be effective, it needs to be very tall so you can see it from a long ways off. To build it higher, let’s use a loop.

Open the ||loops:Loops|| Toolbox drawer, and drag a ||loops:repeat 4 times|| block out and place it around the ||loops:for element value of rainbow|| block.

In the ||loops:repeat 4 times|| block, change the 4 to a 10 to make it really high!

player.onChat("beacon", function () {
    location = player.position()
    for (let index = 0; index < 10; index++) {
        for (let value of rainbow) {
            blocks.place(value, location)
            location = positions.add(
            location,
            pos(0, 1, 0)
            )
        }
    }
})
let location: Position = null
let rainbow: number[] = []

Create your beacon

Press the green Play button to run your code in the game. Press T to open the chat window and type in beacon. You should see a very tall colorful beacon stretching up to the sky!🌈 Great job! 🌈

player.onChat("beacon", function () {
    location = player.position()
    for (let index = 0; index < 10; index++) {
        for (let value of rainbow) {
            blocks.place(value, location)
            location = positions.add(
            location,
            pos(0, 1, 0)
            )
        }
    }
})
let location: Position = null
let rainbow: number[] = []
rainbow = [
RED_CONCRETE,
ORANGE_CONCRETE,
YELLOW_CONCRETE,
LIME_CONCRETE,
LIGHT_BLUE_CONCRETE,
PURPLE_CONCRETE
]