Command Block

A command block is a block that can execute commands. Because it cannot be obtained or edited in Survival mode without cheats, it is primarily used on multiplayer servers and in custom maps.

Obtaining
Command blocks are not available in the Creative inventory. It can either be obtained by using the control, or by using various commands, such as, or.

$$, just like other blocks that can store NBT data, using +  copies the command and options inside the command block. This allows it to be placed elsewhere without having to re-enter the data inside.

Command blocks also cannot be broken in Survival mode without operator permissions, are not flammable, cannot be moved by pistons, and have the same blast resistance as bedrock.

Info
A command block can execute commands when activated by redstone power. It always has permissions of 2 level, so it can be used to allow a specific use of a command by players who can't use that command in general (for example, allowing anyone to obtain a specific item with without allowing everyone to /give themselves whatever they want).

A command block has an orientation that determines the chain command block to activate, and the blocks to be checked to see if a command block in "Conditional" mode executes.

To execute the command, $$ in multiplayer  in the server.properties file must be set to   (default is  ); $$ "Command Blocks Enabled" in options must be enabled.

Modification


To enter command or modify the command block, use the control on the command block to open the command block GUI (graphical user interface). The GUI opens only if the player is in Creative mode, and has the proper permissions. That means, in singleplayer, "Allow Cheats" or "Activate Cheats" in options must be enabled. In multiplayer, Gui can be opened only by operators in Creative mode, and $$  in the server.properties file must be set to   or above (default is 4).

$$ to enter command or modify the command block,  in the server.properties file must be set to   (default is  ).

$$, opening the GUI in singleplayer pauses the game.


 * Console Command

Commands can be entered in the top text pane. The text limit for commands in a command block is 32,500 characters, but the text pane can show only a small portion of this amount at a time.

Press to complete words or cycle through options.

Commands in a command block do not need to be prefixed with the forward-slash as they do in the chat window, but doing so still works.

$$, below the console command text pane are some reminder tips about how to use target selectors.


 * Previous Output

The bottom text pane displays the output message (success or failure) of the last executed command (initially blank). Its text is not editable.

A button to the right of the Previous Output text pane or the left of the "Previous Output" specifies whether the last output should be stored and displayed. It is /enabled when the output should be stored and  /disabled when the output should not be stored. For worlds with many command blocks, especially command blocks running on fast clocks, not storing the output text can reduce memory and storage requirements.

If gamerule  is true (the default), default to  /enabled. Otherwise defaults to /disabled.


 * Block Type


 * Click the "Impulse/Chain/Repeat"/"Block Type" button to change the command block's type. The default state is "Impulse", but non-default command blocks can be placed. The command block also changes color when changing its command block type:


 * "Impulse" command blocks are orange. These execute once every time they are activated.
 * "Chain" command blocks are green. These execute once every time they are triggered if they have been activated.
 * "Repeat" command blocks are purple. These execute their commands once every one game tick (or more) as long as they are activated.


 * Condition


 * Click the "Conditional/Unconditional"/"Condition" button to change the command block's conditional behavior:
 * "Conditional": A command block in conditional mode executes its command only when the command block behind it has executed successfully ("Succeess count" is more than 0).
 * "Unconditional" (default): A command block in unconditional mode executes its command even if there's a command block behind it that didn't execute its command successfully.
 * "Behind it" in the sense of opposite to the direction the command block is facing, regardless of chain direction or even if chaining is occurring.


 * Redstone


 * Click the "Always Active/Needs Redstone"/"Redstone" button to change the command block's activation requirements:
 * "Needs Redstone" (the default for impulse and repeat command blocks): A command block in the "Needs Redstone" setting can be activated only with redstone.
 * "Always Active" (the default for chain command blocks): The command block is activated when set to "Always Active". Then it is always active even without redstone activation.


 * Execute on Tirst Tick


 * Specifies whether a repeating command block executes its command as soon as it is activated. If it's disabled, executes the first time after the delay from the time when it is activated.


 * Delay in Ticks


 * For impulse or chain command block, specifies how many game ticks it will delay to execute command after it is activated or triggered.
 * For repeat command block, specifies how many game ticks it will delay to execute again.


 * Hover Note


 * Specifies the name of command block, which can be seen when you point to the block. It is also used for message commands. If the command block had been named in an anvil before placement, that name is used as well. If it is empty, defaults to.


 * Done


 * $$, click the "Done" button or to save the command and leave the command block GUI.
 * $$, close the GUI to save the command.


 * Cancel


 * Click the "Cancel" button or to leave the command block GUI without saving any changes.

Activation
Command blocks are redstone mechanisms and can be activated by:
 * An adjacent active power component: for example, a lever, a block of redstone, a daylight sensor, a button etc.
 * An adjacent powered block (for example, an opaque block with an active redstone torch under it)
 * A powered redstone comparator or redstone repeater facing the mechanism component
 * Powered redstone dust configured to point at the command block (or on top of it) or directionless; a command block is not activated by adjacent powered redstone dust that is configured to point away from it.

A command block can also be activated by setting to "Always Active" mode.

When activated, a command block tries to execute its command, depending on the command block's type:
 * a command block ("Impulse") tries to execute its command once
 * a chain command block ("Chain") does not try to execute its command until be triggered.
 * a repeating command block ("Repeat") tries to execute its command once every one game tick (or more) until no longer activated.

Trigger and chainning
If any command block having tried execution faces an activated chain command block, it triggers the chain command block to also attempt execution. The chain command block executes its command only when it has been activated and, if in "Conditional" mode, when the command block behind it executed successfully (behind in the sense of the direction it is facing, not in the sense of which command block chained to it). Whether or not the chain command block has been activated or executes successfully, if it is facing another chain command block, it triggers that block to attempt execution also.

Chained command blocks execute simultaneously in the same game tick in the order they are chained. Chained execution cannot be passed to a command block that has already executed in that game tick (loops execute only once).

If the chain command block has been activated, it also updates its success count: If in "Conditional" mode, when the command block behind it didn't executed successfully, sets success count to 0. Otherwise, sets to the success count of the command.

Execution
For a impulse command block, when it is activated, checks whether the command block behind it has executed successfully (if in conditional mode). After 1 gametick (or more), if condition met, tries executing its command once.

For a chain command block, if it has been activated, tries executing its command once as soon as it is triggered.

For a repeat command block, when it is activated, after 1 gametick (or more), checks whether the command block behind it has executed successfully (if in conditional mode). If condition met, tries executing its command once. Then checks and tries executing again after 1 gametick (or more).

When tries executing a command, checks whether it has been already executed in this game tick. If not, executes the command. Then triggers chain command block it pointing to no matter whether the command is executed or not.

In addition:
 * When an impulse or repeat command block in "Needs Redstone" mode with command is placed, or be cloned by a command to a powered location, the new command block tries executing its command only if it hasn't been activated with redstone. $$, it also needs a block update in order to execute its command.
 * When an impulse or repeat command block in "Always Active" mode with command is placed, or be cloned by a command to a powered location, the new command block tries executing its command only if it hasn't been activated with redstone.
 * When an impulse or chain command block is set to "Repeat", if it has been activated, checks whether the command block behind it has executed successfully (if in conditional mode). After 1 gametick (or more), if condition met, tries executing its command once. Then checks and tries executing again after 1 gametick (or more).

Output
When activated, a command block can produce multiple types of output:

Success count

 * A command block can power a redstone comparator facing away from it (possibly separated by a block) with signal strength specific to the success count.


 * The signal strength always reflects the last command executed, even after the command block is deactivated.


 * $$, leaving the command block GUI with clicking the "Done" button or resets the success count to 0, no matter whether making changes in the GUI. $$, leaving the GUI with changes resets the success count to 0.

Message

 * The output message describes the success or failure of the executed command, and may be written to multiple destinations:


 * Previous Output: The output message is always written to the "Previous Output" text pane of the command block GUI.


 * Chat: The output message is written to the chat text in singleplayer mode, or broadcast to all other ops in multiplayer mode, unless it has been suppressed with . Some commands may write additional text to the chat as their normal function, which won't be suppressed (for example, the command writes a message to the chat of all players), separate from the output message. Chat messages that would usually be prefaced by a player's name (such as from the,  and  commands) use    /    as the player name. If the command block had been named in an anvil before placement, that name is used instead. $$, it can also modified in the GUI.


 * Logs: The output message is written to multiplayer server logs unless it has been suppressed with.

Easter eggs
Running "Searge" (case insensitive) as the command in the command block without a preceding " " now set the previous output to "#itzlipofutzli". Its success count is 1.

ID




Block data
$$, a command block's block data specifies whether the command block is currently activated.

Block entity
A command block has a block entity associated with it that holds additional data about the block.