Building
A program as a builder: it takes stone bricks from a chest and puts up a wall of any length and height, layer by layer. A second program builds a hollow tower – and pulls it down again.
Functions: PLACE_BLOCK, REMOVE_BLOCK, GET_BLOCK and SAY
Needs an operator – partly
PLACE_BLOCK with the parameter inventory takes each block from a chest, just like a player places blocks from their inventory. That works for every owner, on every server: the wall and the tower are built for everybody. REMOVE_BLOCK makes blocks disappear without a player, so it only works if the owner of the trigger block is an operator, or if the server allows it with allowBlockChanges=true in config/c0de.properties; otherwise it raises PERMISSION_DENIED. For everybody, MINE_BLOCK pulls the tower down instead (exercise 2).
What you need
- a trigger block with a button on it, and an empty sheet for each program
- for the wall: a chest with two stacks of stone bricks
- for the tower: a stack of cobblestone for the same chest
- for the exercises: a pickaxe
- a flat place of about 10 × 5 blocks for the wall, and a second one of about 7 × 3 blocks for the tower
The idea
PLACE_BLOCK puts a block with an id at a position that holds air or something replaceable like grass. Without inventory, the block comes out of nowhere – that's why it needs the right. With inventory, it is taken from the chest, and if the chest has none left, PLACE_BLOCK raises ITEM_MISSING.
A wall is a rectangle of positions: a loop over the layers, and inside it a loop along the wall.
The wall
PROGRAM wallbuilder
NOOP
INCLUDE c0de/minecraft
NOOP
FUNCTION wall
PARAMETER length INTEGER 8
PARAMETER height INTEGER 3
PARAMETER material STRING "minecraft:stone_bricks"
BEGIN
VARIABLE chest STRUCT c0de/minecraft/POSITION
VARIABLE spot STRUCT c0de/minecraft/POSITION
VARIABLE problem ERROR
ASSIGN chest.x PID.x - 2 ;
ASSIGN chest.y PID.y ;
ASSIGN chest.z PID.z ;
ASSIGN spot.z PID.z ;
FOR row INTEGER 0 ; height - 1 ;
BEGIN
FOR i INTEGER 0 ; length - 1 ;
BEGIN
ASSIGN spot.x PID.x + 2 + i ;
ASSIGN spot.y PID.y + row ;
CALL c0de/minecraft/PLACE_BLOCK problem
PARAMETER position spot ;
PARAMETER id material ;
PARAMETER inventory chest ;
IF problem.code ≠ 0 ;
BEGIN
CALL c0de/minecraft/SAY
PARAMETER message "The wall stops here: " ⊕ problem.message ;
RETURN
END IF
END FOR
END FOR
END FUNCTIONBuilding and running it
- Place the trigger block where the wall should start, and put the button on it.
- Place the chest with the stone bricks 2 blocks west of it.
- Set the trigger block to
wallbuilderandwall, and press the button.
The wall grows from 2 blocks east of the trigger block, 8 blocks long and 3 high, one block per few ticks.

How it works
- Parameters with default values.
length,heightandmaterialhave defaults, so the trigger block needs no items. To build a different wall, put an INTEGER variable itemlengthor a STRING variable itemmaterialinto the trigger block. - The loops. The outer loop counts the layers from the bottom, the inner one the blocks along the wall.
spot.znever changes: the wall runs straight east. - When things go wrong. If the chest runs empty, PLACE_BLOCK raises ITEM_MISSING; if something is in the way, INVALID_ARGUMENT. The CALL catches the error in
problem. Instead of crashing, the program says what happened and stops with RETURN – the wall stays as far as it got.
The tower
The second program has two entry functions: build puts up a hollow tower of cobblestone, 3 × 3 blocks and 6 high, and pullDown removes it again.
PROGRAM towerbuilder
NOOP
INCLUDE c0de/minecraft
NOOP
CONSTANT MATERIAL STRING "minecraft:cobblestone"
NOOP
FUNCTION build
PARAMETER height INTEGER 6
BEGIN
VARIABLE chest STRUCT c0de/minecraft/POSITION
VARIABLE spot STRUCT c0de/minecraft/POSITION
ASSIGN chest.x PID.x - 2 ;
ASSIGN chest.y PID.y ;
ASSIGN chest.z PID.z ;
FOR level INTEGER 0 ; height - 1 ;
BEGIN
FOR dx INTEGER 0 ; 2 ;
BEGIN
FOR dz INTEGER 0 ; 2 ;
BEGIN
IF dx ≠ 1 OR dz ≠ 1 ;
BEGIN
ASSIGN spot.x PID.x + 2 + dx ;
ASSIGN spot.y PID.y + level ;
ASSIGN spot.z PID.z - 1 + dz ;
CALL c0de/minecraft/PLACE_BLOCK
PARAMETER position spot ;
PARAMETER id MATERIAL ;
PARAMETER inventory chest ;
END IF
END FOR
END FOR
END FOR
END FUNCTION
NOOP
FUNCTION pullDown
PARAMETER height INTEGER 6
BEGIN
VARIABLE spot STRUCT c0de/minecraft/POSITION
VARIABLE id STRING
FOR level INTEGER height - 1 ; 0 ; -1 ;
BEGIN
FOR dx INTEGER 0 ; 2 ;
BEGIN
FOR dz INTEGER 0 ; 2 ;
BEGIN
ASSIGN spot.x PID.x + 2 + dx ;
ASSIGN spot.y PID.y + level ;
ASSIGN spot.z PID.z - 1 + dz ;
CALL c0de/minecraft/GET_BLOCK
PARAMETER position spot ;
RESULT id id
IF id = MATERIAL ;
BEGIN
CALL c0de/minecraft/REMOVE_BLOCK
PARAMETER position spot ;
PARAMETER drop TRUE ;
END IF
END FOR
END FOR
END FOR
END FUNCTIONThe tower would stand where the wall begins, so move to free ground first: take the button, the trigger block and the chest and place them there again, the chest again 2 blocks west of the trigger block. Take the leftover stone bricks out of the chest and put the cobblestone in. The tower takes the 3 × 3 blocks from 2 to 4 blocks east and from 1 block north to 1 block south. Set the trigger block to towerbuilder and build, and press the button. To pull it down, switch the function in the dialog to pullDown and press the button again.

