Command blocks

Command blocks are a versatile addition to Minecraft which allows the player to control various aspects of the game (usually accessible via chat only) using redstone. Each command block stores exactly one command. This command is executed when the command block is powered.

While the chat console is limited and will truncate your input past a certain length, you can write more than 30000 characters in a command block and it will not complain.

This page will take you through the basics only, as the enormous variety of applications is impossible to cover here. Command blocks are used for entity manipulation, complex games, reward rooms, cellular automata, self-building structures or, in general, anything in need of a simple programming language in Minecraft.

  • Commands are considered the functions of command block programming. There are many, but the important thing is that almost every command has a series of arguments or parameters. When they are executed or called, they run a series of statements invisible to the player – thus, a give command will internally check if the player exists, check if the item exists, generate the item, find the first free space in the player’s inventory and place it there, returning errors if any of these steps fails (note this is merely an example and the real process is much more complicated if JSON data is added, see below).
  • Command blocks can be thought of as the rough equivalent of a multi-threaded language – that is, you can execute as many command blocks as you can reach with one redstone pulse in one tick at the same time. Barring lag, all of them will run in that same tick.
  • Control flow in programming refers to redirecting the execution of a program somewhere else, skipping a certain section or repeating it one or more times. In command block programming, this is done in what may seem a slightly unconventional manner.
    • Commands can be chained together by sequentially powering them, be it with redstone repeaters or with the use of the chain command block, described below. You can create ever bigger functions by chaining many sections of your creation together and then taking the whole thing and executing it with just one pulse.
    • Any of the logic gates mentioned previously can be used as a means of control flow. Conditional branches such as if-then-else with as many conditions as you want can be created by joining outputs representing certain inputs using Boolean algebra.
    • If you want to emulate programming loops, you can use the repeat command block (more information below). While loops are easy as you can just unpower the command block when your desired condition (compound or not) is false. For loops are harder – a common way is using the scoreboard command to store and update a local database with a counter. We will not be covering scoreboard here as it is very hard for beginners, but there is a full reference on the official wiki.

Obtaining

If you search for command blocks in the creative menu, you will not find them. This is also the case for other reserved blocks such as structure blocks or barriers. To obtain a command block, you must type the following in your chat:

/give command_block

You can obtain an entire stack by typing the number 64 after that if you want, but you’ll only need one if you’re in creative. While on the topic, if you are in survival you won’t be able to break command blocks, as they are not vulnerable with any tool and have the same blast resistance as bedrock.

Types

It used to be the case that there was only one possible command block, the orange one. If you wanted functionality provided by the other two you had to use workarounds. These are the three currently possible types of command block: