Command Block
A command block is an indestructible block that can execute commands. Because it cannot be obtained, destroyed or used in Survival mode without cheats, it is primarily used in multiplayer servers, 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 tick as long as it is activated.
Local game data
Repeating Command Block
A command block is an indestructible block that can execute commands. Because it cannot be obtained, destroyed or used in Survival mode without cheats, it is primarily used in multiplayer servers, 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 tick as long as it is activated.
Obtaining
, command blocks are available in the 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 commands, such as or , or by pressing the control on an existing command block. Just like other blocks that can store NBT data, using + 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 blast resistance as bedrock. Command blocks, structure blocks, and jigsaw blocks cannot be mined in Survival.
Usage
A command block can execute commands when activated by redstone power. It always has permissions of level 2/level 1, 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 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, the game rule command_blocks_work must be set to true; "Command Blocks Enabled" in world options must be enabled. Command blocks can only be placed or broken by an operator player in Creative mode.
Modification
To enter command or modify the command block, use the 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. That means, in singleplayer, "Allow Cheats" or "Activate Cheats" in world options must be enabled. In multiplayer, GUI can be opened only by operators in Creative mode, and op-permission-level in the server.properties file must be set to 2 or above (default is 4). to enter command or modify the command block, enable-command-block in the server.properties file must be set to true (default is false).
, opening the GUI in singleplayer pauses the game. Console Command/Command Input 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 to complete words or cycle through options. , 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 (it is blank or " - " initially). Its text is not editable. A button to the right of the Previous Output text pane or the left of the "Previous Output" specifies whether the last output should be stored and displayed. It is O/enabled when the output text should be stored and X/disabled 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 O/enabled. Otherwise defaults to X/disabled. Block Type
Click the "Impulse/Chain/Repeat" button/"Block Type:" dropdown menu 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 tick (or more) as long as they are activated. Condition Click the "Conditional/Unconditional" button/"Condition:" dropdown menu 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" button/"Redstone:" dropdown menu 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 Tick 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 Ticks 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 Note 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 , click the "Done" button or to save the command and leave the command block GUI. , close the GUI to save the command and changes. Cancel Click the "Cancel" button or to leave the command block GUI without saving any changes.
Activation
Command blocks are redstone mechanisms and can be activated by: An adjacent active power component: for example, a lever, 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. 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 more) 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 more), 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 , 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 more). 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. , 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 more).
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 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 false, it executes the command and triggers another chain command block it is facing. 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. , 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. , 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.