Learn to Code
Inside Minecraft
A hands-on guide to programming with Scratch, Python, and Lua — using the game you already love.
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.
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.
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
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
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.
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.
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.
-- 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.
Page 16: The URL for the Minecraft Pi download should be https://minecraft.net/en-us/edition/pi/
Page 21: In the True or False section, the answers for True and False are reversed.
Page 51: mc.player.getpos() should be mc.player.getPos() — no extra period before the brackets.
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.