Skip to content

Blocks

Blocks are used to define an inline function, inside another function.

block [name] { [<macro arguments> | with <...>]
    <...>
}

Creating a Block

When creating a block inside of a function, it will inline a call to it's generated function.

Creating an unnamed block will put the generated function into the parent function's folder + zzz/<id>.mcfunction.

Creating an Anonymous Block
Code
function example {
    say Before block
    block {
        say Hello, world!
    }
    say After block
}
example.mcfunction
say Before block
function zzz/0
say After block
zzz/0.mcfunction
say Hello, world!

Naming a Block

A named block will put it's generated function into the parent function's folder as <name>.mcfunction.

Creating an Named Block
Code
function example {
    block my_block {
        say Hello, world!
    }
}
example.mcfunction
function my_block
my_block.mcfunction
say Hello, world!

Using Macro Arguments

Blocks can take macro arguments, which are then passed to the inlined function call.

Using Macro Arguments

Hard-coded Arguments

Code
function example {
    block my_block { {input: "world"}
        $say Hello, $(input)!
    }
}
example.mcfunction
function my_block {input: "world"}
my_block.mcfunction
$say Hello, $(input)!

Dynamic Arguments

Code
function example {
    block my_block { with storage example:arguments {}
        $say Hello, $(input)!
    }
}
example.mcfunction
function my_block with storage example:arguments {}
my_block.mcfunction
$say Hello, $(input)!