Skip to content

Command IR Instruction Reference

Simon816 edited this page Jun 9, 2019 · 8 revisions

Summary

Instructions

Basic Commands and Instructions

as_single_cmd

<ret> = as_single_cmd <block>

Forces a basic block to become a single command, the command is returned as a command variable. An error is raised if the block cannot be a single command.

block: BasicBlock The basic block

ret: CmdFunction


bar_set_max

bar_set_max <bar>, <max>

Sets the maximum value for a bossbar.

bar: BossbarRef Bar to modify

max: int Max value


bar_set_players

bar_set_players <bar>, <players>

Set the players who can see the bossbar.

bar: BossbarRef Bossbar

players: Opt(EntitySelection) Players. If NULL then no players will be shown the bar


bar_set_value

bar_set_value <bar>, <val>

Sets the current value of the given bossbar.

bar: BossbarRef Bossbar to modify

val: int Bar value


clear

clear <targets>, <item>, <max_count>

Clears items matching the given item type from targetted entities.

targets: EntitySelection Entities to clear the item from

item: ItemType Item to clear

max_count: int Max count of items. -1 to clear all matching items.


clone

clone <src0>, <src1>, <dest>

Clones a region of blocks specified by a lower left and upper right bound to a given destination position.

src0: Position Lower left position

src1: Position Upper right position

dest: Position Destination position


getter

<ret> = getter <var>

Returns a command variable that when run, gives the variable's value in the 'result' of the command's execution.

var: Variable The variable to create the getter for

ret: CmdFunction


give

give <targets>, <item>, <count>

Gives targetted entities an item.

targets: EntitySelection Entities to give the item to

item: ItemType The item to give

count: int Item count


give_effect

give_effect <target>, <effect>, <seconds>, <amp>, <hide_particles>

Gives target entities the specified effect. See /effect for details.

target: EntitySelection Entities to give the effect to

effect: VirtualString The effect name

seconds: Opt(int) Number of seconds the effect will last

amp: Opt(int) Amplifier

hide_particles: Opt(str) Whether to hide particles (true|false)


join_team

join_team <team>, <members>

Adds the specified entities to the given team.

team: TeamRef The team to join

members: Opt(EntitySelection) Members joining the team. If NULL then the current command sender is added.


kill

kill <target>

Despawns the target entities from the world.

target: EntitySelection Entities to despawn


move_to_entity

move_to_entity <sources>, <target>

Moves entities to another target entity.

sources: EntitySelection Entities to move

target: EntitySelection Destination entity


replace_block_item

replace_block_item <pos>, <slot>, <item>, <amount>

Replaces an item in a block's inventory at a specified slot with the given item. See /replaceitem for details.

pos: Position Block position

slot: VirtualString Inventory slot

item: ItemType Replacement item

amount: Opt(int) Replace amount


replace_entity_item

replace_entity_item <target>, <slot>, <item>, <amount>

Replaces an item in an entity's inventory at a specified slot with the given item. See /replaceitem for details.

target: EntitySelection Target entities to replace their items

slot: VirtualString Inventory slot

item: ItemType Replacement item

amount: Opt(int) Replace amount


run_cmd

run_cmd <cmd>

Runs the command given in the command variable.

cmd: CmdFunction The command variable


set_title_times

set_title_times <player>, <fade_in>, <stay>, <fade_out>

Sets the timer parameters for a title being shown to the player.

player: EntitySelection Players to set the times on

fade_in: int Title fade in time

stay: int Title stay time

fade_out: int Title fade out time


setblock

setblock <pos>, <block>

Sets a block in the world at the given position to the given block type.

pos: Position The block position

block: BlockType The block type


spawn_entity

spawn_entity <entity>, <pos>, <data>

Spawns an entity of the given type at a position.

entity: VirtualString Entity type name

pos: Opt(Position) Position. Defaults to the location of the sender

data: Opt(NBTCompound) Optional NBT data for the entity


spawn_particle

spawn_particle <name>, <pos>, <delta>, <speed>, <count>, <mode>, <targets>

Spawn particle effects with the given parameters. See /particle for details.

name: VirtualString Particle name

pos: Position Position to spawn at

delta: Position Volume to spawn in

speed: float Speed of the particle

count: int Number of particles

mode: str Display mode (normal|force)

targets: Opt(EntitySelection) Players to show the particles to


team_collision

team_collision <team>, <behaviour>

Sets the collision behavious for a given team.

team: TeamRef Team to modify

behaviour: str Collision behaviour


team_color

team_color <team>, <color>

