Command Block

From Minecraft Wiki
(Redirected from Command blocks)
Jump to: navigation, search
[edit]Command Block
Command Block.png
Command Block

Tile Entity







Blast resistance









Yes (64)



First appearance

1.4.2 (12w32a)

Tile Entity ID


Data value

dec: 137 hex: 89 bin: 10001001



A command block is a redstone component 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.


[edit] 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):

  • /give <player> minecraft:command_block <amount> (using @p for player will give the command block to the nearest person)
  • /setblock <x> <y> <z> minecraft:command_block
  • /summon Item <x> <y> <z> {Item:{id:minecraft:command_block,Count:1}}

Using 137 instead of minecraft:command_block also works in the current version, but not in the current snapshots or future versions.

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

[edit] Usage

See also: Commands and Tutorials/Command Block .

The command block can execute commands, such as giving experience to a player.[1] To change the command executed by the block, right-click it to open the command block interface.

A redstone comparator can be used to determine whether or not a command block's command succeeded, as well as the number of times it succeeded in a single execution.

A command block cannot be broken in survival mode, is not flammable, and has the same blast resistance as bedrock making it difficult to destroy with explosions (impossible in survival, but possible with custom explosions). A command block cannot be pushed by a piston, but can be destroyed by an Ender dragon.

[edit] 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 work at all the following values must be set in the file:

  • enable-command-block must be set to true
  • op-permission-level must be set to 2 or above (default is 4)

[edit] Modification

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

Console Command
Commands can be entered in the top text pane. The text limit for commands in a command block is 32,767 characters, but the text pane can only show 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 using it will still work.
Below the console command text pane are some reminder tips about how to use target selectors.
Previous Output
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).
Click the "Done" button to save the command and leave the command block interface.
Click the "Cancel" button to leave the command block interface without saving any changes.

[edit] 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) or directionless; a command block is not activated by adjacent powered redstone dust which is configured to point away from it.

In addition, a command block will activate 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.

[edit] Output

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

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.
Output 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 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 /gamerule commandBlockOutput false. Some commands may write additional text to the chat as their normal function which won't be suppressed (for example, the /say command will write a message to the chat of all players), separate from the output message. Chat messages which would usually be prefaced by a player's name (such as from the /me, /say and /tell 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 /gamerule logAdminCommands false.

[edit] Unusable commands

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

Category Reason for Unavailability Commands
Disabled for server security These commands are likely disabled due to limited use in command blocks and the potential for severe, unintended consequences on servers. ban, ban-ip, deop, kick, op, pardon, pardon-ip, save-all, save-off, save-on, stop, whitelist add/remove/on/off/reload, debug, publish
Disabled for unknown reasons These commands do not bear unintended consequences, but still fail in command blocks. banlist, whitelist list
Available, but shows in the previous output bar** These commands output messages to their user only, not to public chat. help, seed, list, scoreboard objectives/players/teams list

*Some commands, such as /me, /tell, and /say 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.

[edit] Future

This section contains content on features that may be included in the next update.
These features have appeared in development versions, but the full update containing these features has not been released yet.

The command block interface shows the @e target selctor in the tips below the Console Command text pane.

The command block interface allows the player to choose whether the last output should be stored and displayed in the Previous Output text pane. A button to the right of the Previous Output text pane shows O when the output should be stored and X when the output should not be stored.

[edit] Command Stats

Command blocks can post various success results to scoreboard objectives, including:

  • SuccessCount: the number of successes (previously also available by redstone comparator output, but not limited to 15)
  • AffectedBlocks: the number of blocks that were altered
  • AffectedEntities: the number of entities that were altered (including players)
  • AffectedItems: the number of items that were altered
  • QueryResult: value returned by command

The objectives to be used can be specified by running the /stats command or by modifying the command block's NBT data directly with the /blockdata command.

[edit] Video

[edit] History

See also: Commands#History
Official release
27 July 2012
Jeb began tweeting of a new block he had created to start expanding Adventure mode. He began posting pictures, ideas and hints of what the block will be able to do.
31 July 2012
During Notch's AMA he hinted the block may be in 1.4.
1.4.2 12w32a Added command block.
1.5 13w03a Command block success can now power a redstone comparator.
13w04a Command blocks renamed with an anvil now use their name instead of @ in the chat.
1.6.1 13w19a Command blocks are no longer mineable in survival, and are also not damaged by explosions except by Blue Wither Skulls.
1.7.2 13w37a Added a bar that shows the previous output.
Increased the character limit from 256 to 16,369 when inserting a command in-game. Using a third-party editor allows you to reach 32,767 characters.
13w39a Added minecart with command block.
1.8 14w07a Dispensers now place command blocks and run the preset command if there's one, instead of shooting it out.
14w20a Removed the in-game character limit of 16,369, allowing access to the full 32,767 characters.
14w27a Added CommandStats NBT tag.

[edit] Issues

Issues relating to "Command Block" are maintained on the issue tracker. Report issues there.

[edit] Gallery

[edit] References