Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chapter 6 — Command Blocks

What You’ll Build

In the last five chapters every command you ran vanished the moment it finished. You typed it, pressed Enter, watched it work, and if you wanted it again you typed it again. At the end of Chapter 1 you felt the itch: “I wish I could run all of these at once.” This chapter scratches the first half of that itch by moving a command off your keyboard and into the world, where a button press, a lever, or a trail of redstone runs it for you.

The tool is the command block: a special block that holds a command and runs it when redstone powers it. By the end of this chapter you’ll hand yourself a command block, type a command into it, and trigger it with a button. Then you’ll line several command blocks up so a single button press fires a whole sequence in order, turning that ten-line “set up my test area” routine from Chapter 1 into one press of one button. Along the way you’ll meet the three kinds of command block and the switches that change how each one behaves. And at the end you’ll bump into the wall that command blocks can’t get past, which is exactly the wall the rest of the book is built to knock down.

Everything here happens in your Creative test world with cheats on, the same world you’ve used since Chapter 1.

Concepts

A command block is an indestructible block that runs a command when it’s activated by redstone. You can’t craft one, mine one, or use one in Survival without cheats, so it isn’t a normal building block. It’s a tool for Creative worlds, servers, and custom maps. Think of it as a command you’ve written down and nailed to a spot in the world, ready to fire whenever it gets a redstone nudge.

There are three kinds, and the game colors them so you can tell them apart at a glance:

  • An impulse command block (orange) runs its command once each time it’s activated. This is the default, and the one you’ll use most.
  • A repeating command block (purple) runs its command every game tick (20 times a second) for as long as it stays activated.
  • A chain command block (cyan) runs its command when the command block pointing into it runs. It’s the link you use to join blocks into a sequence.

Under the Hood (skippable) A command block always runs at permission level 2, the operator level. That’s genuinely useful on a server: you can offer players a button that runs a /give they’d never be allowed to type themselves, without handing them operator powers. You don’t need this yet; it’s just why command blocks are considered an “operator” tool.

Getting a command block

You can’t find a command block in the normal Creative menu unless you switch it on, so the quickest way is the /give command you already know from Chapter 1. Open the chat box and type:

/give @s command_block

A command block drops into your inventory. Place it like any other block. (You can only place and break command blocks while you’re an operator in Creative mode, which in your test world you are.)

To put a command inside it, point at the block and use it (right-click) to open the command block GUI, the little editing screen. Type your command into the top box. One nice difference from the chat box: inside a command block the leading slash is optional, so give @s diamond and /give @s diamond both work. Press Tab to autocomplete as you type, then click Done (or press Enter) to save and close. The bottom box, Previous Output, will show the result the next time the block runs, which is handy for spotting a mistake.

What Went Wrong? “Right-clicking the block does nothing / I can’t open it.” The command block GUI only opens for an operator in Creative mode with cheats on. If you’re in Survival or cheats are off, you’ll just place a block you can’t edit. Make sure you’re in your Creative test world.

Triggering it with redstone

A command block sitting there does nothing on its own. It needs to be activated by redstone power. The simplest power source is a button or a lever stuck to the block, but anything that delivers redstone power works: a lever, a button, a block of redstone, a pressure plate, or redstone dust pointing at it.

Let’s build the kit button you’ve been wanting. Place a command block, open it, and enter:

give @s diamond_sword

Click Done. Now stick a button on the side of the block (place the button against it) and press the button. A diamond sword lands in your inventory, and it will do so every single time you press, without you ever opening the chat box again. You’ve just built your first machine.

Try It! Put a stone button on the front of the block and label the contraption in your head: “sword dispenser.” Press it five times and watch five swords appear. That repeatability is the whole point of a command block: type the command once, run it forever. Figure (to be captured). a command block with a stone button on its front face, and a diamond sword in the player’s hotbar after pressing

The three switches inside a command block

Open the command block GUI again and look at the row of buttons. Three of them change how the block behaves, and they map onto the three types and a couple of options:

  • Block Type cycles Impulse → Chain → Repeat. Impulse runs once per activation; Repeat runs every tick while powered; Chain runs only when triggered by a block aimed into it. The block changes color (orange, purple, cyan) so you can read a build at a glance.
  • Redstone switches between Needs Redstone and Always Active. “Needs Redstone” (the default for impulse and repeat blocks) means the block only runs when something powers it. “Always Active” means it runs without any redstone at all, which is the normal setting for chain blocks.
  • Condition switches between Unconditional and Conditional. An unconditional block (the default) always runs. A conditional block runs its command only if the command block behind it ran successfully, which lets you build “do this only if that worked” logic.