Sets the color for a team.

team: TeamRef Team to modify

color: TextColor Color of the team


teleport

teleport <target>, <pos>

Moves target entities to a specified position.

target: EntitySelection Entities to move

pos: Position Position to move to


title

title <player>, <action>, <text>

Show a title text to the specified players.

player: EntitySelection Players to show to

action: str 'clear' or 'reset', otherwise title|subtitle|actionbar

text: Opt(TextObject) Text to show


tp_with_rot

tp_with_rot <target>, <pos>, <yrot>, <xrot>

Moves entities to the given position with a specific rotation.

target: EntitySelection Entities to move

pos: Position Position to move to

yrot: (int|float|RelPosVal|AncPosVal) y rotation

xrot: (int|float|RelPosVal|AncPosVal) x rotation


Control Flow

branch

branch <label>

Unconditionally branch to the given label.

label: BasicBlock Destination to branch to


call

call <label>

'calls' a label instead of branching. The label must be tagged with the 'function' modifier. Control will resume to the next instruction after the label has been executed.

label: BasicBlock Label tagged as a function


clear_command_block

clear_command_block

Remove any value from the special command block.


cmpbr

cmpbr <left>, <op>, <right>, <if_true>, <if_false>

Compare two variables and jump depending on the comparison.

left: Variable Left variable

op: str Operator for comparison, one of: lt|le|eq|ge|gt

right: Variable Right variable

if_true: Opt(FunctionLike) Label to branch if true

if_false: Opt(FunctionLike) Label to branch to otherwise


get_stack_head

get_stack_head <dest>

Copies the head of the global stack into the given variable. Do not use in normal circumstances, instead use paramteter passing.

dest: Variable Variable to copy into


invoke

invoke <func>, <fnargs>, <retvars>

Invokes a function.

func: VisibleFunction Function to invoke

fnargs: Opt(tuple) Parameters to pass to the function

retvars: Opt(tuple) Tuple of Variables to place return values into


pop_stack

pop_stack

Removes the head of the global stack. Do not use in normal circumstances, instead use parameter passing.


push_function

push_function <func>

Push a function pointer to the top of the global stack.

func: FunctionLike Function to push


push_stack_frame

push_stack_frame <framevals>

(Internal) Create a new stackframe.

framevals: tuple Frame content


push_stack_val

push_stack_val <value>

Push a value to the top of the global stack.

value: (Variable|int) Value to push


rangebr

rangebr <var>, <min>, <max>, <if_true>, <if_false>

Branch to a label depending on the value of a variable.

var: Variable Variable to test

min: Opt(int) Minimum value, or NULL for negative infinity

max: Opt(int) Maximum value, or NULL for positive infinity

if_true: Opt(FunctionLike) Label to jump to if min <= var <= max

if_false: Opt(FunctionLike) Label to jump to otherwise


ret

ret

Return from a function.


set_command_block

set_command_block <func>

Sets the special command block to run the given function on the next tick.

func: FunctionLike Function to run


set_command_block_from_stack

set_command_block_from_stack

Copies the value from the top of the stack into the special command block.


Events

add_event_condition

add_event_condition <event>, <path>, <value>

Add a condition to an event that must be true for the event handler to be invoked.

event: EventRef Event to add the condition to

path: VirtualString JSON path in the advancement

value: VirtualString Value that must match


event

<ret> = event <event_name>

Creates a new event object.

event_name: VirtualString The event name

ret: EventRef


event_handler

event_handler <handler>, <event>

Add an event handler to the given event specification.

handler: IRFunction Event handler

event: EventRef Event


extern

extern

Marks the function as externally visible. The function will not be removed during optimization.


revoke_event_adv

revoke_event_adv <func>

(Internal) Revokes an advancement to allow an event to re-fire.

func: IRFunction Handler


setupfn

setupfn <func>

Tags a function as being part of the setup phase. It is called whenever the datapack is reloaded.

func: VisibleFunction The setup function


Execute Instructions

exec_align

exec_align <chain>, <axes>

Executes the rest of the chain with the position aligned to the given axes. See /execute align for details.

chain: ExecChain Execute chain

axes: str Axes


exec_anchor

exec_anchor <chain>, <anchor>

Execute the rest of the chain with the anchor position (^) fixed to either feet or eyes of the current entity.

chain: ExecChain Execute chain

anchor: str 'feet' or 'eyes'


exec_as

exec_as <chain>, <target>

Executes the rest of the chain for each entity matching the given selection, changing @s to refer to the current matching entity.

chain: ExecChain Execute chain

