Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Command Block

From SAS Gaming Wiki

Template:For Template:Infobox block A command block is an Minecraft:indestructible Minecraft:block that can execute Minecraft:commands. Because it cannot be obtained, destroyed or used in Minecraft:Survival mode without cheats, it is primarily used in multiplayer servers, Minecraft:Creative worlds, and custom maps. There are 3 types of these blocks.

An impulse command block is the default block type; it executes only once when activated.

A chain command block executes every time when triggered.

A repeating command block executes every game Minecraft:tick as long as it is activated.

Obtaining

Template:IN, command blocks are available in the Minecraft:Creative inventory under the "Operator Utilities" tab, if the "Operator Items Tab" setting in the "Controls" Options tab is set to "ON". Across both Java and Bedrock editions, they can either be obtained by using various Minecraft:commands, such as Template:Cmd or Template:Cmd, or by pressing the Template:Control Minecraft:control on an existing command block. Just like other blocks that can store Minecraft:NBT data, using Template:Control + Template:Key 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 are not flammable, and have the same Minecraft:blast resistance as Minecraft:bedrock. Command blocks, Minecraft:structure blocks, and Minecraft:jigsaw blocks cannot be mined in Minecraft:Survival.

Usage

Template:See also

A command block can execute commands when activated by redstone power. It always has permissions of level 2Template:Only/level 1Template:Only, 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 Template:Cmd 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, Template:In the Minecraft:game rule command_blocks_work must be set to true; Template:In "Command Blocks Enabled" in Minecraft:world options must be enabled.

Command blocks can only be placed or broken by an Minecraft:operator player in Minecraft:Creative mode.

Modification

File:Command Block GUI.png
Java Edition command block GUI

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

Template:IN to enter command or modify the command block, enable-command-block in the Minecraft:server.properties file must be set to true (default is false).

File:Bedrock Command Block GUI.png
Bedrock Edition command block GUI

Template:IN, opening the GUI in Minecraft:singleplayer pauses the game.

Console CommandTemplate:Only/Command InputTemplate:Only
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 Template:Key to complete words or cycle through options.
Template:IN, below the console command text pane are some reminder tips about how to use Minecraft:target selectors.
Previous Output
The bottom text pane displays the output message (success or failure) of the last executed command (it is blankTemplate:Only or " - "Template:Only initially). Its text is not editable.
A button to the right of the Previous Output text paneTemplate:Only or the left of the "Previous Output"Template:Only specifies whether the last output should be stored and displayed. It is OTemplate:Only/enabledTemplate:Only when the output text should be stored and XTemplate:Only/disabledTemplate:Only 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 sendCommandFeedback is true (the default), default to OTemplate:Only/enabledTemplate:Only. Otherwise defaults to XTemplate:Only/disabledTemplate:Only.
Block Type
File:Command block textures.png
Left: "Impulse" block type.
Middle: "Chain" block type.
Right: "Repeating" block type.
Top: "Unconditional" mode.
Bottom: "Conditional" mode.
Click the "Impulse/Chain/Repeat" buttonTemplate:Only/"Block Type:" dropdown menuTemplate:Only 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. They execute once every time they are activated.
  • "Chain" command blocks are cyan. They execute once every time they are triggered if they have been activated.
  • "Repeat" command blocks are purple. They execute their commands once every one game Minecraft:tick (or moreTemplate:Only) as long as they are activated.
Condition
Click the "Conditional/Unconditional" buttonTemplate:Only/"Condition:" dropdown menuTemplate:Only 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" buttonTemplate:Only/"Redstone:" dropdown menuTemplate:Only 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 TickTemplate:Only
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 TicksTemplate:Only
For impulse or chain command block, specifies how many game ticks it delays before executing a 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 are different.
Hover NoteTemplate:Only
Specifies the name of the 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
Template:IN, click the "Done" button or Template:Key to save the command and leave the command block GUI.
Template:IN, close the GUI to save the command and changes.
Cancel
Click the "Cancel" button or Template:KeyTemplate:Onlyto leave the command block GUI without saving any changes.

Activation

Command blocks are redstone mechanisms and can be activated by:

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