- The ring. Three loops go through the layers and the 3 × 3 positions of each layer.
dx ≠ 1 OR dz ≠ 1leaves out the middle, so the tower is hollow. - From the top.
pullDowncounts the layers down with the step -1. A tower that loses its bottom first would look odd for a while. - Only its own blocks. Before REMOVE_BLOCK, GET_BLOCK checks that there is cobblestone. If you put a door into the tower, the program leaves it alone.
drop TRUE: every removed block falls on the ground as an item, as if it was mined. WithFALSE, it simply disappears.- No catching here. If the chest runs empty,
buildcrashes with ITEM_MISSING – the trigger block's dialog shows the error. Compare with the wall, which catches it.
Try it yourself
- Give the wall windows: in the middle layer, leave out every third block.
Solution
i \ 3 ≠ 1 is true for all blocks except the 2nd, 5th, 8th …; in the middle layer (row 1), only these get a block.
PROGRAM windowwall
NOOP
INCLUDE c0de/minecraft
NOOP
FUNCTION wall
PARAMETER length INTEGER 8
PARAMETER height INTEGER 3
PARAMETER material STRING "minecraft:stone_bricks"
BEGIN
VARIABLE chest STRUCT c0de/minecraft/POSITION
VARIABLE spot STRUCT c0de/minecraft/POSITION
VARIABLE problem ERROR
ASSIGN chest.x PID.x - 2 ;
ASSIGN chest.y PID.y ;
ASSIGN chest.z PID.z ;
ASSIGN spot.z PID.z ;
FOR row INTEGER 0 ; height - 1 ;
BEGIN
FOR i INTEGER 0 ; length - 1 ;
BEGIN
IF row ≠ 1 OR i \ 3 ≠ 1 ;
BEGIN
ASSIGN spot.x PID.x + 2 + i ;
ASSIGN spot.y PID.y + row ;
CALL c0de/minecraft/PLACE_BLOCK problem
PARAMETER position spot ;
PARAMETER id material ;
PARAMETER inventory chest ;
IF problem.code ≠ 0 ;
BEGIN
CALL c0de/minecraft/SAY
PARAMETER message "The wall stops here: " ⊕ problem.message ;
RETURN
END IF
END IF
END FOR
END FOR
END FUNCTION- Pull the tower down without any rights: break it with MINE_BLOCK and a pickaxe from the chest, and put the cobblestone back into the chest.
Solution
Put a pickaxe into the chest. MINE_BLOCK takes it as tool_inventory and puts the drops into the same chest as output_inventory. It takes as long as a player would need, and the pickaxe wears out.
PROGRAM towerminer
NOOP
INCLUDE c0de/minecraft
NOOP
CONSTANT MATERIAL STRING "minecraft:cobblestone"
NOOP
FUNCTION pullDown
PARAMETER height INTEGER 6
BEGIN
VARIABLE chest STRUCT c0de/minecraft/POSITION
VARIABLE spot STRUCT c0de/minecraft/POSITION
VARIABLE id STRING
ASSIGN chest.x PID.x - 2 ;
ASSIGN chest.y PID.y ;
ASSIGN chest.z PID.z ;
FOR level INTEGER height - 1 ; 0 ; -1 ;
BEGIN
FOR dx INTEGER 0 ; 2 ;
BEGIN
FOR dz INTEGER 0 ; 2 ;
BEGIN
ASSIGN spot.x PID.x + 2 + dx ;
ASSIGN spot.y PID.y + level ;
ASSIGN spot.z PID.z - 1 + dz ;
CALL c0de/minecraft/GET_BLOCK
PARAMETER position spot ;
RESULT id id
IF id = MATERIAL ;
BEGIN
CALL c0de/minecraft/MINE_BLOCK
PARAMETER position spot ;
PARAMETER tool_inventory chest ;
PARAMETER output_inventory chest ;
END IF
END FOR
END FOR
END FOR
END FUNCTIONRead more
- The functions of this recipe: PLACE_BLOCK, REMOVE_BLOCK, GET_BLOCK, MINE_BLOCK and SAY
- Changing the world and Owner and permissions in the guide
- Drawing a circle, another builder with PLACE_BLOCK
- Errors in the guide: catching an error in a CALL