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: /give <playername> command_block 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 enable-command-block to true in the server.properties file. If this line doesn't exist, you'll have to add it. You can find our video on how to do this here [Enabling Command Blocks] 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.


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:

Variable Function
@p Nearest player
@r Random player
@a All players

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.

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 Template:Cmd. 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 "/".


Examples

  • It is possible to make teleporters using the command block. (e.g. code: tp @p x y z)
  • 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: tp @p ~0 ~8 ~0 This would teleport the player 8 blocks into the air).
  • Commands using coordinates add 0.5 to whole numbers, like usual. 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.
  • The commandBlockOutput gamerule does not affect the command block using the say and me, tell and tellraw commands.
  • You can also clear players inventories, to prevent griefing and/or cheating. <playername> [item]

If you don't want to target a specific player, you can use @a, @p, or @r instead of <playername>-

Game Rules

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

Usage: /gamerule <gamerule> <true/false>

Gamerule Effect
commandBlockOutput Enables/disables text output of command block commands to console
doDaylightCycle Enables/disables day/night cycle
doFireTick Enables/disables fire updates (no fire spread or dissipation)
doMobLoot Enables/disables mob drops
doMobSpawning Enables/disables the spawning of mobs (with the exception of spawn eggs and mob spawners)
doTileDrops Enables/disables blocks dropping items when broken (includes TNT destroying blocks)
keepInventory Enables/disables keeping inventory on death
mobGriefing Enables/disables creepers, ghasts, and Wither blowing up blocks, endermen picking up blocks, zombies breaking doors, and certain mobs picking up weapons/armor
naturalRegeneration Allows/Disallows player to naturally regenerate health (if their hunger bar is high enough)


Arguments

After using a target (@a, @p or @r) you can optionally use arguments. This is how you use the arguments: @<selector>[<argument>=<value>,<argument>=<value>]
NOTE: Make sure you do NOT add a space between arguments or commas.

Argument Function
x X coordinate for the search center. Note, this cannot be a decimal value.
y Y coordinate for the search center. Note, this cannot be a decimal value.
z Z coordinate for the search center. Note, this cannot be a decimal value.
r Maximum search radius.
rm Minimum search radius.
m A player's game mode. -1=All, 0=Survival, 1=Creative, 2=Adventure
c Number of players. If negative, uses players from the end of the list first.
l Maximum experience level of players.
lm Minimum experience level of players.
score_name objective "name", the maximum score this player has.
score_name_min objective "name", the minimum score this player has.
team Checks if player is in the specified team. Inserting an '!' before the team name checks only for players not on this team. Providing no team name allows for checking for all players without a team.
name Checks for players with this name. Using =! instead of = checks only for players who do not have this name. (Example: name=!Notch)

Example: @p[x=1,y=30,z=26,r=10,rm=2,m=1,c=3,l=25,lm=3]

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:

@p[1,30,26,10,rm=2,m=1,c=3,l=25,lm=3,score_Kills_min=1,score_Deaths=2,team=Red]

is identical to the previous example.

Because the argument 'c' uses players from the end of a list first when negative, @p[c=-1] may be used to select the farthest player instead of the nearest one.