When activated, a command block executes its command, depending on the command block's type:

  • An 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 moreTemplate:Only) 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 game tick (or moreTemplate:Only), 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 game tick (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 Template:In, 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 game tick (or moreTemplate:Only).

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.

Also:

  • 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. Template:IN, it also needs a block update 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 game tick (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 game tick (or moreTemplate:Only).

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.

Template:IN, 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 a 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.

Template:IN, 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.
Template:IN, success count is usually 0 or 1, except for Template:Cmd and Template:Cmd.
Template:IN, success count is an integer related to the 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.)
Template:IN, leaving the command block GUI by clicking "Done" or pressing Template:Key resets the success count to 0, regardless of whether changes were made in the GUI. Template:IN, 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 Minecraft:ops in multiplayer mode, unless it has been suppressed with Template:Cmd. Some commands may write additional text to the chat as their normal function, which won't be suppressed (for example, the Template:Cmd 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 Template:Cmd, Template:Cmd and Template:Cmd commands) use @ Template:Only / ! Template:Only as the player name. If the command block had been named in an Minecraft:anvil before placement, that name is used instead. Template:IN, it can also modified in the GUI.
Logs: The output message is written to multiplayer server logs unless it has been suppressed with Template:Cmd.

Template:Anchor Notes

Command blocks execute commands with OP level 2. The following commands cannot be used in a command block: Template:Cmd, Template:Cmd, Template:Cmd, Template:Cmd, Template:Cmd, Template:CmdTemplate:Only, Template:Cmd, Template:Cmd, Template:Cmd, Template:Cmd, Template:CmdTemplate:Only, Template:Cmd, Template:Cmd, Template:Cmd, Template:Cmd, Template:Cmd, and Template:Cmd (i.e., Template:Cmd, Template:Cmd, Template:Cmd, and all of the multiplayer-only commands except Template:Cmd).

Easter eggs

Template:Main

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

Piston interactivity

Command blocks cannot be pushed by Minecraft:pistons. They also cannot be pushed or pulled by Minecraft:sticky pistons.

Sounds

Template:Sound table/Block/Metal

Data values

ID

Template:Edition: Template:ID table Template:ID table Template:ID table Template:ID table

Template:Edition: Template:ID table Template:ID table Template:ID table Template:ID table

Block states

Template:See also

Template:El: Template:Bst Template:Bst

Template:El: Template:Bst Template:Bst

Block data

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

Template:El: Template:See also

<section begin="block data"/>

  • Template:Nbt Block entity data
    • Template:Nbt inherit/blockentity
    • Template:Nbt inherit/nameable
    • Template:Nbt: 1 or 0 (true/false) - Allows to activate the command without the requirement of a redstone signal.
    • Template:Nbt: The command to issue to the server.
    • Template:Nbt: 1 or 0 (true/false) - Indicates whether a conditional command block had its condition met when last activated. True if not a conditional command block.
    • Template:Nbt: stores the tick a chain command block was last executed in.
    • Template:Nbt: The last line of output generated by the command block. Still stored even if the Minecraft:game rule Template:Cd is Template:Cd. Appears in the GUI of the block when right-clicked, and includes a timestamp of when the output was produced.
    • Template:Nbt: 1 or 0 (true/false) - States whether or not the command block is powered by redstone or not.
    • Template:Nbt: Represents the strength of the analog signal output by redstone comparators attached to this command block.
    • Template:Nbt: 1 or 0 (true/false) - Determines whether the LastOutput is 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.
    • Template:Nbt: 1 or 0 (true/false) - Defaults to true. If set to false, loops can be created where the same command block can run multiple times in one tick.

<section end="block data"/>

Template:El:

See Minecraft:Bedrock Edition level format/Block entity format.

History

Template:See also

Announcement

Template:HistoryTable

Java Edition

Template:HistoryTable

Bedrock Edition

Template:HistoryTable

Legacy Console Edition

Template:HistoryTable

Data history

Template:HistoryTable

Issues

Template:Issue list

Gallery

Mojang images

In other media

References

Template:Reflist

External links

Navigation

Template:Navbox redstone Template:Navbox blocks

Minecraft:cs:Příkazový blok Minecraft:de:Befehlsblock Minecraft:es:Bloque de comandos Minecraft:fr:Bloc de commande Minecraft:it:Blocco comandi Minecraft:ja:コマンドブロック Minecraft:ko:명령 블록 Minecraft:nl:Opdrachtblok Minecraft:pl:Blok poleceń Minecraft:pt:Bloco de Comando Minecraft:ru:Командный блок Minecraft:th:บล็อกคำสั่ง Minecraft:uk:Командний блок Minecraft:zh:命令方块