Minecraft/Commands

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Commands can be executed on any version of Minecraft which has the chat console. To run a command, type a forward slash. There are many commands to learn.

Variables
How to select What it is
~ Inserts the current axis position when used inside a position argument. This can be used so you don't need to know your coordinates, or if a command block is likely not going to be in a set location. You may add a number after it, positive or negative, to add an offset, so ~~-3~ is 3 blocks below, and ~~3~ is 3 blocks above. ~ 3 ~ would be an absolute y=3. ~3~ would not be invalid, however, as there is only an x and y, but not a z.
@p The closest player.
@a All players.
@r Random player.
@e All entities.
@s Self. Note that this does not work on command blocks unless using the /execute command.

The @ selectors also allow finer tuning, like this: @r[r=10,tags=alive] checks for a random player within ten blocks, with the "alive" tag (set with /tag). All of them are:

  • r: range. Note that this is a radius!
  • tags: checks if a tag exists on that entity.
  • type: checks its identifier matches. The identifier is usually a snake_case (all lowercase, underscores instead of spaces) version of its name.
  • x / y / z: If a coordinate matches.
  • dx / dy / dz: distance from x / y / z. Note, an x of 0 and dx of 5 will only check x=0 to x=5. Set dx to -5 to reverse this, or x to -5 and dx to 10.