A repeating command block is worth a quick experiment: set one to Repeat, give it effect give @a minecraft:night_vision 2 0 true, and power it with a lever. Flip the lever on and everyone has permanent night vision, refreshed every tick; flip it off and it fades. That “keep doing this while powered” behavior is what Repeat is for.

What Went Wrong? “I pressed the button and nothing happened.” Three things to check. First, the block needs redstone power actually touching it (a button on the block, a lever beside it). Second, an impulse block fires once per activation, so if the button’s already been pressed and reset, press it again. Third, on a server or in a stubborn world, confirm the command_blocks_work game rule is on (it’s on by default).

Chaining: one button, a whole sequence

Now the second half of Chapter 1’s wish: running many commands from a single press. This is what chain command blocks are for. The rule is simple: when a command block runs, it triggers the chain command block it’s pointing at, which runs and triggers the next one, and so on down the line, all in the same tick and in order.

Here’s how to rebuild Chapter 1’s “set up my test area” as one button:

  1. Place an impulse command block. This is the trigger. Give it the first command: say Setting up the test area...
  2. In a straight line, place more command blocks so each one faces into the next (place each new block by aiming at the previous one). Set every block after the first to Chain type and Always Active.
  3. Fill the chain blocks with the rest of the sequence, one command each: give @s diamond_sword, then give @s diamond_pickaxe, then give @s bread 16, then summon cow, then summon pig, then summon zombie, and finally say Test area ready!.
  4. Put a button on the first (impulse) block and press it.

The impulse block fires, triggers the first chain block, which triggers the next, straight down the line. One press, and your kit, your mobs, and both messages all happen at once. That ten-line routine you used to type by hand is now a single button.

Figure (to be captured). a row of command blocks — one orange impulse block with a button, followed by several cyan chain blocks all facing the same direction — with a freshly spawned cow, pig, and zombie nearby

What Went Wrong? “Only the first block ran.” The follower blocks must be set to Chain type and they must physically point into one another. A chain block also needs to be Always Active (or powered) to fire. If one block in the middle is still an orange impulse block, the chain breaks there. Walk the line and check each block’s type and the direction it faces.

The wall command blocks hit

Command blocks are brilliant for a contraption in one spot: a trap, a teleport pad, a kit button. But try to build something big with them and the cracks show. The commands are buried inside blocks scattered around your world, so finding the one with the typo means hunting through your build. They don’t travel: there’s no way to hand a friend “my command blocks” as a download the way you’d share a map or a mod. And a real project can need hundreds of commands, which becomes an unmanageable forest of blocks you can’t search, copy, or keep tidy.

What you really want is to write your commands as files: organized in folders, editable in a text editor, searchable, shareable as a single download, and not physically jammed into the world. Minecraft has exactly that system, and it’s where this book is headed next. It’s called a data pack, and the moment you meet it in Part III, every command you’ve learned to type becomes something you can save, name, and run by the dozen.

What Can Go Wrong

  • The block won’t open or won’t place. Command blocks are operator tools: you need Creative mode with cheats on. In Survival, or with cheats off, you can’t edit or break them.
  • Pressing the trigger does nothing. The block needs redstone power reaching it, and an impulse block fires once per activation (press the button again). On servers, the command_blocks_work game rule must be on (it is by default).
  • A chain stops partway. Every follower block must be set to Chain type, must be Always Active (or powered), and must point into the next block. One impulse block or one wrong-facing block in the middle breaks the rest of the line.
  • I can’t tell why a command failed. Open the block and read the Previous Output box at the bottom; it shows the result of the last run, the same success-or-red-failure idea you learned reading feedback in Chapter 1.

What You Know Now

You can hand yourself a command block with /give @s command_block, type a command into its GUI, and fire it with a button or lever, turning a command you used to retype into a machine you press. You know the three types and their colors: impulse (orange, once), repeating (purple, every tick), and chain (cyan, triggered in sequence), plus the Redstone and Condition switches that tune them. You can chain blocks so one button runs a whole routine in order, which finally grants Chapter 1’s wish to “run all of these at once.” And you’ve seen the ceiling: command blocks live buried in the world, can’t be shared, and don’t scale. Next, in Chapter 7, you’ll start climbing past that ceiling by learning what Minecraft is really doing under the hood, on your way to writing commands as files you can save and share.