Commands are short lines of text that make things happen in Minecraft: give items, teleport players, spawn mobs, change the weather and much more. They are also the easiest way to add logic to an add-on, because you can bundle them into functions.
The quick way: GodCraft
In GodCraft you write commands inside a Function, with hints that suggest command names and arguments as you type.
- Open the Workshop and add a Function to your add-on.
- Type your commands. The hints help you get the syntax right.
- Choose when it runs: every tick, once on world load, or only when you type
/function. - Export it together with the rest of your add-on.
The rest of this page teaches the command language itself, which you need either way.
Turn on cheats
Most commands only work when cheats are on.
- Open your world's settings.
- Turn on Activate Cheats (in the Game or Cheats section).
- Open chat and type
/. A list of commands appears.
Achievements
Turning cheats on disables achievements for that world, even if you turn them off again later. Use a separate test world for add-on work.
A few commands, like /say and /tell, work without cheats.
Command syntax
Every command starts with its name, followed by arguments separated by spaces:
/give @p minecraft:diamond 5giveis the command.@pis who gets the item (a target selector, see below).minecraft:diamondis the item ID. For vanilla items you can leave outminecraft:.5is the amount. It is optional: leave it out and you get 1.
Reference pages show required arguments and optional ones. For example, /give needs a player and an item, while the amount and data are optional. Every argument must be in the right order, and you cannot skip an optional one to set the one after it.
Tip
In chat, commands start with /. Inside function files and command blocks, the slash is optional and is usually left out.
Target selectors
A target selector picks which players or entities a command affects.
| Selector | Picks |
|---|---|
@p | The nearest player |
@a | All players |
@r | A random player |
@s | Yourself: the entity running the command |
@e | All entities (mobs, items, players, and more) |
@initiator | The player who is talking to an NPC (used in NPC dialogue buttons) |
You can also type a player's name instead of a selector, like /give Steve diamond. Names with spaces go in quotes: "Steve Two".
Selector arguments
Add arguments in square brackets to narrow the selection. Separate several with commas, and do not put spaces around =.
/kill @e[type=minecraft:zombie,r=10]This removes only zombies within 10 blocks. The most useful arguments:
| Argument | Meaning | Example |
|---|---|---|
type | Entity type | @e[type=minecraft:cow] |
name | Name or name tag | @e[name=Bob] |
family | Type family of the mob | @e[family=monster] |
r and rm | Maximum and minimum distance | @a[r=20] |
c | How many to pick, closest first | @e[type=minecraft:pig,c=3] |
tag | Has a tag from /tag | @a[tag=red_team] |
m | Game mode | @a[m=survival] |
l and lm | Maximum and minimum XP level | @a[lm=10] |
x, y, z | Where to measure distance from | @e[x=0,y=64,z=0,r=5] |
scores | Scoreboard values | @a[scores={points=10..}] |
Add ! to flip a test: @e[type=!minecraft:player] means "every entity that is not a player". A negative c picks the farthest instead of the closest.
Your own mobs work too. If you made myname:critter from Your first custom mob, try @e[type=myname:critter] or @e[family=critter].
Coordinates
Positions are written as three numbers: x (east and west), y (up and down) and z (south and north).
Absolute coordinates
Plain numbers are exact spots in the world:
/tp @s 100 70 -250Relative coordinates: ~
A tilde ~ means "from where the command runs", measured along the world's axes. A number after it adds an offset.
/tp @s ~ ~10 ~
/setblock ~2 ~ ~ minecraft:gold_block
/summon minecraft:pig ~ ~1 ~~ ~10 ~is 10 blocks straight up.~2 ~ ~is 2 blocks east.- A lone
~means "no change" on that axis.
See /teleport, /setblock and /summon.
Local coordinates: ^
A caret ^ is measured from where the entity is looking: left, up and forward.
/tp @s ^ ^ ^5This moves you 5 blocks in the direction you face, even if you are looking diagonally. The three parts are ^left ^up ^forward, and negative numbers go the other way.
Note
You cannot mix ^ with ~ or plain numbers in one position. Use all three as ^ or none.
Running commands as others
/execute changes who runs a command and where. It is the most powerful command in the game:
/execute as @a at @s run summon minecraft:lightning_bolt ~ ~ ~Read it from left to right: for every player (as @a), at their own position (at @s), run a summon. Inside /execute, @s means each selected entity in turn and ~ ~ ~ is their spot.
A few commands to try
/give @s minecraft:diamond_sword
/effect @a minecraft:speed 30 1
/time set day
/weather clear
/say Hello, world!
/kill @e[type=minecraft:item]- /effect gives Speed II for 30 seconds (amplifier 1 is level II).
- /time and /weather change the world.
- The last one clears all dropped items, which is handy when a test gets messy.
What next
- Put commands in a file so you can run many at once: Functions and command blocks.
- Run /function to trigger them from chat.
- Browse every command in the commands reference, starting from /execute.