O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learn to Program with Minecraft

Book Description

Learn to Program with Minecraft is a kid-friendly introduction to customizing Minecraft with Python programming.

Table of Contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. About the Author
  5. About the Technical Reviewer
  6. Brief Contents
  7. Contents in Detail
  8. Acknowledgments
  9. Introduction
    1. Why Learn to Program?
    2. Why Python?
    3. Why Minecraft?
    4. What’s in This Book?
    5. Online Resources
    6. Let the Adventure Begin!
  10. Chapter 1: Setting Up for Your Adventure
    1. Setting Up Your Windows PC
      1. Installing Minecraft
      2. Installing Python
      3. Installing Java
      4. Installing the Minecraft Python API and Spigot
      5. Running Spigot and Creating a Game
      6. Starting Over with a New World
      7. Playing Offline
      8. Switching to Survival Mode
    2. Setting Up Your Mac
      1. Installing Minecraft
      2. Installing Python
      3. Installing Java
      4. Installing the Minecraft Python API and Spigot
      5. Running Spigot and Creating a Game
      6. Starting Over with a New World
      7. Playing Offline
      8. Switching to Survival Mode
    3. Setting Up Your Raspberry Pi
    4. Getting to Know IDLE
      1. Getting to Know the Python Shell
      2. Say Hello to IDLE’s Text Editor
      3. When to Use the Python Shell and When to Use the Text Editor
      4. The Prompts Used in This Book
    5. Testing Your Minecraft Python Setup
  11. Chapter 2: Teleporting with Variables
    1. What Is a Program?
    2. Storing Data with Variables
      1. The Structure of Programming Languages
      2. Syntax Rules for Variables
      3. Changing the Values of Variables
      4. Integers
      5. Mission #1: Teleport the Player
      6. Floats
      7. Mission #2: Go Exactly Where You Want
    3. Slowing Down Teleportation Using the time Module
      1. Mission #3: Teleportation Tour
    4. Debugging
      1. Mission #4: Fix the Buggy Teleportation
    5. What You Learned
  12. Chapter 3: Building Quickly and Traveling Far with Math
    1. Expressions and Statements
    2. Operators
      1. Addition
      2. Mission #5: Stack Blocks
      3. Mission #6: Super Jump
      4. Subtraction
      5. Mission #7: Change the Blocks Under You
      6. Using Math Operators in Arguments
      7. Mission #8: Speed Building
      8. Multiplication
      9. Division
      10. Mission #9: Spectacular Spires
    3. Exponents
    4. Parentheses and Order of Operations
    5. Handy Math Tricks
      1. Shorthand Operators
      2. Playing with Random Numbers
      3. Mission #10: Super Jump Somewhere New!
    6. What You Learned
  13. Chapter 4: Chatting with Strings
    1. What Are Strings?
    2. The print() Function
      1. Mission #11: Hello, Minecraft World
    3. The input() Function
      1. Mission #12: Write Your Own Chat Message
    4. Joining Strings
      1. Converting Numbers to Strings
      2. Concatenating Integers and Floats
      3. Mission #13: Add Usernames to Chat
    5. Converting Strings to Integers with int()
      1. Mission #14: Create a Block with input
    6. Bounce Back from Errors
      1. Mission #15: Only Numbers Allowed
      2. Mission #16: Sprint Record
    7. What You Learned
  14. Chapter 5: Figuring Out What’s True and False with Booleans
    1. Boolean Basics
      1. Mission #17: Stop Smashing Blocks!
    2. Concatenating Booleans
    3. Comparators
      1. Equal To
      2. Mission #18: Am I Swimming?
      3. Not Equal To
      4. Mission #19: Am I Standing in Something Other Than Air?
      5. Greater Than and Less Than
      6. Greater Than or Equal To and Less Than or Equal To
      7. Mission #20: Am I Above the Ground?
      8. Mission #21: Am I Close to Home?
    4. Logical Operators
      1. and
      2. Mission #22: Am I Entirely Underwater?
      3. or
      4. Mission #23: Am I in a Tree?
      5. not
      6. Mission #24: Is This Block Not a Melon?
      7. Logical Operator Order
      8. Is My Number Between Two Others?
      9. Mission #25: Am I in the House?
    5. What You Learned
  15. Chapter 6: Making Mini-Games with if Statements
    1. Using if Statements
      1. Mission #26: Blast a Crater
      2. else Statements
      3. Mission #27: Prevent Smashing, or Not
      4. elif Statements
      5. Mission #28: Offer a Gift
      6. Chaining Together elif Statements
      7. Mission #29: Teleport to the Right Place
      8. Nested if Statements
      9. Mission #30: Open a Secret Passage
    2. Using if Statements to Test a Range of Values
      1. Mission #31: Restrict Teleport Locations
    3. Boolean Operators and if Statements
      1. Mission #32: Take a Shower
    4. What You Learned
  16. Chapter 7: Dance Parties and Flower Parades with while Loops
    1. A Simple while Loop
      1. Mission #33: A Random Teleportation Tour
    2. Controlling Loops with a Count Variable
      1. Mission #34: The Watery Curse
      2. Infinite while Loops
      3. Mission #35: Flower Trail
    3. Fancy Conditions
      1. Mission #36: Diving Contest
      2. Boolean Operators and while Loops
      3. Checking a Range of Values in while Loops
      4. Mission #37: Make a Dance Floor
      5. Nested if Statements and while Loops
      6. Mission #38: The Midas Touch
    4. Ending a while Loop with break
      1. Mission #39: Create a Persistent Chat with a Loop
      2. while-else Statements
      3. Mission #40: Hot and Cold
    5. What You Learned
  17. Chapter 8: Functions Give You Superpowers
    1. Defining Your Own Functions
      1. Calling a Function
      2. Functions Take Arguments
      3. Mission #41: Build a Forest
      4. Refactoring a Program
      5. Mission #42: Refactor Away
      6. Commenting with Docstrings
      7. Line Breaks in Arguments
      8. Function Return Values
      9. Mission #43: Block ID Reminder
    2. Using if Statements and while Loops in Functions
      1. if Statements
      2. Mission #44: Wool Color Helper
      3. while Loops
      4. Mission #45: Blocks, Everywhere
    3. Global and Local Variables
      1. Mission #46: A Moving Block
    4. What You Learned
  18. Chapter 9: Hitting Things with Lists and Dictionaries
    1. Using Lists
      1. Accessing a List Item
      2. Changing a List Item
      3. Mission #47: High and Low
    2. Manipulating Lists
      1. Adding an Item
      2. Inserting an Item
      3. Deleting an Item
      4. Mission #48: Progress Bar
    3. Treating Strings like Lists
    4. Tuples
      1. Setting Variables with Tuples
      2. Mission #49: Sliding
      3. Returning a Tuple
    5. Other Useful Features of Lists
      1. List Length
      2. Mission #50: Block Hits
      3. Randomly Choosing an Item
      4. Mission #51: Random Block
      5. Copying a List
      6. Items and if Statements
      7. Mission #52: Night Vision Sword
    6. Dictionaries
      1. Defining a Dictionary
      2. Accessing Items in Dictionaries
      3. Mission #53: Sightseeing Guide
      4. Changing or Adding an Item in a Dictionary
      5. Deleting Items in Dictionaries
      6. Mission #54: Block Hits Score
    7. What You Learned
  19. Chapter 10: Minecraft Magic with for Loops
    1. A Simple for Loop
      1. Mission #55: Magic Wand
      2. The range() Function
      3. Mission #56: Magic Stairs
      4. Playing Around with range()
    2. Other List Functions
      1. Mission #57: Pillars
      2. Mission #58: Pyramid
    3. Looping Over a Dictionary
      1. Mission #59: Scoreboard
    4. for-else Loops
      1. Breaking a for-else Loop
      2. Mission #60: The Diamond Prospector
    5. Nested for Loops and Multidimensional Lists
      1. Thinking in Two Dimensions
      2. Accessing Values in 2D Lists
      3. Mission #61: Pixel Art
      4. Generating 2D Lists with Loops
      5. Mission #62: A Weather-Worn Wall
      6. Thinking in Three Dimensions
      7. Outputting 3D Lists
      8. Accessing Values in 3D Lists
      9. Mission #63: Duplicate a Building
    6. What You Learned
  20. Chapter 11: Saving and Loading Buildings with Files and Modules
    1. Using Files
      1. Opening a File
      2. Writing to and Saving a File
      3. Reading a File
      4. Reading a Line of a File
      5. Mission #64: To-Do List
      6. Part 1: Writing the To-Do List
      7. Part 2: Displaying the To-Do List
    2. Using Modules
      1. The pickle Module
      2. Importing pickle
      3. Importing One Function with the from Clause
      4. Importing All Functions with *
      5. Giving a Module a Nickname
      6. Mission #65: Save a Building
      7. Part 1: Saving the Building
      8. Part 2: Loading the Building
    3. Storing Lots of Data with the shelve Module
      1. Opening a File with shelve
      2. Adding, Modifying, and Accessing Items with shelve
      3. Mission #66: Save a Collection of Structures
      4. Part 1: Saving a Structure to a Collection
      5. Part 2: Loading a Structure from a Collection
    4. Installing New Modules with pip
      1. Using pip on Windows
      2. Using pip on a Mac or Raspberry Pi
    5. Using a Module from pip: Flask
      1. Mission #67: Position Website
    6. What You Learned
  21. Chapter 12: Getting Classy with Object-Oriented Programming
    1. Object-Oriented Basics
    2. Creating a Class
      1. Creating an Object
      2. Accessing Attributes
      3. Mission #68: Location Objects
    3. Understanding Methods
      1. Mission #69: Ghost House
    4. Returning Values with Methods
      1. Mission #70: Ghost Castle
    5. Creating Multiple Objects
      1. Mission #71: Ghost Town
    6. Class Attributes
    7. Understanding Inheritance
      1. Inheriting a Class
      2. Adding New Methods to Subclasses
      3. Mission #72: Ghost Hotel
    8. Overriding Methods and Attributes
      1. Mission #73: Ghost Tree
    9. What You Learned
  22. Afterword
  23. Block ID Cheat Sheet
  24. Index
  25. More Smart Books for Curious Kids!
  26. Resources
  27. Requirements