Skip to main content

Minecraft Commands and Command Blocks

The server should be set up with permission groups, so the kids should be able to use commands without needing Op (short for operator, means full admin permissions and gives a player a lot of power over the server). However, we’ll need to turn it on later in the Command Blocks section of this lesson.

 

(Again, start with all the monitors off and all the players frozen. We’re going to teach about commands first, then they get to build and play.)

 

What is a command? 

Remember when we talked to other players on the server using the chat box? A command is just like that, except we’re talking to the server and telling it to do something. 

We’ve actually already used commands, when we first started on the server by making a plot or when you changed your gamemode.

Commands always start with a slash “/” to tell the server that we want to talk to it rather than another player.

There are several commands in Minecraft. These are just a few of the most common ones you’ll use (there’s a poster in the room with this list of commands on it, show them that). 

Common Commands

  • /me <text> - Says your name then <text>, useful for describing actions as if you were doing them (e.g. /me plays minecraft would result in “PlayerName plays minecraft”)
  • /tell <player> <message> - sends <player> a private message with the text <message>. Only the specified player can see this message.
    • There are several other commands that do the same thing:
    • /msg
    • /whisper
    • /w
  • /time set <value> - Sets the current time of day to <value>, between 0-24000. 0/24000 is sunrise, 6000 is noon, 12000 is sunset, and 18000 is midnight.
    • /time add <value> will add to the current time instead of setting it.
  • /give <player> <item> [amount] [damage/data value] [data tags] - Gives <player> [amount] of <item>, or 1 of <item> if [amount] is not used. [damage/data value] will be the damage for tools, or for blocks with several variants like wool, a number specifying which variant to use. [data tags] are beyond the scope of this class, but are basically just values that can change more properties of the item, and can do things like renaming it or adding enchantments.
  • /tp <player> - teleports you to <player>
    • /tp <target> <destination> - teleports <target> player to <destination> player. Can be used to teleport other players to you.
    • /tp <target> <x> <y> <z> - teleports <target> player to the coordinates (<x>,<y>,<z>). Coordinates will be discussed later when talking about command blocks.
  • /weather <clear|rain|thunder> - Will set the weather to clear, rain, or thunder. If an incorrect option is entered, it will fail.
  • /gamemode <survival|creative|adventure|spectator> [player] - will set your own gamemode to the gamemode specified, or will set [player]’s gamemode if a player name is given.
  • And many more… A more complete list is on the poster in the classroom, and an even more complete list can be viewed in the appendices or by running /help.
  • On our server: /p home, /p trust <name>, /p deny <name>, /p flag <set, add, remove, > <weather, time, use, > <value>

 

Command arguments

Some of these commands are written with angle brackets around some text. This means that these commands need extra information to run.

For example, a command like /clear doesn’t need to know anything, because all it does is clear a player’s inventory. You run it, and it clears your inventory. However, a command like /give, which gives an item to a player, needs to know more things to do its job. 

Ask: Does anyone know what /give might need to know to do its job?

  • The target player’s name (who to give the stuff to)
  • The item name (what kind of stuff to give)
  • How many of the item to give
  • Other information about the item, like special values for how damaged it is or to change enchantments

These extra bits of information we give a command are called command arguments. Have you noticed how we can’t put any spaces in a command? That is because spaces tell the server where one argument ends and the next one begins. 

Take the command /give king8343 diamond_sword 1, for example. If the server is reading the item name and comes across a space, it stops reading the name and starts looking for the next argument, which is the item amount. If you put spaces in an item name instead of underscores (“diamond sword” instead of “diamond_sword”) the server will think “diamond” is the name and “sword” is the amount to give, which doesn’t make any sense to it. You’ll get an error if you try that.

Going back to the way the commands are written in reference: commands are often written with their name, then for arguments, angle brackets and some text describing what the argument is. 

Optional arguments are often written with square brackets. Optional arguments are arguments that do not need to be given for the command to do its job. For example, the damage argument in /give is not needed if you don’t want to give someone a damaged item. If you do want to give someone a half-broken sword, for example, you can give the server a number for damage, but it is not required for the command to run.

 

To recap:

/command tells the server that we want it to do something. “Command” will be the name of the command we want the server to run.

<description> means the argument is required, and “description” will describe what is needed. 

[description] means the argument is not required, and “description” will describe what is needed.

 

Command selectors

