Learn to Code
Inside Minecraft

A hands-on guide to programming with Scratch, Python, and Lua — using the game you already love.

Published by Dennis Publishing · Ages 9+

How to Code in Minecraft book cover

What You'll Learn

Four real programming languages. One blocky world full of possibilities.

Scratch

Start with visual block-based coding. Drag, drop, and see your creations come to life inside Minecraft.

Python

Graduate to real text-based code. Use the mcpi module to build, create patterns, and automate the Minecraft world.

Lua

Program ComputerCraft turtles — robots that mine, build, and farm for you. Modding meets coding.

Hardware

Go beyond the screen. Connect Arduino and Raspberry Pi to bring your Minecraft projects into the physical world.

Inside the Book

Four chapters that take you from complete beginner to confident coder.

1

Getting Started

Set up your development environment, install a local server, and get ready to code. Covers Python, Scratch, and McMyAdmin setup with clear step-by-step instructions.

2

Scratch and Minecraft

Learn programming fundamentals with Scratch's visual blocks, then connect Scratch to Minecraft via Python. Build structures, create patterns, and see your code reshape the world.

Exercises: Hello Minecraft World, Home Automation, The Order of Things

3

Python and Minecraft

Take the leap into real code. Use Python and the mcpi module to talk directly to Minecraft — get your player's position, create and destroy blocks, detect block types, and build a mini game from scratch.

Exercises: Hello Minecraft World, Minecraft Whispers, Force Field, Killer Drop

4

Lua and ComputerCraft

Install mods and program turtles — in-game robots that follow your Lua scripts. Build a password-protected door lock, launch Rednet fireworks, create touchscreens, and automate everything.

Exercises: Password Door Lock, Rednet Fireworks, Touchscreen, A New Hope

Where Next?

Compare what you've learned across languages, explore LearnToMod, Raspberry Pi, and discover how your new coding skills apply far beyond Minecraft.

Why Learn to Code with Minecraft?

Because the best way to learn is inside something you already love.

Motivation built in

You already spend hours in Minecraft. Now every line of code has an instant, visible result in a world you care about.

Real languages, real skills

Scratch, Python, and Lua aren't toy languages. They're used by professional developers every day.

Problem-solving first

Programming is thinking. This book teaches you to break problems down, think logically, and debug — skills that outlast any language.

Try the Code

Real code from real chapters. This is what you'll be writing.

Python Chapter 3: Hello Minecraft World
import mcpi.minecraft as minecraft
mc = minecraft.Minecraft.create()

mc.postToChat("Hello Minecraft World")

Your first Python program — three lines to talk to Minecraft. Once connected, you can build, destroy, and reshape the world with code.

Python Chapter 3: Killer Drop
import mcpi.minecraft as minecraft
import time

mc = minecraft.Minecraft.create()

while True:
    pos = mc.player.getTilePos()
    b = mc.getBlock(pos.x, pos.y - 1, pos.z)
    if b == 0:  # standing on air!
        mc.postToChat("Falling!!!")
    time.sleep(0.3)

A mini game that detects when the ground disappears beneath you. Build a bridge, then remove blocks and try not to fall.

Lua Chapter 4: Password Door Lock
-- Password Door Lock
local password = "secret"

while true do
  write("Enter password: ")
  local input = read("*")
  if input == password then
    rs.setOutput("back", true)
    sleep(3)
    rs.setOutput("back", false)
  end
end

Program a ComputerCraft computer to control a redstone door. Get the password right and the door opens for 3 seconds.

Errata & Updates

Known corrections and setup tips for newer versions of Minecraft.

Fix

Page 16: The URL for the Minecraft Pi download should be https://minecraft.net/en-us/edition/pi/

Fix

Page 21: In the True or False section, the answers for True and False are reversed.

Fix

Page 51: mc.player.getpos() should be mc.player.getPos() — no extra period before the brackets.

Tip

Newer Minecraft versions: The book was written for Minecraft 1.8.x. If using a newer launcher, create a profile for version 1.8.x for best compatibility with the CraftBukkit server and mcpi module.

About the Author

Jim Christian has been playing and teaching Minecraft ever since a group of students pestered him into starting an after-school club. That experience — watching kids light up when their code actually built something in a world they cared about — led to How to Code in Minecraft, written while running coding workshops at Fire Tech Camp.

With over 30 years in software development and education, Jim is also the author of How to Think Like a Coder: Without Even Trying! (Batsford, 2017) and writes about AI implementation at Signal Over Noise.

You might spot him in-game as woogadoo or Sn0wCrash.

Get the Book

Available in paperback wherever books are sold.