Link Search Menu Expand Document

Command Tutorial

Table of Contents
  1. Command Tutorial
  2. Beginning
    1. What are commands?
    2. Why commands?
    3. Beginning
    4. Basics
      1. What is a block?
      2. What is an entity?
      3. What is a syntax?
      4. How do I read a syntax?
    5. Coordinate Management
    6. What are coordinates?
      1. What are Tildes?
      2. Local Coordinates (Caret Notation)
    7. Entity Management
      1. Deleting an Entity
      2. Targetting
    8. Execute
  3. Exporting a Map
  4. Functions Structure

Beginning

Written by VideoCarp

Estimated Read Time: 6:58 (minutes)
Firstly, since you’re new I recommend reading to full.

What are commands?


Commands are bits of text that the game Minecraft understands, they can get quite advanced, but they’re easy to pick up and learn.

Why commands?


Commands are very useful, they’re great to work with, even when making addons, written in JSON, they can help.
Most maps are also made using Minecraft commands, they’re very helpful.

Beginning


Firstly I’m going to cover some logic, this is probably the most important part. There’s a lot to cover, but I’m mostly going to be covering the beginner’s basics.
In Minecraft, there are 2 types of things, as a summary. Those 2 things are entities and blocks. You might’ve heard of those a lot, and they’re very important.

Basics


Here are some of the basics, read above for a bit of how to read this.

What is a block?


A block is essentially an object that takes up a 1x1 space. An example of a block would be say grass, dirt, etc. Everything in the below image is a block, don’t worry about the water just yet.

grassblock

What is an entity?


An entity as I like to think of it is any object that is not fixed to it’s position, and can take damage. Water isn’t fixed to it’s position, is it an entity? No, the reason for that is because water cannot take damage.
All mobs, but NOT only mobs are entities. Below is an example of an entity.

chicken.png



Now that you know what entities and blocks are, that’s a step forward.

What is a syntax?


A quick explanation I’ll give about syntaxes is that they’re the format of the command, if your command doesn’t
execute, then there’s a chance it’s that. Give all syntax errors a full read, if they don’t work, take reference
from either the wiki, gamepedia, or the /help <command-name> command while in game.
An example of a syntax error is: /kill @ e. That specific one will be raised because there is a space between the @ and the e. We’ll go deeper into these @ things in a bit. Below is an example of a syntax error. This most likely happened because the person didn’t put an argument afterwards, but don’t worry too much.
error example

How do I read a syntax?


Here’s a quick sumnary, it isn’t really accurate (I personally don’t read them and somehow know it):
Don’t try to memorize the something: type ones if you don’t understand.

  • <text_here>. These brackets mean that this argument is required.
  • [text_here]. These brackets mean that this argument is optional.
  • (option1 | option2). These brackets mean that this argument must be one in the list.
  • |. This character in a bracket means ’or‘.
  • something: int. If : int is after something, that means the argument must be a whole number, also known as integers.
  • something: string. If these are after something, that means the argument must be text, also known as string or str.
  • something: float or something: double. If these are after something, that means the argument has a decimal place.

    Coordinate Management


    This is a crucial part in commands.

    What are coordinates?


To put it in my way, coordinates are really just the location of an object. But how do you know the coordinates?
How are coordinates formatted? Well, regarding both of them, there are three axes, namely X, Y, and Z.
How are they formatted?
They are formatted in the standard way, x y z, and you’ll see more about those later.
How does one get the coordinates of something?
It’s quite simple to do this, you do not need to teleport yourself. You can simply run this command:
/gamerule showcoordinates true and your coordinates should show at the top left. Once they’re showing, read the numbers after
Position. It should look somewhat like this: Position: X, Y, Z. If it doesn’t show exactly like that, don’t panic. X, Y, and Z are used to represent the number, whatever it is, is where your legs are. We’ll be getting into
tildes on the next section, they will be necessary.

What are Tildes?


Tildes are the ~ character, which in English means about, near, or here.
Same thing goes for coordinates in Minecraft.
Each tilde in a command represents from where the command is being executed, and math can be done on those.
To add to the coordinate: ~<number>. This goes for all X, Y, and Z axes. You can also use ~+<number>.
To remove from the coordinate: ~-<number>. Note the -. This goes for all axes.

Say you want the player to teleport 10 blocks upwards, remember the Y axis is vertical.
tp <target> ~ ~10 ~.
Now what is target you may ask. Target means the entity the command is being executed on.
This command moves the player 10 blocks up from the command block if there is one, or the person who executed it.
Don’t worry yet about making the player do it, we’ll cover it now.

