Builder Wall

Introduction

With builder operations, we can automate creation of objects and structures. Let’s try them out and build a wall out of stone bricks!

Create a path

As the builder movement advances, we want to leave new blocks. Set trace path for the builder and use mossy stone bricks for blocks.

builder.tracePath(MOSSY_STONE_BRICKS)

Move forward

The builder path is traced by blocks after movement. This means that when you tell it to trace a path, blocks are placed starting at the position where the builder began and all along the path where it moved. Move the builder forward by 20 blocks before tracing.

builder.move(FORWARD, 20)
builder.tracePath(MOSSY_STONE_BRICKS)

Mark the staring point

When you first run your program, the builder’s position is the same as the player. That is also the beginning of the path for tracing with blocks. If you want the builder to trace a path of blocks away from where you currently are, first move it away and then set a mark to tell it where to start tracing.

builder.move(LEFT, 5)
builder.mark()
builder.move(FORWARD, 20)
builder.tracePath(MOSSY_STONE_BRICKS)

Go vertical

Now, to get ready for another row on top of your wall, move the builder up and turn in the opposite direction.

builder.move(LEFT, 5)
builder.mark()
builder.move(FORWARD, 20)
builder.move(UP, 1)
builder.turn(TurnDirection.Left)
builder.turn(TurnDirection.Left)
builder.tracePath(MOSSY_STONE_BRICKS)

Make some rows

Build a stone wall that is 10 rows high by putting the builder movement actions into a loop.

builder.move(LEFT, 5)
builder.mark()
for (let i = 0; i < 10; i++) {
    builder.move(FORWARD, 20)
    builder.move(UP, 1)
    builder.turn(TurnDirection.Left)
    builder.turn(TurnDirection.Left)
}
builder.tracePath(MOSSY_STONE_BRICKS)

Make it even

It seems that after the last row an extra block is placed. Use some air to trim that off.

builder.move(LEFT, 5)
builder.mark()
for (let i = 0; i < 10; i++) {
    builder.move(FORWARD, 20)
    builder.move(UP, 1)
    builder.turn(TurnDirection.Left)
    builder.turn(TurnDirection.Left)
}
builder.tracePath(MOSSY_STONE_BRICKS)
builder.place(AIR)

Try the chat command!

Run your code and look up! Do you see your new wall?