Skip to content
This repository was archived by the owner on Dec 20, 2022. It is now read-only.

Language reference: vocabulary

Keheck edited this page Mar 24, 2020 · 8 revisions

The point of the language vocabulary is to give you every command that exists.

Table of contents:

  1. Vanilla Commands

1.1. Run a vanilla command

  1. Variables

2.1. Creating a variable

2.2. Variable operations

  1. Functions

3.1. Running a single function

3.2. Running a function alias

  1. Block variables

4.1. Creating a block variable

4.2. Setting the block type

4.3. Appending and prepending a value to an array

4.4. Inserting a value into an array

  1. If/Unless Statements

5.1. Testing variable values

5.2. Testing block variables

  1. Tips and tricks

Vanilla commands

A vanilla command is a command that is executable in Minecraft

Run a vanilla command

run: [command]

example: run: setblock 1 2 3 minecraft:stone

Variables

Variables hold numerical values to be used for later on. In Minecraft, these variables are represented by scoreboard values.

Note: Since there is no way of knowing how the data pack will work, it can't do any variable checks (e.g. if it was declared or not)

Creating a variable

var: [name] = [value]

example: var: foo = 42

Variable operations

var: [name1] [operation] [name2]

name1: the name of the first operand

name2: the name of the second operand

operation: one of the following operations:

  1. =: assignment; assigns the value of the second operand to the value of the first operand
  2. +=: addition; adds the value of the second operand to the value of the first operand
  3. -=: subtraction; subtracts the value of the second operand from the value of the first operand
  4. *=: multiplication; multiplies the value of the first operand with the value of the second operand
  5. /=: division; divides the value of the first operand by the value of the second operand
  6. %=: modulus; divides the value of the first operand by the value of the second operand and assigns the remainder to the first operand
  7. >: greater than; assigns the value of the second operand if - and only if - the value of the first operand is the greater one
  8. <: less than; assigns the value of the second operand if - and only if - the value of the first operand is the smaller one
  9. >< value flip; assigns the value of one operand to the other

example: var: foo += bar

Note: performing operations with numbers are currently not possible. To work around this issue, you can do something like this (the variable foo was already created):

var: const = 42

var: foo *= const

Functions

Functions are the core element of data packs. They are a file with a list of commands that are all executed in one tick

Running a single function

fnc: [namespace]->[name]

namespace: The namespace the function is in (can be in a different data pack as well)

name: The name of the function

example: fnc: foo->bar

Running a function alias

fnc: [namespace]?[alias]

namespace: The namespace the alias is in

alias: the JSON file holding all the function names

example: fnc: foo?bar

Block variables

Block variables are used to hold coordinates of a position representing a block in Minecraft.

Note: block variables are only accessible in the function they were declared in.

Creating a block variable

blk: [name] = [x],[y],[z]

name: the name of the variable (can already be declared)

x/y/z: the coordinates

example: blk: foo = 420, 69, 42

Setting the block type

blk: [name].type=§[blockID]§[state]{nbt}

name: the name of the variable

blockID: a valid block id (just the id, no prefix. will be fixed in the next update)

state: a block state (1)

nbt: the nbt data of the block (1)(2)

(1) can be omitted

(2) has to be in JSON format (keys in quotes)

example 1: blk: foo.type = §furnace§[facing=north]{"BurnTime":42}

example 2: blk: foo.type = §stone§

Appending and prepending a value to an array

blk: [name][path][operation][value]

name: The block variable

path: The nbt path

operation: One of these options

  1. ->: Appends a value
  2. <-: Prepend a value

value: The value to append

example 1: blk: foo.bar -> 42

example 2: blk: foo.bar[0].arr <- {"hello":"world"}

Note: If the appended value is in nbt/json format, keys must be written in quoutes as well. Also, numbers can't have identifiers, i.e. "s", "L", "f" or "d", since they are not valid in json.

Inserting a value into an array

blk: [name][path][index]+=[value]

name: The block variable

path: The path to the array

index: The index to insert into

value: The value to append

example: blk: foo.arr[2] += 42

Note 1: If the appended value is in nbt/JSON format, keys must be written in quotes as well. Also, numbers can't have identifiers, i.e. "s", "L", "f" or "d", since they are not valid in JSON.

Note 2: Inserting means that 1 is added to all indices at the given index and all following ones and then the value is inserted into the index

if/unless statements

If/Unless statements are control structures that execute the corresponding instructions if/unless, and only if/unless, the given condition is met. An "If" statement executes its instructions when the condition is true, and an "Unless" statement executes its instructions when the condition is false

Testing variable values

if/unless([variable1][operation][value/variable2])

variable1: the left side of the condition

operation: One of the given options

  1. =: equality; is true when the given values are equal
  2. >=: greater than or equal; is true when the left side is greater than or equal to the right value
  3. <=: less than or equal; is true when the left side is less than or equal to the right value
  4. <: less than; is true when the left side is less than the right side
  5. >: greater than; is true when the left side is greater than the right side

variable2: the left side of the condition

value: a numerical value

Example: if(foo = 42)

Note: all statements that need to execute when the "if/unless" condition is met need to be in curly brackets:

if(foo = 42)
{
    var: foo = 69
    blk: a = 2, 4, 6
}

Testing block variables

if/unless([block]=§[blockID][state]{nbt}§)

block: The name of the block variable

blockID: expected block id

state: the expected block state (can be omitted)

nbt: the expected nbt data (can be omitted)

Example: if(foo=§furnace§[facing=north]{CookTime:42}

Tips and tricks

  1. To access variables via the "run" command, you need to reference the scoreboard "vars" (ex. "run: scoreboard players set foo vars 42