Have you noticed how several commands ask for a player’s name? You can also use special things called command selectors that have the server pick a player.

  • @a stands for all players on the server. For example, If you run /give @a diamond, a diamond will be given to every player on the server.
  • @p stands for the nearest player to the person running the command. If you want to give a diamond to someone next to you, do /give @p diamond.
  • @r stands for a random player. The server will choose a player at random. If you want to do a lottery, for example, do /give @r diamond. A random player will get a diamond!

 

It’s time to use what we learned. However:

Make sure everyone understands that commands and command selectors are very powerful, and that if someone abuses them, that person will not get to play for the rest of the day. Everyone should try to be careful about what commands they use and try not to hurt anyone. Dangerous or harmful commands should not be used (e.g. DO NOT use /tp with @a, don’t fill people’s inventories up if they don’t want you to, don’t kill any other players).e

Let them turn on the monitors and have them play around with commands until the break. Tell them to try out a few different ones off the list.

 

 

Command Blocks

Ask if anyone already knows what a command block is. There’s a good chance some of them will already know.

Previously, we had to execute commands ourselves, by using the chat box. However, there’s another way to run commands, and it can happen automatically. We can use what is called a command block.

A command block is a device that a player can enter a command into. When the command block is activated by redstone power, the command will be executed. This lets you make machines that run commands automatically. 

A command block can be set by right-clicking on it, which makes a menu appear, as shown below:

 

There are a couple different types of command blocks (you won’t use these very much, most of the time you will use the “regular” or Impulse command block):

  • Impulse - Runs a command only once. This is the “normal” or default command block. You will use this most of the time.
  • Chain - Can be hooked up with in a row with other chain command blocks, and when a command block at the back end of the chain gets activated, all the command blocks in the chain are activated one by one. Chaining command blocks means that redstone isn’t required to run the blocks in the chain. You have to change “Needs Redstone” to “Always Active” for these to work.
  • Repeat - Will run its command over and over while it is activated. Useful because you don’t need as many redstone clocks.

Coordinates

Coordinates are a way of representing an exact location in a Minecraft world. A good way to explain coordinates is with a grid.


On this grid, you can represent any location by using its distance on each dimension from the origin, or center of the grid. Minecraft worlds are the exact same way, but with 3 dimensions.
The origin is located at the center of the world, at bedrock level. X is backwards (west) and forwards (east) in one horizontal direction (east-west), Y is up and down, and Z is backwards (north) and forwards (south) in the other horizontal direction (north-south).

How to find a location in Minecraft

  1. Have everyone press Fn+F3 (it’s normally just F3 but these are Macs). The debug menu should appear, which gives the player detailed information about what is going on under the hood, such as how fast the game is running or where the player is looking, which is what we want to find.
    2017-05-25_18.19.22.png
  2. Place a block at the location you want to use. If you’re planning to teleport someone here, note that location is measured by where the feet are for players.
    2017-05-25_18.21.15.png
  3. Point your crosshair at the block, then look at the “Looking at” section of the debug text.

    The three numbers after “Looking at” are the coordinates of the block. This particular block’s coordinates are -422, 69, 136, meaning that it is 422 blocks backwards or west from the origin, 69 blocks above bedrock, and 136 blocks forwards or south from the origin. These three numbers are what you want to use in a command that asks for coordinates; write them down.
  1.  
  2. Remove the block when you’re done writing down the coordinates.
  3. Enter the coordinates in a command that asks for coordinates, such as /tp:

 

  1. 2017-05-25_18.28.08.png
    In this example, when this command block is activated, it will teleport the nearest player to the location we chose at the beginning. Success!

Example Usages

  • A button to change the time of day, or change the weather
  • A button or pressure plate that teleports whoever pushes it to a secret location (using coordinates)
  • A vending machine, that will give players who push buttons certain food items

Time to Build

You will need to op all players on the server by doing /op <player> in order for them to be able to use command blocks. This isn’t very desirable, which is why we have the permission groups set up instead of the Op/No op system Minecraft has by default, but it is a rule in Minecraft that only Opped players can use command blocks. Make sure each player is aware, as before, that any abuse of their privileges will result in them sitting out the rest of the day. Also make sure that they understand this is the only day to use command blocks; after the day is over, de-op each player by running /deop <player>.

Give the kids this challenge: 

Make three different command block devices. It’s okay if they are simple, but they have to be different (e.g. not just three command blocks that run the same /give command with a different item).

 

While they’re building, keep checking to see if anyone needs any help or advice on anything. Everyone should only be able to build in their own space; try to keep them focused on the task at hand.


At the end, maybe show off people’s devices (or just the best/coolest ones) on the big screen (if time permits - for something more complex like this, it’s probably best to leave as much building time as possible).