Command Block

The Command Block is a block made with the intent to support Adventure mode and allows mapmakers to expand the interaction with the player through server commands. The block can run specified server commands when activated by a redstone current. Considering its great power and possibilities, it can't be normally crafted. It is not available in the creative mode inventory either. Only players with sufficient privileges to use the 'give' command:   (or someone in creative who finds one in the world and uses pick block on it) can obtain the block. Furthermore, only players which are in Creative mode and are also an operator on the server are able to edit and successfully save the command of the block. To be able to use this block in multiplayer, you have to set the value of  to   in the server.properties file. If this line doesn't exist, you'll have to add it. It is not possible to break Command Blocks in Survival Mode, and explosions do not damage them in any mode. They can't be pushed by pistons, but can be destroyed by EnderDragons.

Usage
The Command Block can execute some useful commands, such as giving items or experience to a player.

To change the command executed by the block, simply right-click it, and the GUI will open.

In place of player names, it is possible to use multiple different variables:

Comparators can be used to determine whether or not a command block's command succeeded, as well as the number of times it has succeeded in a single execution. More information on this behavior can be found here, and command success criteria can be found in the Command article.

When using commands, treat them as if entered from the console - you always need to specify the target, so it is not possible to use commands such as "kill" which do not take a player argument. For example, to change the mode to Survival for the nearest player type. Note that you will have to be in Creative mode to change the command associated with the block.

The command block sends commands through the console in singleplayer and multiplayer, though commands can still be prefixed with a "/". If you want to give the nearest player stone, you can enter or.

For innovative, practical uses of the Command Block, view Tutorials/Command Block.

Examples
If you don't want to target a specific player, you can use,  , or   instead of  - Keep in mind that you can use @p (which means "closest player") in player issued commands as an easy to type 2 character replacement for your own name. The closest player to you will always be you.
 * It is possible to make teleporters using the command block. (e.g. code: ) Taking it one step further, a teleport station can be made, with multiple button activated teleporters that each teleport you 500 blocks further than the last (or any interval you like). Since these will be blind teleports at first, creative mode is recommended during the "scouting" stage, as is aiming at least 20 blocks above sea level so as to make appearing entombed in the ground less likely. If you do appear in ground, try     to get out (may require multiple uses). See next example for explaination of relative coordinates (x y z values with ~ before them).
 * If you use the teleport command with the command block, you can use relative coordinates in the destination coordinates by placing an  in front of a Coordinate (e.g. code:   This would teleport the player 8 blocks into the air).
 * Commands using coordinates (e.g. or ) add 0.5 to whole numbers, like usual. This is so you appear centered over the block you appear on instead of at the edge or corner of it. To clarify, the number -33 would be interpreted as -32.5, and the number 187 would be interpreted as 187.5. Values with decimal places (25.3, 90.0) after them are left as-is.
 * The player can make a kind of world guard using the command block. (e.g. code: )
 * Using the radius argument with a teleporter hooked up to a clock circuit can be used to create an exclusion zone ("forcefield") around an x y z coordinate (doesn't have to be centered on the command block, in fact how would you disable it without an external editor if it prevented you from getting to itself?). Simply program it to teleport any player within a certain range of that point to a further away point, or just back 10 meters using relative coordinates. Note that such a forcefield wouldn't know which direction you were approaching from. For example it might push you back if you're approaching from the east but a western approach would cause it to pull you in. That probably won't matter however because anyone pulled in would be rapidly leapfrogged through the area and out the other side. NOW they're approaching from the east.
 * If you just want to murder another player with a boobytrap, a command block set to teleport someone into the void with a pressure plate on it is a much more lethal variant on the common tnt + floor trigger "land mine" trap. Or you could teleport them straight down 3 or 4 blocks using relative coordinates and kill them with suffocation damage. If they try to quickly mine their way out of it there is a good chance they'll mine the blocks in front of them but not the one enveloping their head. BE WARNED HOWEVER that using pressure plates with command blocks that use @p can be dangerous due to the fact that non-player entities could step on it. If a villager/skeleton/sheep/loyal dog steps on the floor trigger they won't be the one affected by it because they aren't players. Instead the command block will affect the nearest player NO MATTER HOW FAR THEY ARE. If you want to use this fact for evil, try putting one inside a door in a village. Come nightfall a villager will run inside and trigger it. If other players are camping out in the village the victim will be one of them.
 * The commandBlockOutput gamerule does not affect the command block using the and,  and  commands.
 * The commands, , and will cause the command block to say user name of the nearest player in the message.
 * You can also clear players inventories, to prevent griefing and/or cheating.
 * Command Blocks can create custom Monster Spawners using the setblock command (eg:  ). Anything that counts as an entity can be spawned (except a player of course) which includes all hostile and neutral mobs, as well as minecarts, fireballs, anything that can be shot or thrown (arrows, snowballs, ender pearls, custom thrown potions, etc), fireworks, PRIMED tnt (but not unlit), falling sand or gravel, paintings and item frames, experience orbs, and even dropped items of any type (when they're in item form like in your inventory but they're floating in the world they're counted as entities). Pig/Cow/Chicken spawners can be placed in the butcher's backyard in a village to create a constant meat supply (eg   ). Note that the spawner in the last code example will spawn a chicken riding a pig. There doesn't seem to be a limit to how many levels of riders you can use (eg: a chicken riding a pig riding a cow riding a horse riding a silverfish riding a villager ("say that's a mighty odd hat you have on Farmer Brown")). Please note that if you want to use the RequiredPlayerRange tag you have to use the MaxNearbyEntities tag as well. Same deal with MinSpawnDelay and MaxSpawnDelay. Lastly, note that the y value used in both of those spawner example codes was -1, which (assuming you're not flying) will put the spawner in the surface level of the ground at your feet.

Game Rules
Game Rules allow players and command blocks to adjust several base settings.

Usage:

Disabled or Unavailable Commands
The following commands cannot be used in a command block for various reasons:

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

Arguments
After using a target (,  or  ) you can optionally use arguments. This is how you use the arguments: NOTE: Make sure you do NOT add a space between arguments or commas.

Example:

Alternatively, the coordinates and maximum (but not minimum!) radius can be provided more concisely as long as they're the first (up to four) arguments without keys, for instance:

is identical to the previous example.

Because the argument 'c' uses players from the end of a list first when negative,  may be used to select the farthest player instead of the nearest one.