← All Courses

Minecraft Coding: Command Your World

Free   6 lessons

Lesson 6: Command Blocks — Automate Everything

Command Blocks — Automate Everything

Typing commands manually is useful, but command blocks let commands run automatically — over and over, triggered by events, or chained together. This is where Minecraft commands become a real programming environment.

Getting a Command Block

Command blocks can't be obtained from creative inventory normally. You have to give them to yourself:

/give @s minecraft:command_block

Place it like any other block. Right-click to open it.

The Three Types

Impulse (orange) — runs once when powered by redstone. Default type.

Repeat (purple) — runs every game tick (20 times per second) as long as powered. Used for continuous checks.

Chain (green) — runs after the block behind it runs. Used to create sequences.

Conditional Mode

Each block has a Conditional toggle. In conditional mode, a chain block only runs if the previous block succeeded. This is the if statement of command block programming.

Always Active vs Needs Redstone

Set a repeat block to "Always Active" and it runs continuously without needing redstone power. Perfect for ongoing game mechanics.

Building a Healing Station

Place a repeat command block set to Always Active. Type inside it:

/execute if entity @p[distance=..3] run effect give @p minecraft:regeneration 2 1

Now any player who stands within 3 blocks of this command block gets constant regeneration. You've built a healing station without any mods.

Building a Kill Zone

Repeat block, Always Active:

/execute if entity @e[type=minecraft:zombie,distance=..20] run kill @e[type=minecraft:zombie,distance=..20]

Any zombie that comes within 20 blocks of this block is instantly killed. Zombie-proof zone.

Chaining Commands — The Sequence

Place these in a row: Impulse → Chain → Chain → Chain

Point each one toward the next. In the impulse block:

/tp @p 0 100 0

First chain:

/effect give @p minecraft:levitation 3 0

Second chain:

/playsound minecraft:entity.firework_rocket.launch master @p

Third chain:

/title @p title {"text":"Welcome!","color":"gold"}

When you power the first block, all four run in sequence — teleport the player, make them float, play a sound, and show a title. You just built a mini cutscene.

Building a Simple Mini-Game: Hot Floor

Place several repeat command blocks around an arena. In each one:

/execute if entity @a[distance=..1] if block ~ ~-1 ~ minecraft:red_concrete run effect give @a[distance=..1] minecraft:wither 3 0

Any player standing on red concrete takes wither damage. Paint some tiles red at random intervals using another command block:

/fill ~-5 ~-1 ~-5 ~5 ~-1 ~5 white_concrete replace red_concrete
/fill ~(random tile) ~-1 ~(random tile) ... red_concrete

You've started building an actual mini-game using only command blocks — no mods, no plugins.

Scoreboard — Tracking Data

The scoreboard system lets you store numbers for each player. This is how you create real game variables:

/scoreboard objectives add kills playerKillCount
/scoreboard objectives setdisplay sidebar kills

Now player kill counts are tracked and displayed on the sidebar. Real game logic.

Where This Goes Next

Command blocks are the gateway to:

  • Adventure maps — full story-driven Minecraft experiences
  • Mini-games — hunger games, bed wars, parkour with checkpoints
  • Datapacks — JSON-based function files that run commands automatically
  • Minecraft Bedrock Add-ons — JavaScript-based behavior packs
  • Real programming — the logic you've learned (conditions, loops, sequences, variables) is the same logic in Python, JavaScript, and every other language

Final Challenge: Build Something

Using what you've learned, build one of these:

  1. A dungeon — use /fill to build it, /summon to populate it with enemies, command blocks to trigger traps
  2. A lobby — teleport pads that /tp players to different areas, with title screen effects
  3. A survival challenge — a room that spawns increasingly difficult waves of mobs using repeat command blocks and a scoreboard timer

Post your creation. You're a Minecraft developer now.