Local Coordinates (Caret Notation)


‘Caret Notation’ is another important part in Minecraft commands, it is local coordinates, it’s a bit like tildes, however it’s based on direction. Here’s a quick summary:

  • X The X axis moves player to the left.
  • Y The Y axis moves player up.
  • Z The Z axis moves player forward.

You may have thought that not all directions are covered in Caret notation, but really, they are. Tildes and Carets both take + and -, so to go backwards, you can teleport the player using ^ ^ ^-1, and that will send the player 1 block backwards.
Adding - in carets will go to the opposite direction of the axis, right and down are done the same way as backwards, except with the different coordinate. Both carets and tildes are X Y Z (^ ^ ^).

Entity Management


This section is on how to manage entities. There are a lot of commands that can affect entities, but here I’ll cover the crucial ones.

Deleting an Entity


It’s very easy to delete an entity, you can simply use the kill command to delete an entity. But what if you wanted to delete a dropped item, or perhaps a specific mob? Below is more info.

Targetting


You can use the target selector argument, which I will be specifying information about right here. You can use the @e targetting, but further than that is what we’ll be focusing on.
Target Selectors What are these? Well, I like to explain these as the main argument in selecting which entity to use.
A list of each one of them, and what they do is below:

  • @p This selects the nearest player from where the command was executed.
  • @r This selects a random player in the world who is online.
  • @s This selects the entity that executed the command. All entities, not only players included.
  • @a This selects all the players.
  • @e This selects all entites.

For example, I want a creeper to say Aww man in the chat, I’d use:
execute @e[type=creeper,name="creep.er"] ~ ~ ~ say Aww man.
You see those things in the [] brackets? They will be covered next.

@e[type=<entity_type> will select a specific type of entity, this could be TNT, a dropped item, a specific mob type, etc, it can find any entity type. But what if you wanted a specific entity?
@e[type=<entity_type>,name=<name>. With that, you’ll find one of a name.
A very common issue I find others doing is when they’re getting the name, they usually forget to add quotes after the = sign. If the mob has a space in the name, simply instead of <name>, imagine it becomes "<name>".
The name argument may be ugly, and so here is an alternative, this is also a way to group entities. /tag <target> (add | remove) <name: string>.
This will add a new group to the targetted entity, after adding it you can remove the name, if there is one.
Now string means to add quotes, just like the name in the target selector. In commands, and programming, string is just text data, which in most cases are set by ". In Minecraft, use ".
An example of a string is: "Hello World!". In Minecraft, if you wrap with these quotes, you can use any character for any argument, including spaces. You may want to check for the range, here’s how:
@e[r=<range number>]
In most guides, number will be represented as int or integer. They both mean a number. However, an int is not float nor double (if you’re unsure ignore those two words), it cannot take a decimal value. 1.01 for example, is not an integer. An integer is just a whole number.

Execute


This is an extremely important section! This section is fully dedicated to making entities execute a command, think of it as sudo, but for commands.
The execute command is the most powerful command in the entire game, but don’t worry, it isn’t hard to pick up on. /execute <target> <location> <selected command syntax> is the syntax. <selected command syntax>
refers to the command you’re getting the entity to execute. I always have my location as ~ ~ ~ and when it’s
like that, it executes anywhere, that’s at least what I use for myself.
But what if you wanted to check if someone was on a specific block type?
execute <target> <position> detect <detectPos> <block_to_detect> <data value> <command>.
That would be your syntax. detect isn’t in brackets, this means to just put it there, regardless.
Say you wanted a creeper walking on grass to kill nearby ocelots, you’d use this: ` /execute @e[type=creeper] ~ ~ ~ detect ~ ~-1 ~ grass kill @e[type=ocelot]`

Quick notice, when stuck, try to use use effect, armor stands, tags and names.

Exporting a Map

Visit here to see how to.

Functions Structure

Functions are very simple to make, here’s a basic folder structure: Functions are a way to kinda import a ton of commands into new worlds easily, unlike command blocks however, they cannot be conditional.
When you run the function command, it executes the .mcfunction file named by your argument.

For example, a file named cool_file.mcfunction will execute if you return the argument as cool_file in other words,
/function cool_file , however, if a different argument is written, the game will search for the .mcfunction file named by that, if none, the command will fail.

.mcfunction files are always filled with nothing but commands.

Now for the folder setup.

Function Pack Structure:

(your pack name)📂

<pack_icon.png>📄

(functions)📂, <manifest.json>📄 , <pack_icon.png>📄

<filename.mcfunction>📄

Here are some open-source examples of raw commands on GitHub.