target: EntitySelection Entities to iterate over


exec_at_entity

exec_at_entity <chain>, <target>

Executes the rest of the chain for each entity matching the given selection, changing the relative position, rotation and dimension to originate from the matching entity.

chain: ExecChain Execute chain

target: EntitySelection Entities to iterate over


exec_at_entity_pos

exec_at_entity_pos <chain>, <target>

Executes the rest of the chain using just the position of each matching entity.

chain: ExecChain Execute chain

target: EntitySelection Entities to iterate over


exec_at_pos

exec_at_pos <chain>, <pos>

Executes the rest of the chain from the given position.

chain: ExecChain Execute chain

pos: Position Position


exec_face_entity

exec_face_entity <chain>, <target>, <feature>

Executes the rest of the chain with a rotation that faces the given target entity's feature.

chain: ExecChain Execute chain

target: EntitySelection Target entity to face

feature: str 'eyes' or 'feet'


exec_face_pos

exec_face_pos <chain>, <pos>

Executes the rest of the chain with a rotation that faces the given position.

chain: ExecChain Execute chain

pos: Position Look position


exec_finish

exec_finish <exec>

Finishes an execute chain without running an action. Used when only interested in whether a conditional matched or not.

exec: ExecChain Execute chain


exec_if_block

exec_if_block <chain>, <pos>, <block>

Only execute the rest of the chain if the given block specification matches.

chain: ExecChain Execute chain

pos: Position Block position

block: BlockType Block type to test for


exec_if_blocks

exec_if_blocks <chain>, <begin>, <end>, <dest>, <type>

See /execute if blocks.

chain: ExecChain Execute chain

begin: Position Begin position

end: Position End position

dest: Position Test position

type: str all or masked


exec_if_cmp

exec_if_cmp <chain>, <left>, <op>, <right>

Executes the rest of the chain if the left variable relates to the right variable using the given operation.

chain: ExecChain Execute chain

left: Variable Left variable

op: str Operator, one of: lt|le|eq|ge|gt

right: Variable Right variable


exec_if_entity

exec_if_entity <chain>, <target>

Execute the rest of the chain if at least one entity is found matching the given selection.

chain: ExecChain Execute chain

target: EntitySelection Entities


exec_if_var

exec_if_var <chain>, <var>, <min>, <max>

Execute the rest of the chain if the given variable is within the given bounds.

chain: ExecChain Execute chain

var: Variable Variable

min: Opt(int) Minimum value, or NULL for negative infinity

max: Opt(int) Maximum value, or NULL for positive infinity


exec_rot_entity

exec_rot_entity <chain>, <target>

Executes the rest of the chain with the rotation equivalent to the rotation of the given entity.

chain: ExecChain Execute chain

target: EntitySelection Entities to execute with the rotation of


exec_rotate

exec_rotate <chain>, <y>, <x>

Executes the rest of the chain with the given rotation.

chain: ExecChain Execute chain

y: (int|float|RelPosVal) Y rotation

x: (int|float|RelPosVal) X rotation


exec_run

exec_run <exec>, <func>

Finishes the execute chain by running either a command variable, a function label, or a function that takes no parameters.

exec: ExecChain Execute chain

func: (CmdFunction|FunctionLike) Function or command to run


exec_store

exec_store <chain>, <storetype>, <spec>

Adds an execute store component to the execute chain.

chain: ExecChain Execute chain

storetype: str Either result or success

spec: ExecStoreSpec Execute store specificaion


exec_store_bar

<ret> = exec_store_bar <bar>, <attr>

Creates an execute store specification that stores into a bossbar.

bar: BossbarRef Bossbar to store into

attr: str Attribute to store into, either 'value' or 'max'

ret: ExecStoreSpec


exec_store_entity

<ret> = exec_store_entity <target>, <path>, <nbttype>, <scale>

Create an execute store specification that stores into an entity's NBT.

target: EntitySelection Target entity

path: VirtualString NBT path

nbttype: NBTType NBT type

scale: (int|float) Scale before storing

ret: ExecStoreSpec


exec_store_var

<ret> = exec_store_var <var>

Creates an execute store specification that stores into a variable.

var: Variable Variable to store into

ret: ExecStoreSpec


exec_unless_block

exec_unless_block <chain>, <pos>, <block>

Only execute the rest of the chain if the given block specification doesn't match.

chain: ExecChain Execute chain

pos: Position Block position

block: BlockType Block type to test for


exec_unless_blocks

exec_unless_blocks <chain>, <begin>, <end>, <dest>, <type>

See /execute unless blocks.

chain: ExecChain Execute chain

begin: Position Begin position

end: Position End position

dest: Position Test position

type: str all or masked


exec_unless_cmp

exec_unless_cmp <chain>, <left>, <op>, <right>

Executes the rest of the chain if the left variable doesn't relate to the right variable using the given operation.

chain: ExecChain Execute chain

left: Variable Left variable

op: str Operator, one of: lt|le|eq|ge|gt

right: Variable Right variable


exec_unless_entity

exec_unless_entity <chain>, <target>

Execute the rest of the chain if no entity is found to match the given selection.

chain: ExecChain Execute chain

target: EntitySelection Entities


exec_unless_var

exec_unless_var <chain>, <var>, <min>, <max>

Execute the rest of the chain if the given variable is not within the given bounds.

chain: ExecChain Execute chain

var: Variable Variable

min: Opt(int) Minimum value, or NULL for negative infinity

max: Opt(int) Maximum value, or NULL for positive infinity


execute

<ret> = execute

Create a new execute chain.

ret: ExecChain


NBT Instructions

nbt_assign

nbt_assign <var>, <nbt>

Sets NBT data on the given variable (which must have type 'nbt').

var: Variable Variable to set the value on

nbt: NBTBase NBT value


nbt_compound

<ret> = nbt_compound

Creates a new NBT compound.

ret: NBTCompound


nbt_compound_set

nbt_compound_set <var>, <name>, <val>

Sets a key to the given NBT value in a compound tag.

var: NBTCompound Compound to set on

name: str Key

val: NBTBase Value


nbt_data_getter

<ret> = nbt_data_getter <target>, <path>, <scale>

Creates a command variable that when called, sets the 'result' value to whatever the value at the path is in a block or entity.

target: (BlockRef|EntitySelection) Block or entity to retrieve the value from

path: VirtualString NBT path to the value

scale: float Scale the result before returning

ret: CmdFunction


nbt_data_merge

nbt_data_merge <target>, <data>

Merge the given NBT compound with a block or entity.

target: (BlockRef|EntityRef) Block or entity to merge with

data: NBTCompound Compound tag holding values to merge into the target


nbt_list

<ret> = nbt_list <list_type>

Creates a new NBT list of the given element type.

list_type: Opt(NBTType) Type of elements. NULL leaves the list with an unknown type

ret: NBTList


nbt_list_append

nbt_list_append <list>, <value>

Appends the given NBT value to an NBT list.

list: NBTList List to append to

value: NBTBase Value to append. The value type must be compatible with the list's element type


nbt_modify_from

nbt_modify_from <target>, <target_path>, <action>, <source>, <source_path>

Modify a block or entity at the given NBT path, performing the given action, choosing the value from a path in another block or entity.

target: (BlockRef|EntitySelection) Block or entity to modify

target_path: VirtualString NBT path to modify

action: str Action, one of: append|insert|merge|prepend|set

source: (BlockRef|EntitySelection) Source entity or block

source_path: VirtualString Path in source


nbt_modify_val

nbt_modify_val <target>, <path>, <action>, <source>

Modify a block or entity at the given NBT path, performing the given action, with the given NBT value.

target: (BlockRef|EntitySelection) Block or entity to modify

path: VirtualString NBT path to modify

action: str Action, one of: append|insert|merge|prepend|set

source: NBTBase Value


nbt_val

<ret> = nbt_val <type>, <value>

Creates an NBT value of the given NBT type and value.

type: NBTType NBT type

value: (NoneType|float|int|VirtualString) Value of this NBT component. Must be valid for the NBT type

ret: NBTBase


nbtsubpath

<ret> = nbtsubpath <root>, <path>, <vartype>

Create a derivative NBT variable from a sub-path of a parent NBT variable.

root: Variable Original variable

path: VirtualString subpath

vartype: VarType Type of the variable

ret: Variable


Variable Arithmetic Instructions

Variable assign

<var> = <value>

Sets a variable to a given value.

var: Variable Variable to set the value on

value: (int|Variable) Value to set


Variable operation

<dest> <op> <src>

Performs an operation on a destination variable using a source value. See /scoreboard for details on each operation.

Valid operations are:

+=

/=

%=

>

<

*=

-=

><

dest: Variable Destination for the operation

src: (int|Variable) Source for the operation


Text Instructions

text

<ret> = text

Creates a text object.

ret: TextObject


text_append

text_append <text>, <value>

Appends the given value to the text object.

text: TextObject Text to append to

