Command Block

From Minecraft Wiki
(Redirected from Repeating command block)
Jump to: navigation, search
Command Block
Impulse Command Block.gifChain Command Block.gifRepeating Command Block.gif
Conditional Impulse Command Block.gifConditional Chain Command Block.gifConditional Repeating Command Block.gif
Command BlockChain Command BlockRepeating Command Block
Type

Block Entity

Rarity

Epic

Requirements

None

Physics

No

Transparency

No

Luminance

0

Blast resistance

18,000,000

Hardness

-1

Tool

None

Renewable

No

Stackable

Yes (64)

Flammable

No

Drops

None

Block Entity ID

command_block

Data values

See § Data values

Namespaced ID

See § Data values

Information icon.svg
This feature is exclusive to Java Edition, Bedrock Edition and Education Edition.
Duncan Geere Mojang avatar.png

If you mostly play survival mode, and you’re thinking “that sounds a lot like cheating”, then you’re right - which is why command blocks aren’t available in survival mode. They’re a feature that we built specifically for creative mode, and for adventure mode mapmakers. Jeb announced their existence in a tweet in July 2012, and they were added to the game in version 1.4.2 – the Pretty Scary Update, which also added spooky anvils, creepy flowerpots and terrifying carrots on sticks.

Duncan Geere[1]

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]

Command blocks are not available in the Creative inventory. It can either be obtained by using the pick block control, or by using various commands, such as /give @s minecraft:command_block, or /setblock ~ ~ ~ minecraft:command_block.

Just like other blocks that can store NBT data, using pick block + CTRL 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, cannot be moved by pistons, and have the same blast resistance as bedrock.

Usage[edit]

A command block can execute commands when activated by redstone power. It always has all permissions, 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 /give, without allowing everyone to /give themselves whatever they want).

A command block has an orientation ("facing") that determines the chain command block to activate, and the blocks to be checked to see if a command block in "Conditional" mode executes.

Modification[edit]

Command block GUI.

To enter or modify the command in a command block, use the Use Item 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. In singleplayer, cheats must be enabled to edit command blocks. In multiplayer, command blocks can be edited successfully only 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,500 characters, but the text pane can show only a small portion of this amount at a time. Press Tab ↹ to complete words or cycle through options.

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

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 (initially blank). Its text is not editable.

A button to the right of the Previous Output text pane specifies whether the last output should be stored and displayed. It shows O (the default) when the output should be stored and X when the output should not be stored. A command block that's tracking its output while executing its command causes a block update, and when you have 64 of those command blocks tracking their output while executing their command sharing the same chunk, it then causes 1 or more chunk updates because 64 block updates in 1 chunk cause one or more chunk updates. If the amount of chunk updates is high enough, then it can cause fps drops for players if they're receiving the chunk updates. To avoid this, simply have all of your command blocks not track their output at all, except for temporary debugging purposes.

Impulse/Chain/Repeat
Click the "Impulse/Chain/Repeat" button to change the command block's type. The default state is "Impulse", but non-default command blocks can be 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 only when the command block pointing to it is processed. This differs from the Conditional option in that it detects what is pointing to it, instead of simply behind it. The command blocks pointing to it also don't need to be chain command blocks themselves to trigger the chain. When a chain is triggered, all of its commands execute simultaneously.
  • "Repeat" command blocks are purple. These execute their commands once per game tick as long as they are activated (20 times per second, barring lag).
Conditional/Unconditional
Top: Command blocks in "Unconditional" mode. Bottom: Command blocks in "Conditional" mode.
Click the "Conditional/Unconditional" button to change the command block's conditional behavior:
  • "Conditional": A command block in conditional mode executes its command only after the command block behind it has executed 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).
  • "Unconditional" (default): A command block in unconditional mode executes its command (if activated correctly) even if there's a command block behind it that didn't execute its command successfully.
Always Active/Needs Redstone
Click the "Always Active/Needs 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 must be activated with redstone in order to execute its command.
  • "Always Active" (the default for chain command blocks): The command block is always active even without redstone activation (chain command blocks execute their command when chained, repeating command blocks execute their command every game tick (20 times every second), and impulse command blocks activate once then cannot be activated again).
Done
Click the "Done" button or ↵ Enter to save the command and leave the command block GUI.
Cancel
Click the "Cancel" button or Esc 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 does not activate a command block it is attached to), 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.

In addition, when a command block is cloned by a command to a powered location, the new command block executes its command only if the original has never been activated (visible in the F3 debug screen as "triggered").

Unlike all other redstone components, except the note block, a command block can be activated every game tick (20 times per second, barring lag). However, if it's set to Needs Redstone, then activating it two game ticks in a row requires that it transition from powered to unpowered and back during the same tick (for example, with a setblock clock).

A command block in "Always Active" mode is always activated. The default state is "Needs Redstone", which means that it runs only when powered.

When activated, a command block tries to execute its command, depending on the command block's type:

  • a command block ("Impulse") tries to execute its command once
  • a chain command block ("Chain") does not try to execute its command until another command block facing it executes its own command
  • a repeating command block ("Repeat") tries to execute its command every game tick until no longer activated

Chained execution[edit]

If any command block faces a chain command block (a command block in "Chain" mode) when activated, it notifies the chain command block to also attempt execution. The chain command block executes its command only if activated and, if in "Conditional" mode, if the command block behind it executed successfully (behind in the sense of the direction it is facing, not in the sense of which command block chained to it). Whether or not the chain command block is activated or executes successfully, if it is facing another chain command block, it notifies that block to attempt execution also.

Chained command blocks execute in the same game tick in the order they are chained. Chained execution cannot be passed to a command block that has already executed in that game tick (loops execute only once).

Output[edit]

