Writing
HomeWritingDocumentation

Datapack Compiler & EMCL Documentation


Version: 1.0Revised: 17th January, 2020by Morgan

Introduction

The Datapack Compiler converts EMCL (Extended Minecraft Command Langauge) into minecraft function files, offering support for better control flow, mathematical operations, and data types
Here is a sample application that plots 3D graphs using armor stands.

This documentation will explain the syntax for EMCL.
The compiler is currently in alpha, so bugs are to be expected. Feel free to report them to Heledron@gmail.com, or through the official reddit thread.

1. Comments


Comments can be used to document code. They are ignored by the compiler.

Single line comments begin with two forward slashes ( // ).
Multil line comments begin with /* and end with */.
// This is a comment /* This is a multi-line comment. Stuff I write here will not affect the program. */

2. Variables


Variables store values. Their values can be modified throughout the program.

Currently, the avalible data types are:

Declaration:

To declare a variable, specify the type, name and value.
int myVariable = 1;

It is also valid to declare a variable without specifying a value.
int myVariable;

Assignment:

To modify a variable, you can override its existing value.
myVariable = 3;

3. Maps


Maps are a special type of variable. They can store multiple values corresponding to minecraft target-selectors. To declare a map, use the following syntax:
int myMap{};

To modify a value inside a map, use a subscript.
myMap.abc = 1; // 'abc' will be used as the target

You can also use a valid in-game target selector as a subscript by writing it as a string.
// '@e[type=minecraft:armor_stand' will be used as the target // this will set the score of all armor stands to 3. myMap["@e[type=minecraft:armor_stand"] = 3;


4. Expressions and operations


Mathematical operators

Operators are used to perform operations on variables and constants.
Some examples of operators are +, -, *, / for addition, subtraction, multiplication, and division respectively.
myVariable = 10 + 2; // same as myVariable = 12 myVariable = 10 - 2; // same as myVariable = 8 myVariable = 10 * 2; // same as myVariable = 20 myVariable = 10 / 2; // same as myVariable = 5

It is also possible to use variables in expressions, or chain multiple operations together to create complex expressions.
int a = 100; int b = a * 10 / (2+3);

Operators have precedence. That means some operators will be executed first.

Here is a list of operators:
OperatorDescriptionExampleReturns
+Additiona+bResult of operation
-Subtractiona-bResult of operation
*Multiplicationa*bResult of operation
/Divisiona/bResult of operation
%Modulusa%bResult of operation

5. Assignment Operators


Assignment operators modify the value of a variable. In the example below, myVariable is increased by 10.
myVariable += 10 // increased myVariable by 10

Assignment operators return the value of the variable after the operation.
b = 3; b += (a = 4); // same as a = 4, b = 7

Here is a list of assignment operators:
OperatorSyntaxSame as
=a = ba = b
+=a += ba = a + b
-=a -= ba = a - b
*=a *= ba = a * b
/=a /= ba = a / b
%=a %= ba = a % b
++a++a = a + 1
++a++a = a - 1

6. Logical Operators and Control flow


An expression is known to be 'truthy' if it is not equivalent to to 0.

Conditional operators

Conditional operators return 'true' if a condition is satisfied. Here is a list of conditional operators:

OperatorSyntaxDescription
==a == bReturns true if a is equal to b, false otherwise.
!=a != bReturns true if a is not equal to b, false otherwise.
<a < bReturns true if a is less than b, false otherwise.
<=a <= bReturns true if a is less than or equal to b, false otherwise.
>a > bReturns true if a is greater than b, false otherwise.
>=a >= bReturns true if a is greater than or equal to b, false otherwise.

Logical operators

Logical operators deal with the truthiness of values. Here is a list of logical operators:

Operator Syntax Description
&& a && b Returns true if both a and b are truthy, false otherwise.
|| a || b Returns true if either a or b are truthy, false otherwise.

if statements

if statements will run a block of code if an expression is truthy.
int a = 1; if (a) { // code in here will run, as a is truthy } int b = 0; if (b) { // code in here will not run, as b is not truthy }

if else statements

if else statements will run the first block of code if an expression is truthy, and the second block if it is not.
int a = 1; if (a) { // code in here will run } else { // code in here will not run } int b = 0; if (b) { // code in here will not run } else { // code in here will run }

while loops

while loops will repeatedly run a block of code until the condition is no longer satisfied.
int a = 0; while (a < 10) { // this will run 10 times. a++; }

for loops

for loops accept 3 statements. The first statement runs before the loop. The second is the condition for the loop. The third statement will run after each iteration of the loop.
for (statement 1; statement 2; statement 3) { // code block }
for (int a = 0; a < 10; i++) { // this will run 10 times. }

7. Functions


Functions can be used to call recurring blocks of code.
They are declared like so:
void myFunction() { // do stuff... }
Only void-type functions are supported at the moment.
Functions can be invoked like so:
myFunction();

8. Commands


Syntax

To insert a minecraft command, precede the command with a forward slash ( / ).
/tellraw @a "Hello World!";
Here is an example in context:
for (int i = 0; i < 10; i++) { // this command will run 10 times. /tellraw @a "Hello World!"; }

Interpolation

The compiler will interpolate certain patterns in commands based on your output configuration.
To reference a variable, insert the variable name between ${ and }.
This is better than referencing the variable directly, as changes you make in the configurations will be reflected in the outputted code.
/command ${x};
To reference the container objective, use this pattern: ${!o}
To reference the float scale, use this pattern: ${!f}
To reference the inverse of the float scale, use this pattern: ${!nf}
To reference the namespace, use this pattern: ${!n}

Interpolation Examples:

This will set the score of all players to 100 for the objective 'abc'.
int x = 100; /scoreboard players operation @a abc = ${x} ${!o}
This will set the y position of all armor stands to yPosition (55.5).
float yPosition = 55.5; /execute as @e[type=minecraft:armor_stand] store result entity @s Pos[1] double ${nf} run scoreboard players get ${yPosition} ${!o};
All possible and potential rights reserved. Should you have any concerns, feel free to contact me at Heledron@gmail.com.
Heledron