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, and have the same blast resistance as bedrock. Command blocks, structure blocks, and jigsaw blocks cannot be mined in survival.

Usage
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/Command Input


 * 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.


 * 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.


 * Press to complete words or cycle through options.


 * $$, 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 (it is blank or " " initially). 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 text should be stored and  /disabled when the output text 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 obtained and 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 ("Success count" is greater 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 First Tick


 * Specifies whether a repeat 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 delays before executing command after it is activated or triggered.
 * For repeat command block, specifies how many game ticks it delays to execute again.


 * Note that for impulse or repeat command block, 0 and 1 work the same; the game takes 0 as 1. However, For chain command block, 0 and 1 is different.


 * 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 and changes.


 * 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 executes its command, depending on the command block's type:
 * A impulse command block executes its command once.
 * A chain command block does not execute its command until it is triggered.
 * A repeat command block executes its command once every one game tick (or more) until no longer activated.

Execution
An impulse command block, when it is activated, checks whether the command block behind it has executed successfully (if in conditional mode). After the delay of 1 gametick (or more), if the condition is met before the delay (if in "Conditional" mode), it executes its command once and triggers the chain command block it is pointing to.

A repeat command block, when it is activated, after 1 gametick (always 1 no matter how many "Delay in Ticks" is), checks whether the command block behind it has executed successfully (if in conditional mode). If the condition is met, and if "Execute on First Tick‌" is enabled $$, it executes its command once and triggers the chain command block it is pointing to. If it is still activated, it then checks, executes, and triggers the chain command block again after 1 gametick (or more).

When executing a command, it also updates its success count: If in "Conditional" mode, if the command block behind it didn't execute successfully, it sets its success count to 0. Otherwise, it sets it to the success count of the command.

In addition:
 * When an impulse or repeat command block in "Needs Redstone" mode with a command is placed or is cloned by a command to a powered location, the new command block executes 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 a command is placed or is cloned by a command to a powered location, the new command block executes 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 (always 1 no matter how many "Delay in Ticks" is), if the condition is met, it executes its command once and triggers the chain command block it is pointing to. Then it checks, executes, and triggers the chain command block again after 1 gametick (or more).

Trigger and chaining
If any command block having executed its command (whether successfully or unsuccessfully) faces a chain command block, it triggers the chain command block to also attempt execution.

When a chain command block is triggered,
 * If it has been activated,
 * It checks whether it is in "Conditional" mode and the command block behind it hasn't executed successfully (Behind in the sense of the direction it is facing, not in the sense of which command block chained to it),
 * If true, it triggers another chain command block it is facing, without executing the command.
 * If false, it checks whether it has been already executed in this game tick. If false, it executes the command and triggers another chain command block it is facing. If true, it does nothing. That means that chained execution cannot be passed to a command block that has already executed in that game tick (loops execute only once).
 * If it has not been activated, it triggers the chain command block it is facing to attempt execution.

Chained command blocks execute simultaneously in the same game tick in the order they are chained.

$$, it can also delay before executing commands if "Delay in Ticks" is not 0:
 * When it is triggered,
 * If it has been activated, the chain command block checks whether the command block behind it has executed successfully (if in conditional mode), then it delays.
 * After delay, if the condition is met before the delay (if in "Conditional" mode), it executes its command once and triggers the chain command block it is pointing to no matter whether the condition met.
 * If it has not been activated, it triggers (without delay) the chain command block it is facing to attempt execution.

$$, it can execute multiple times in the same game tick if "UpdateLastExecution" is set to false. In this case, it does not check whether it has already executed in this game tick.

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

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. Success count is an integer between 0 to 2,147,483,647 (inclusive).


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


 * $$, success count is usually 0 or 1, except for and.


 * $$, success count is a integer related to command (e.g., the number of players affected by the command, the number of blocks that were altered, the value returned by the command, etc.)


 * $$, 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.

Piston interactivity
Command blocks cannot be pushed by pistons. They also cannot be pushed nor pulled by sticky pistons.

ID




Metadata
$$, a command block's block data specifies its orientation and condition mode.

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

History
{{History||1.6.1|snap=13w19a|Command blocks are no longer mineable in survival.
 * Command blocks are no longer damaged by explosions, except by blue [[wither81234567899012356899001358990

{{History||1.7.2|snap=13w37a|A bar that shows the previous output of command blocks has been added. {{History||1.8|snap=14w07a|Dispensers now place command blocks, instead of shooting them out.}} {{History|||snap=14w20a|The in-game character limit of 16,369 has been removed, allowing access to the full 32,767 characters.}} {{History|||snap=14w27a|Added CommandStats NBT tag to command blocks.}} {{History||1.8.6|Dispensers no longer place command blocks. }} {{History||1.9|snap=15w33a|The character limit for command blocks is now 32,500 instead of 32,767.}} {{History|||snap=15w34a| Added the chain command block and the repeating command block. {{History|||snap=15w34b|Added Conditional mode within command blocks. {{History|||snap=15w35a|  The textures of all three command blocks have been changed. {{History|||snap=15w36a|Players are now unable to use commands, such as {{cmd|give}}, within command blocks. {{History|||snap=15w36d|Each command block type now appears with different colors on maps.}} {{History|||snap=16w02a|Running {{cmd|help}} in a command block now randomly uses one of various different humorous phrases as the previous output.}} {{History|||snap=16w04a|Running "Searge" as the command in the command block without a preceding " " now sets the previous output to "#itzlipofutzli".}} {{History||1.11|snap=16w32a|The block entity ID has been changed from  to  .}} {{History||1.12|snap=17w16a|Chains of command blocks no longer schedule their commands to be run in the next tick. Instead, they now execute all in the same tick they are read. This allows later blocks in a chain to be modified via earlier blocks, allowing techniques like branching and looping, all in the same tick. {{History|||snap=17w17a|Added  and   NBT tags, which control the tracking of which tick a chain command block was last executed in.}} {{History|||snap=pre6|Tab-completing command names in command blocks no longer add a  prefix.}} {{History||1.13|snap=17w47a|Prior to The Flattening, the numeral IDs for the command block, repeating command block, and chain command block were 137, 210, and 211, respectively.}} {{History|||snap=pre1|The player can now tab-complete in command blocks again.}} {{History||1.14|snap=18w43a|  The textures of command blocks have been changed.}} {{History|||snap=18w47b| The textures of impulse and repeating command blocks have been changed.}}
 * The character limit when inserting a command in a command block has been increased from 256 to 16,369. Using a third-party editor allows the player to reach 32,767 characters.}}
 * Added block facing for command blocks.
 * Impulse Command Block JE2.png The texture of command blocks has been changed.}}
 * Added tab completion support within command blocks.}}
 * Conditional Impulse Command Block JE1 BE1.png Conditional Chain Command Block JE1 BE1.png Conditional Repeating Command Block JE1 BE1.png When command blocks are set to conditional, the back of the arrow texture is now curved.
 * Added Always active and needs redstone options for command blocks.
 * Added  NBT tag to control redstone options within command blocks.}}
 * Players, who are unable to use commands, can no longer place command blocks.}}
 * Added  game rule to control the max length of such a chain.}}

{{History|pocket}} {{History||1.0.5|snap=alpha 1.0.5.0|  Added all types of command blocks.}} {{History|bedrock}} {{History||1.8.0|snap=beta 1.8.0.8|Command blocks now have a default name of {{code|!}} instead of {{code|@}}.}} {{History||1.10.0|snap=beta 1.10.0.3|  The textures of command blocks have been changed.}} {{History||1.12.0|snap=beta 1.12.0.2|Tab-complete has been added to command blocks.
 * Added a delay option to command blocks, which allows a delay to be added to a redstone tick delay field.}}

{{History|console}} {{History||xbox=TU19|xbone=CU7|ps=1.12|wiiu=Patch 1| Added command blocks. {{History|foot}}
 * Command blocks do not have any functionality and can be obtained only with mods.}}