When activated, a command block can produce multiple 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 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 /me, /say and /tell commands) use @ as the player name. If the command block had been named in an anvil before placement, that name is 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 displays only in the command block's Previous Output pane rather than being displayed in the chat): /help, /seed, /list, /scoreboard objectives, /scoreboard players, and /team list.

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

Easter eggs[edit]

Running "Searge" as the command in the command block without a preceding "/" now set the previous output to "#itzlipofutzli". Additionally, if /help is run via command block, it gives various messages prefixed with "Searge says: ". This no longer works on Bedrock Edition.

Data values[edit]

ID[edit]

Java Edition:

Name Namespaced ID
Impulse Command Block command_block
Chain Command Block chain_command_block
Repeating Command Block repeating_command_block
Block entity command_block

Bedrock Edition:

Name Namespaced ID Numeric ID
Impulse Command Block command_block 137
Chain Command Block chain_command_block 189
Repeating Command Block repeating_command_block 188
Block entity ? -

Block data[edit]

In Bedrock Edition, a command block's block data specifies whether the command block is currently activated.

Bits Values
0x1
0x2
0x4

A 3-bit field storing the command block's facing:

  • 0: facing down
  • 1: facing up
  • 2: facing north
  • 3: facing south
  • 4: facing west
  • 5: facing east

6 and 7 are unused but produce command blocks facing down and up respectively.

0x8 Whether the block is in conditional mode.

Block states[edit]

Java Edition:

Name Default value Allowed values Description
conditionalfalsefalse
true
True if the command block is in conditional mode.
facingnorthdown
east
north
south
up
west
The direction the command block is pointing.

Block entity[edit]

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

  • Block entity data
    • Tags common to all block entities see Template:Nbt inherit/blockentity/template
    •  CustomName: Optional. The name of this command block in JSON text component, replacing 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.
    •  powered: 1 or 0 (true/false) - States whether or not the command block is powered by redstone or not.
    •  auto: 1 or 0 (true/false) - Allows to activate the command without the requirement of a redstone signal.
    •  conditionMet: 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.
    •  UpdateLastExecution: 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.
    •  LastExecution: stores the tick a chain command block was last executed in.

Video[edit]

History[edit]

Java Edition
July 27, 2012Jeb 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 can do.
July 31, 2012During Notch's AMA he hinted the block may be in Java Edition 1.4.
1.4.212w32aImpulse Command Block Revision 1.png Added command block.
1.513w03aCommand block success can now power a redstone comparator.
13w04aCommand blocks renamed with an anvil now use their name instead of @ in the chat.
1.6.113w19aCommand blocks are no longer mineable in survival.
Command blocks are now no longer damaged by explosions, except by Blue wither skulls.
1.7.213w37aA bar that shows the previous output of command blocks has now been added.
The character limit when inserting a command in a command block has now been increased from 256 to 16,369. Using a third-party editor allows the player to reach 32,767 characters.
1.814w07aDispensers now place command blocks, instead of shooting them out.
14w20aThe in-game character limit of 16,369 has now been removed, allowing access to the full 32,767 characters.
14w27aAdded CommandStats NBT tag.
1.8.6Dispensers no longer place command blocks.[2]
1.915w33aCharacter limit for command blocks is now 32,500 instead of 32,767.
15w34aChain Command Block Revision 1.png Repeating Command Block Revision 1.png Added the chain command block and the repeating command block.
Added block facing for command blocks.
Impulse Command Block Revision 2.png Command block textures have now been updated.
15w34bAdded Conditional mode within command blocks.
Added tab completion support within command blocks.
15w35aImpulse Command Block.png Chain Command Block.png Repeating Command Block.png Updated texture of all three command blocks.
Added Always active and needs redstone options for command blocks.
Added auto NBT tag to control redstone options within command blocks.
When command blocks are set to conditional, the back of the arrow texture is curved.
15w36aPlayers are now unable to use commands, such as /give, within command blocks.
Players, who unable to use commands, can now no longer place command blocks.
15w36dEach command block type now appears with different colors on maps.
16w02aRunning /help in a command block now randomly uses one of various different humorous phrases as the previous output.
16w04aRunning "Searge" as the command in the command block without a preceding "/" now sets the previous output to "#itzlipofutzli".
1.1116w32aThe block entity ID is changed from Control to command_block.
1.1217w16aChains 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.
Added maxCommandChainLength game rule to control the max length of such a chain.
17w17aAdded UpdateLastExecution and LastExecution NBT tags, which control the tracking of which tick a chain command block was last executed in.
pre6Tab-completing command names in command blocks no longer add a / prefix.
1.1317w47aPrior to The Flattening, the numeral IDs for the command block, repeating command block, and chain command block were 137, 210, and 211, respectively.
pre1The player can now tab-complete in command blocks again.
1.1418w43aImpulse Command Block TextureUpdate Revision 1.pngChain Command Block TextureUpdate.pngRepeating Command Block TextureUpdate Revision 1.png Changed the texture of command blocks.
18w47bImpulse Command Block TextureUpdate.pngRepeating Command Block TextureUpdate.png Changed the texture of impulse and repeating command blocks.
Pocket Edition
1.0.5alpha 1.0.5.0Impulse Command Block.png Chain Command Block.png Repeating Command Block.png Added all types of command blocks.
Bedrock Edition
1.8.0beta 1.8.0.8Command blocks now have a default name of ! instead of @.
1.12.0beta 1.12.0.2Added tab-complete to command blocks.
Added a delay option to command blocks, which allows a delay to be added to a redstone tick delay field.
Legacy Console Edition
TU19CU71.12Patch 1Impulse Command Block Revision 1.png Added command blocks.
Command blocks do not have any functionality and can be obtained only with mods.

Gallery[edit]

Issues[edit]

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

References[edit]