Share

Share

Command Block

From Minecraft Wiki
Jump to: navigation, search
Command Block
Command Block.png
Command Block
Type

Tile Entity

Physics

No

Transparency

No

Luminance

No

Blast resistance

18,000,000

Hardness

-1

Tool

None

Renewable

No

Stackable

Yes (64)

Flammable

No

First appearance

1.4.2 (12w32a)

Tile Entity ID

Control

Data value

dec: 137 hex: 89 bin: 10001001

Name

command_block

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

Obtaining[edit]

A command block cannot be broken in survival mode, is not flammable, and has the same blast resistance as bedrock. A command block cannot be pushed by a piston, but can be destroyed by an Ender dragon.

Command blocks are not available in the creative inventory, but can be obtained via "pick block" or various commands, such as /give <player> minecraft:command_block <amount>

Usage[edit]

See also: Commands and Tutorials/Command Block

A command block can execute commands when activated by redstone power.

Modification[edit]

Command block GUI.

To enter or modify the command in a command block, right-click on the command block to open the command block GUI. The GUI will only open if the player is in creative mode, and has the proper permissions. 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 server.properties file:

  • enable-command-block must be set to true
  • op-permission-level must be set to 2 or above (default is 4)
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). The command block GUI 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. For worlds with many command blocks, not storing the output text can reduce memory and storage requirements.
Done
Click the "Done" button to save the command and leave the command block GUI.
Cancel
Click the "Cancel" button to leave the command block GUI without saving any changes.

Activation[edit]

Command blocks are redstone mechanisms and 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 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 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), using the command specified in the command block item's BlockEntityTag. When a command block is cloned by a command to a powered location, the new command block will only execute its command if the original has never been activated (visible in the F3 debug screen as "triggered").

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

Output[edit]

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

Redstone Comparator
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.
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 /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.
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.

Notes[edit]

The following commands cannot be used in a command block: /ban, /banlist, /ban-ip, /debug, /deop, /kick, /op, /pardon, /pardon-ip, /publish, /save-all, /save-off, /save-on, /stop, and /whitelist (i.e., /debug, /publish, and all of the multiplayer-only commands except /list).

The following commands are usable but with limited functionality (their output only displays in the command block's Previous Output pane rather than being displayed in the chat): /help, /seed, /list, /scoreboard objectives, /scoreboard players, and /scoreboard teams list.

The following commands use the command block's name (defaults to @) in their output: /me, /say, and /tell.

Data values[edit]

A command block has an ID name of minecraft:command_block and is further defined by its block data and block entity. A command block also has a block state which is expected to replace the functionality of block data in a future version.

Block data[edit]

A command block's block data specifies whether the command block is currently activated.

Bits Values
0x1 Set if the command block has been previously activated with its current command.
0x2
0x4
0x8
(unused)

Block entity[edit]

See also: Block entity format

  • Block entity data

    •  id: Control

    •  x: X coordinate of the Block Entity.

    •  y: Y coordinate of the Block Entity.

    •  z: Z coordinate of the Block Entity.

    •  CustomName: Optional. The name of this command block, which will replace the usual '@' when using commands such as "say" and "tell".

    •  Command: The command to issue to the server.

    •  SuccessCount: Represents the strength of the analog signal output by redstone comparators attached to this command block. Only updated when the command block is activated with a redstone signal.

    •  LastOutput: The last line of output generated by the command block. Still stored even if the gamerule commandBlockOutput is false. Appears in the GUI of the block when right-clicked, and includes a timestamp of when the output was produced.

    •  TrackOutput: 1 or 0 (true/false) - Determines whether or not the LastOutput will be stored. Can be toggled in the GUI by clicking a button near the "Previous Output" textbox. Caption on the button indicates current state: "O" if true,"X" if false.

    •  CommandStats: Information identifying scoreboard parameters to modify relative to the last command run.

      •  SuccessCountName: Player name to store success of the last command. Can be a player selector but may only have one resulting target.

      •  SuccessCountObjective: Objective's name to store the success of the last command.

      •  AffectedBlocksName: Player name to store how many blocks were modified in the last command. Can be a player selector but may only have one resulting target.

      •  AffectedBlocksObjective: Objective's name to store how many blocks were modified in the last command.

      •  AffectedEntitiesName: Player name to store how many entities were altered in the last command. Can be a player selector but may only have one resulting target.

      •  AffectedEntitiesObjective: Objective's name to store how many entities were altered in the last command.

      •  AffectedItemsName: Player name to store how many items were altered in the last command. Can be a player selector but may only have one resulting target.

      •  AffectedItemsObjective: Objective's name to store how many items were altered in the last command.

      •  QueryResultName: Player name to store the query result of the last command. Can be a player selector but may only have one resulting target.

      •  QueryResultObjective: Objective's name to store the query result of the last command.

Block state[edit]

See also: Block states
Name Value Description

 triggered
true
false
True if the command block has been previously activated with its current command.

Video[edit]

History[edit]

The first image released by Mojang of the command block.
The second image released by Mojang showing the block giving glass to the player.
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.
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.
Upcoming
1.9 Command blocks will have a new GUI.

Issues[edit]

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