Command Block

A command block is a redstone mechanism that can execute commands when activated. Because it cannot be obtained legitimately in survival mode, it is primarily used on multiplayer servers and in custom maps.

It is not possible to break a command block in survival mode, and explosions do not damage it in any mode. It cannot be pushed by a piston, but can be destroyed by an Ender Dragon.

Obtaining
Command blocks cannot be crafted and do not generate naturally during world generation. They also are not available in the creative inventory.

Command blocks can be obtained through various commands (requires enabled cheats in singleplayer, or an operator in multiplayer):
 * (using  for player will give the command block to the command's user)

Command blocks can also be obtained by using the "pick block" control (defaults to the mouse middle button) on an existing command block.

Usage
.

The command block can execute useful commands, such as giving items or experience to a player. To change the command executed by the block, simply right-click it, and the GUI will open.

Comparators can be used to determine whether or not a command block's command succeeded, as well as the number of times it has succeeded in a single execution. More information on this behavior can be found here, and command success criteria can be found in the Command article.

When using commands, treat them as if entered from the console - you always need to specify the target. For example, to change the mode to Survival for the nearest player type. Note that you will have to be in Creative mode to change the command associated with the block.

The commandBlockOutput gamerule does not affect the command block using the and,  and  commands.

The command block sends commands through the console in singleplayer and multiplayer, though commands can still be prefixed with a "/".

Permission
In singleplayer, cheats must be enabled to edit command blocks.

In multiplayer, command blocks can only be edited successfully by operators in creative mode and for command blocks to works at all the following values must be set in the server.properties file:
 * must be set to
 * must be set to  or above (default is 4)

Modification
To enter or modify the command in a command block, right-click the command block to open the command block interface.


 * "Console Command" Text Pane
 * You can enter a command in the top text pane. Commands in a command block do not need to be prefixed with the forward slash as they do in the chat window, but using it will still work.


 * The text limit for commands in a command block is 32,767 characters. The top text pane can only show a small portion of this amount at a time.


 * Below the console command text pane are some reminder tips about how to use target selectors.


 * "Previous Output" Text Pane
 * The bottom text pane doesn't appear until the command block has been activated at least once. Its text is not editable and shows the output message of the last executed command (success or failure).


 * "Done" Button
 * Click the "Done" button to save the command and leave the command block interface.


 * "Cancel" Button
 * Click the "Cancel" button to leave the command block interface without changing anything.

Activation
Like other redstone mechanisms, a command block can be activated by:
 * an adjacent active power component: for example, a redstone torch (except that a redstone torch will not activate a command block it is attached to), a block of redstone, a daylight sensor, etc.
 * an adjacent powered opaque block (for example, a block with an active redstone torch under it)
 * a powered redstone repeater or redstone comparator facing the mechanism component
 * powered redstone dust configured to point at the command block (or on top of it); a command block is not activated by adjacent powered redstone dust which is not configured to point at it.

In addition, a command block will be activated when it is placed by a dispenser, even if that location wouldn't normally activate the command block.

When activated, a command block will try to execute its command.

Output
Command blocks have two types of output:


 * Output Message


 * The output message of the executed command may be written to multiple destinations:


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


 * 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 . Output messages which 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 will be used instead.


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


 * Redstone Output


 * A command block can power a redstone comparator facing away from it (possibly separated by a block) with a signal strength specific to the last executed command (for example, the number of players affected by the command).


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

Unusable commands
The following commands cannot be used in a command block for various reasons:

* Some commands, such as,  , and   would be expected to require a player as the executor, but work in command blocks and the server console. The command block's "name" defaults to "@", but can be renamed with an anvil.

** Seed's output can be read from the command block's "Previous output" window. However as it only allows 1 line, commands like help or list will only show the first line of the output.