/give <playername> command_blockcan 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
truein 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.
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.
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 "/".
- 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 ~0This 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
@r instead of
Game Rules allow players and command blocks to adjust several base settings.
/gamerule <gamerule> <true/false>
|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)|
After using a target (
@r) 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.
|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
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,
@p[c=-1] may be used to select the farthest player instead of the nearest one.