Skip to content
This repository was archived by the owner on Nov 3, 2024. It is now read-only.

The mc language

SnaveSutit edited this page Nov 24, 2020 · 11 revisions

Contexts

  • Folder context refers to where functions and directories can be defined.
  • Function context refers to syntax inside of functions where commands can be written.
  • Macro context refers to the folder context inside of .mcm files
#!foo.mc
# Folder context
dir {
    # Folder context
    function bar {
        # Function context
        say Hello
    }
}
# Folder context
function bas {
    # Function context
    say World!
}

Functions

You can create functions using the function keyword:

function foo {
    say I am called via `function mc_file_name:foo`
}

Functions can only be defined within Folder context

Directories

You can create sub directories using the dir keyword:

dir foo {
    function bar {
        say I am called via `function mc_file_name:foo/bar`
    }
    dir bar {
        function bas {
            say I am called via `function mc_file_name:foo/bar/bas`
        }
    }
}

Directories can only be defined within Folder context

Function Blocks

Function blocks are used to define groups of commands that will be wrapped up into a function on compile-time.

Using the block keyword will define a block and inline the generated function call:

block {
    scoreboard players set @s value 1
    tellraw @s {"score":{"objective":"value","name":"@s"}}
}
# When this compiles it will inline something similar to this:
# function mc_file_name:__generated__/block/0

# The block keyword can be omitted, but recommended for readability in most cases.
# This will compile the same as above
{
    scoreboard players set @s value 1
    tellraw @s {"score":{"objective":"value","name":"@s"}}
}

Function blocks can also be defined at the end of execute commands:

execute if score @s value matches 1 run block {
    tellraw @s "Value is 1"
}
# When this compiles it will inline something similar to this:
# execute if score @s value matches 1 run function mc_file_name:__generated__/execute/0

# Again the block keyword can be omitted:
execute if score @s value matches 1 run {
    tellraw @s "Value was 1"
    scoreboard players set @s value 0
}

Keep in mind that if you do not omit the block keyword after an execute command it will always define a function, even if the block only contains a single command. If omitted and only 1 command is inside the block instead of making a function it will just append that command to the end of the execute command. For example:

execute if score @s value matches 1 run {
    tellraw @s "Value is 1"
}

Would compile to execute if score @s value matches 1 run tellraw @s "Value was 1"

Function blocks can also be named using the name keyword:

block {
    name foo
    say hi
}

This allows for manual naming to remove the __generated__ folders from your datapack if you so choose.

Function blocks can only be defined and used within Function context

Clocks

Clocks are an easy way of running a function every set increment of time. For instance you could create a clock that runs every 5 seconds like this:

clock 5s {
    say I run every 5 seconds!
}

the time argument takes a schedule command time input (5s, 10t, 1d)

Clocks can only be defined and used within Folder context

Clone this wiki locally