value: (VirtualString|int|Variable|TextObject) Value to append


text_click_action

text_click_action <text>, <action>, <value>

Sets the click action on a text object.

text: TextObject Text object

action: str Action, one of: open_url|open_file|change_page

value: VirtualString Value of the action


text_click_func

text_click_func <text>, <action>, <func>

Sets the click action of a text object to run or suggest a function or command.

text: TextObject Text object

action: str Either run or suggest

func: (FunctionLike|CmdFunction) Function or command


text_send

text_send <text>, <target>

Sends a text object to target players.

text: TextObject Text to send

target: EntitySelection Players to send the text to


text_style

text_style <text>, <prop>, <val>

Sets a style property of a text object.

text: TextObject Text to change the style of

prop: str Style property

val: (str|VirtualString) Style value


Type Constructor Instructions

add_block_prop

add_block_prop <block>, <key>, <value>

Adds a property to the block reference.

block: BlockType Block

key: str Property name

value: VirtualString Property value


add_item_prop

add_item_prop <item>, <nbtprop>

Adds an NBT value to the item properties.

item: ItemType Item

nbtprop: NBTCompound NBT value


anc_pos

<ret> = anc_pos <val>

Creates a position component that is relative to the current anchor location (i.e. '^').

val: (float|int) Offset from anchor

ret: AncPosVal


block

<ret> = block <block_id>

Creates a block type reference.

block_id: VirtualString ID of the block

ret: BlockType


bossbar

<ret> = bossbar <name>, <display>

Creates a bossbar reference.

name: str Bossbar name

display: TextObject Display text

ret: BossbarRef


command

<ret> = command <cmd>

Creates a command variable out of a raw command string.

cmd: VirtualString Raw command string

ret: CmdFunction


define

<ret> = define <type>

Creates a local variable of the given variable type.

type: VarType Variable type

ret: Variable


entity_local_access

<ret> = entity_local_access <local>, <target>

Creates a variable whose value depends on the objective and target entities.

local: EntityLocal Scoreboard objective

target: EntitySelection Target entities

ret: Variable


global

<ret> = global <type>

Creates a global variable of the given variable type.

type: VarType Variable type

ret: Variable


item

<ret> = item <item_id>

Creates an item reference.

item_id: VirtualString Item ID

ret: ItemType


objective

<ret> = objective <name>, <criteria>

Creates a new objective reference, optionally with some criteria.

name: VirtualString Objective name

criteria: Opt(VirtualString) Criteria. If NULL then it will be 'dummy'

ret: EntityLocal


parameter

<ret> = parameter <type>

Add a required parameter of a given type to a function.

type: VarType Parameter type

ret: Variable


player_ref

<ret> = player_ref <name>

Creates a reference to a player name.

name: VirtualString Player name

ret: EntityRef


position

<ret> = position <x>, <y>, <z>

Create a position variable.

x: (int|float|RelPosVal|AncPosVal) X value

y: (int|float|RelPosVal|AncPosVal) Y value

z: (int|float|RelPosVal|AncPosVal) Z value

ret: Position


rel_pos

<ret> = rel_pos <val>

Create a position component that is relative to the sender (i.e. '~').

val: (float|int) Offset from sender

ret: RelPosVal


return

<ret> = return <type>

Define a variable to hold a return value of the given type for a function.

type: VarType Return type

ret: Variable


sel_nbt

sel_nbt <sel>, <path>, <val>

Adds an NBT specification to the selector. Candidate entities must have the NBT value specified in the given NBT value.

sel: Selector Selector

path: VirtualString Path to NBT, empty string is the root path

val: NBTBase Value that candidate entities must match


select_score_range

select_score_range <sel>, <score>, <min>, <max>

Adds a score range parameter to the selector.

sel: Selector Selector

score: EntityLocal Score

min: Opt(int) Minimum value, or NULL for negative infinity

max: Opt(int) Maximum value, or NULL for positive infinity


selector

<ret> = selector <type>

Creates a new selector object.

type: SelectorType Type of selector (a|e|s|p|r)

ret: EntitySelection


set_block_nbt

set_block_nbt <block>, <nbt>

Sets NBT data to a block reference.

block: BlockType Block

nbt: NBTCompound NBT value


set_selector

set_selector <sel>, <key>, <value>

Sets a selector key to the given value.

sel: Selector Selector

key: str Key

value: VirtualString Value


team

<ret> = team <name>, <display>

Creates a team reference.

name: str Team name

display: Opt(TextObject) Optional display text

ret: TeamRef

Clone this wiki locally