42

What are the basics of Minecraft commands? If I were to start from scratch, with no knowledge on the topic, what are some things that I need to know?

1
  • 12
    For those voting to close this question: this is in reaction to the recent Community Check-in on Meta. One of the popular suggestions was to have what essentially is a reference question and answer related to Minecraft commands. This is meant to help reduce the large amount of low quality questions related to Minecraft commands and have a way to close them as a duplicate instead of closing them as unclear. As such, this question naturally has a broader scope than usual questions, but that's fine in this case since it's meant as a reference question.
    – Nzall
    Jul 18, 2019 at 7:23

1 Answer 1

52

Basics of commands and arguments

Minecraft's commands system allows players to modify the game in ways besides mining and placing blocks. Commands have different arguments that specify their behavior, such as a selected entity or specified location.

For example, the very basic version of /summon has two arguments:

  • An entity to summon
  • A location to summon it at

It is important to note that the term “entity” does not only refer to mobs, such as creepers and blazes, but also to other objects that are not blocks, including item frames, paintings, snowballs, and dropped items.

Knowing the /summon command's arguments, we can fill them in like so:

Example

Summon a wither skeleton at the position (0, 80, 0).

summon minecraft:wither_skeleton 0 80 0

Relative and local coordinates

This, however, is very limiting: what if we wanted to summon an entity at our current position? This is where relative cordinates come in.

Relative coordinates are used by putting a ~ instead of a number. To summon a silverfish at my current location, you would do /summon minecraft:silverfish ~ ~ ~.

If you want to add an offset to the location of the relative coordinates, you can do so by typing numbers directly after the ~.

Example

To summon a lightning bolt 1 block east, 2.3 blocks up, and 17.914 blocks north:

summon minecraft:lightning_bolt ~1 ~2.3 ~-17.914

There are also local coordinates, which use carets (^ ^ ^). These work identically to relative coordinates, but any offset you use is offset based on the direction that the executing entity is looking.

Example

Summon a fireball one block in front of the executing entity's crosshairs:

summon minecraft:fireball ^ ^ ^1

You cannot mix local coordinates with other types of coordinates. All three axes X, Y, and Z must either all use ^ or not.

Target selectors

Alongside positional coordinates, which select a position in the world to work with, there are also arguments which select an existing entity within the world to work with. These are named target selectors, but can be called entity selectors as an alternative name.

The most basic entity selector is simply the @ sign followed directly by one of five letters. There are five options:

  • @s selects the self (the entity executing the command)
  • @p selects the closest player (to the executing position)
  • @r selects a random player in the world
  • @a selects all players in the world
  • @e selects all entities in the world

Target selectors also accept arguments, which are filters to further narrow the amount of entities selected. These range from selecting entities based on what type of entity they are, to filtering based on their location, or even based on their name, or the number of XP levels they have.

Selectors are useful if you want to do anything to anyone besides named players:

Analysis

kill @e[type=minecraft:item]
  • The command is /kill. /kill accepts a single argument, an entity selector that selects which entity to kill.
  • The target selector is @e[type=minecraft:item]. The @e says to start with a list of all entities. Then, type=minecraft:item filters the list to only include item entities and nothing else.
    All entities that are within the list after filtering will be killed.

Therefore: This command will kill all entities of type minecraft:item. This means that all dropped item entities will be killed.

It is at this point that it should be noted that commands are case-sensitive. This means that you cannot put a capital letter where there should be lowercase, or vice versa. Many broken commands have been fixed by correcting a misplaced capital or lowercase letter, so make sure you are always very careful about what you are typing.

Because there are so many different selector arguments, we won't be covering them all here. If you would like to see what's available, click the link above to view a full list on the Minecraft Wiki.

That being said, we have a few important things to note:

  • x=, y=, and z= are special arguments. They are different from the rest in that they are not actual filters, but they instead provide information to other filters. x=, y=, and z= define a position in the world where the other filters are calculated from.

    Analysis

    kill @a[x=1,y=2,z=3]
    
    • The command is /kill. /kill accepts one argument, an entity or list of entities to remove.
    • The target selector is @a[x=1,y=2,z=3]. The only filters present are x=1,y=2,z=3, defining a position for other filters to be calculated from.
      But there are no other filters that will utilize this position.

    Therefore: The target selector @a[x=1,y=2,z=3] does not perform any filtering. This command will kill all players in the dimension that you run this command from.

/execute command

This is all very useful, but how would I go about summoning a lightning bolt onto every creeper in the loaded world? The /summon command has no entity selector, and I don't want to go around writing down the coordinates of every creeper that I can see. The solution is the /execute command, arguably the most important command in the game because it is able to change the 'metadata' behind a command: who's running it, where they are, which direction they are facing, among other things. The /execute command has several different specifiers we can attach to it to make it run commands in different ways. One of these is the at specifier, which allows us to choose which entities we want to run some command at. In this case, we would want to do /execute at @e[type=minecraft:creeper] run summon minecraft:lightning_bolt ~ ~ ~. This would run the command "summon a lightning bolt here" from the position of all of the creepers.

It is very important to remember who is executing a command and where is the command being executed from. An example of the problems that happen when you forget this is the command /execute at @e[type=creeper] run kill @s. At first glance, this may seem like it will kill all creepers loaded in the world, but it won't. It will kill the entity who runs the command, because @s refers to the self (kill self) and no matter where the command is executed (even if it is at the position of all creepers) @s still refers to whoever is running the command. A fix might appear to be /execute positioned as @e[type=creeper] run kill @s, but this has the same problem: the executing entity is still the entity who runs the command. To fix this, one would run /execute as @e[type=creeper] run kill @s. Now, @s refers to @e[type=creeper]. Of course, one could just do /kill @e[type=creeper], but this is just an example problem.

NBT Data

This is all very well and good, but what if we want to do something more complicated, such as give a random player an unbreakable golden sword with Fire Aspect II which has the bolded, non-italic, dark-red name "Flame Boi" and eats non-gamers? This is where NBT comes in. NBT stands for Named Binary Tags, and it essentially allows you to set certain attributes of items, blocks, entities, etc. beyond just their location. NBT data consists of tags which have a name and a value. Sometimes, a tag may have multiple or nested values, in which case a list [] (series of values) or compound {} (tags within a tag) will be required. A full list of NBT tags is on this site, but right now we will just use the ones required for the sword. To give the sword, we would use

/give @r minecraft:golden_sword{Enchantments:[{id:"minecraft:fire_aspect",lvl:2}],Unbreakable:1,display:{Name:"{\"text\":\"Flame Boi\",\"color\":\"dark_red\",\"italic\":\"false\",\"bold\":\"true\"}",Lore:["{\"text\":\"This sword eats non-gamers.\"}"]}} 1

To break it down, Enchantments:[] is a list of enchantments, each of which is a compound tag (enclosed with {}) with multiple, comma separated modifiers. The id:"" tag is a String (series of characters) so it's enclosed in quotes, while the level:#, being just an integer, doesn't need any quotes. The golden sword's Unbreakable:# tag is set to 1 so it lasts long enough to actually kill something, and the display:{} tag carries all of the information needed to display the item in the inventory, such as the name and lore. The Name:"" tag is actually a String (if you want to color it and change the font type) and because of this it gets formatted in a special way. Because quotes by themselves are interpreted as containing Strings, they need to be "escaped" with a backslash so they actually get sent in as part of the Name:"" String. This means that without the backslashes, our Name:"" command looks like this: {"text":"Flame Boi","color":"dark_red","italic":"false","bold":"true"}, which is much more decipherable. Finally, Lore:[] is a list of lines of lore to display, where each line (delineated by {something something something}) also needs to have escaped quotes so it can be interpreted properly.

Additional NBT tips A very helpful command for learning about NBT tags is /data get entity @s SelectedItem. It tells you all of the NBT tags that the item that you're currently holding has.
That includes custom names, colors, enchantments, etc.
To use it you can craft, find, or /give yourself the item that you want to use, rename and enchant it with an anvil and then hold it. Run /data get entity @s SelectedItem to get all of the tags that the item has that you may need to /give yourself an identical item.

A helpful keyboard shortcut is F3+I, it will copy a /setblock or /summon command into your clipboard that you can use to set a block, or summon an entity that will be identical to the one you're looking at, including all NBT-tags and block states.
You can copy that command into a text editor with Ctrl+C to learn a lot about NBT tags. If you want a /summon command for a horse with blue leather armor, you can find or /summon a horse, give it blue leather armor, then look at it, press F3+I and copy the command into a command block, no changes required. You won't need all of the NBT tags in most cases, you can make the command shorter by removing excess NBT tags. Make sure to test the command a few times in the process to make sure you didn't break anything.
The keyboard shortcuts provided here are for Windows users, they may be different for mac, linux, or other systems

Conclusion

If you've read through this and still have a question on how a command works or where to put an NBT tag or something similar, be sure to read the wiki about that command, or this website which has the data types in NBT, this website which lists the NBT tags in Minecraft, this website which contains information on player NBT, or this website which has information on chunk NBT.

NBT is very similar to JSON, so several links which may help explain JSON are this, this, this, this, and this. Don't worry if you don't have any programming knowledge/experience or if it is too technical for you: JSON is related to NBT in structure but you don't need to know about server-client data interchange or anything like that to use NBT. This is a good JSON validator, however be wary: JSON and NBT are not the same, so valid nbt such as {Enchantments:[{id:"minecraft:infinity",lvl:1}],Unbreakable:1,display:{Name:"{\"text\":\"Epic Pearl\",\"color\":\"light_purple\"}",Lore:["{\"text\":\"Yaw yeet\"}"]}} will be flagged as incorrect JSON because the String identifiers (id, lvl, etc.) are not enclosed with quotation marks. It's better to figure out why something is broken by hand (tracing braces/brackets, retyping it, checking capitalization...) than be misled by a JSON checker which operates by slightly different rules than NBT. However, /tellraw and /title use strict JSON (which can be found here) so the above tool is very useful for helping create those types of commands.

If you have read through this guide and are ready to ask a question about , make sure to read this guide which gives some pointers on how to ask your question.

8
  • From what I see, NBT uses JSON. This is very popular format with many tools built around it (such as online syntax validators). It may be worth adding some links about it.
    – arghtype
    Jul 17, 2019 at 18:07
  • 2
    @arghtype Added links for examples of JSON as well as tutorials that weren't too technical. As soon as I find a decent syntax checker (that isn't too complicated) I'll link it too.
    – Nik3141
    Jul 17, 2019 at 19:46
  • You may want to mention the commonly used commands (/setblock, /kill, /tp, etc.)?
    – L. F.
    Jul 18, 2019 at 2:34
  • @L.F. I linked the wiki with the list of all commands, but I think you're right. I'll add a new section with quick links to common commands and a short explanation of each.
    – Nik3141
    Jul 18, 2019 at 2:38
  • 2
    If you don't know how to do the JSON code, you can use jsoneditoronline.org (to avoid problems). It works even with the "broken" JSON used in NBT. An example, using your code: jsoneditoronline.org/?id=0c83060741d14cd7a94de655ffae074d (it will show a syntax error, but, click on the button with an arrow to the right). Disclaimer: I have absolutely NO AFFILIATION AT ALL with the provided tool. Jul 19, 2019 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .