Book Reviews - Learn to Program with Minecraft

Book Reviews - Learn to Program with Minecraft
You've bested creepers, traveled deep into caves, and maybe even gone to The End and back-but have you ever transformed a sword into a magic wand? Built a palace in the blink of an eye? Designed your own color-changing disco dance floor?
In Learn to Program with Minecraft, you'll do all this and more with the power of Python, a free language used by millions of professional and first-time programmers!
Begin with some short, simple Python lessons and then use your new skills to modify Minecraft to produce instant and totally awesome results. Learn how to customize Minecraft to make mini-games, duplicate entire buildings, and turn boring blocks into gold.
You'll also write programs that:
  • Take you on an automated teleportation tour around your Minecraft world
  • Build massive monuments, pyramids, forests, and more in a snap!
  • Make secret passageways that open when you activate a hidden switch
  • Create a spooky ghost town that vanishes and reappears elsewhere
  • Show exactly where to dig for rare blocks
  • Cast a spell so that a cascade of flowers (or dynamite if you're daring!) follows your every move
  • Make mischief with dastardly lava traps and watery curses that cause huge floods
Whether you're a Minecraft megafan or a newbie, you'll see Minecraft in a whole new light while learning the basics of programming. Sure, you could spend all day mining for precious resources or building your mansion by hand, but with the power of Python, those days are over!
Requires: Windows 7 or later; OS X 10.10 or later; or a Raspberry Pi.
Uses Python 3
1 Setting Up for Your Adventure 1
Setting Up Your Windows PC . 2
Installing Minecraft . 2 Installing Python . 3 Installing Java 4
Installing the Minecraft Python API and Spigot . 6
Running Spigot and Creating a Game 7
Starting Over with a New World . 8
Playing Offline . 9
Switching to Survival Mode . 10
Setting Up Your Mac . 11
Installing Minecraft . 12
Installing Python . 13
Installing Java 14
Installing the Minecraft Python API and Spigot . 15
Running Spigot and Creating a Game 16
Starting Over with a New World . 17
Playing Offline . 18
Switching to Survival Mode . 18
Setting Up Your Raspberry Pi 18
Getting to Know IDLE . 20
Getting to Know the Python Shell . 20
Say Hello to IDLE’s Text Editor . 21
When to Use the Python Shell and When to Use the Text Editor . 23
The Prompts Used in This Book . 23
Testing Your Minecraft Python Setup 24
2 Teleporting with Variables 27
What Is a Program? 27
Storing Data with Variables 28
The Structure of Programming Languages 29
Syntax Rules for Variables . 30
Changing the Values of Variables 30
Integers . 31
Mission #1: Teleport the Player . 31
Floats . 37
Mission #2: Go Exactly Where You Want 38
Slowing Down Teleportation Using the time Module 39
Mission #3: Teleportation Tour . 40
Debugging . 42
Mission #4: Fix the Buggy Teleportation 43
What You Learned 45
3 Building Quickly and Traveling Far with Math 47
Expressions and Statements 47
Operators 48
Addition
Mission #5: Stack Blocks 49
Mission #6: Super Jump . 51
Subtraction 52
Mission #7: Change the Blocks Under You 52
Using Math Operators in Arguments . 54
Mission #8: Speed Building 55
Multiplication . 58
Division 58
Mission #9: Spectacular Spires . 58
Exponents 60
Parentheses and Order of Operations . 61
Handy Math Tricks 62
Shorthand Operators 62
Playing with Random Numbers 62
Mission #10: Super Jump Somewhere New! . 63
What You Learned 64
4 Chatting with Strings 65
What Are Strings? . 66
The print() Function 66
Mission #11: Hello, Minecraft World 67
The input() Function . 68
Mission #12: Write Your Own Chat Message 69
Joining Strings 71
Converting Numbers to Strings 71
Concatenating Integers and Floats 72
Mission #13: Add Usernames to Chat . 72
Converting Strings to Integers with int() 74
Mission #14: Create a Block with input . 74
Bounce Back from Errors 76
Mission #15: Only Numbers Allowed . 77
Mission #16: Sprint Record 78
What You Learned 80
5 Figuring Out What’s True and False
with Booleans 81
Boolean Basics . 82
Mission #17: Stop Smashing Blocks! . 82
Concatenating Booleans 83
Comparators 83
Equal To . 84
Mission #18: Am I Swimming? . 85
Not Equal To . 86
Mission #19: Am I Standing in Something Other Than Air? 87
Greater Than and Less Than 88
Greater Than or Equal To and Less Than or Equal To 89
Mission #20: Am I Above the Ground? . 90
Mission #21: Am I Close to Home? . 91
Logical Operators . 92
and . 93
Mission #22: Am I Entirely Underwater? . 93
or . . . 95
Mission #23: Am I in a Tree? 95
not . . . 96
Mission #24: Is This Block Not a Melon? . 97
Logical Operator Order 98
Is My Number Between Two Others? 99
Mission #25: Am I in the House? 100
What You Learned 101
6 Making Mini-Games with if Statements 103
Using if Statements 104
Mission #26: Blast a Crater 105
else Statements 107
Mission #27: Prevent Smashing, or Not 108
elif Statements . 109
Mission #28: Offer a Gift . 110
Chaining Together elif Statements 112
Mission #29: Teleport to the Right Place 113
Nested if Statements . 115
Mission #30: Open a Secret Passage 115
Using if Statements to Test a Range of Values . 117
Mission #31: Restrict Teleport Locations 118
Boolean Operators and if Statements . 119
Mission #32: Take a Shower 120
What You Learned 122
7
Dance Parties and Flower Parades
with while Loops 123
A Simple while Loop 123
Mission #33: A Random Teleportation Tour 125
Controlling Loops with a Count Variable 127
Mission #34: The Watery Curse 128
Infinite while Loops . 130
Mission #35: Flower Trail . 130
Fancy Conditions . 131
Mission #36: Diving Contest . 132
Boolean Operators and while Loops . 134
Checking a Range of Values in while Loops 135
Mission #37: Make a Dance Floor 135
Nested if Statements and while Loops . 137
Mission #38: The Midas Touch 138
Ending a while Loop with break 139
Mission #39: Create a Persistent Chat with a Loop 139
while-else Statements 141
Mission #40: Hot and Cold . 141
What You Learned 144
8
Functions Give You Superpowers 145
Defining Your Own Functions 146
Calling a Function 146
Functions Take Arguments . 147
Mission #41: Build a Forest 148
Refactoring a Program 150
Mission #42: Refactor Away 151
Commenting with Docstrings . 152
Line Breaks in Arguments 153
Function Return Values 153
Mission #43: Block ID Reminder . 155
Using if Statements and while Loops in Functions 157
if Statements 157
Mission #44: Wool Color Helper . 158
while Loops . 159
Mission #45: Blocks, Everywhere 160
Global and Local Variables 162
Mission #46: A Moving Block . 163
What You Learned 165
9
Hitting Things with Lists and Dictionaries 167
Using Lists 168
Accessing a List Item . 168
Changing a List Item . 169
Mission #47: High and Low 169
Manipulating Lists . 171
Adding an Item 171
Inserting an Item 172
Deleting an Item . 172
Mission #48: Progress Bar 173
Treating Strings like Lists 175
Tuples 175
Setting Variables with Tuples . 176
Mission #49: Sliding 177
Returning a Tuple . 179
Other Useful Features of Lists 179
List Length . 179
Mission #50: Block Hits 180
Randomly Choosing an Item 182
Mission #51: Random Block . 183
Copying a List . 183
Items and if Statements . 185
Mission #52: Night Vision Sword . 186
Dictionaries 188
Defining a Dictionary 188
Accessing Items in Dictionaries 189
Mission #53: Sightseeing Guide . 190
Changing or Adding an Item in a Dictionary . 191
Deleting Items in Dictionaries . 192
Mission #54: Block Hits Score . 192
What You Learned 194
10 Minecraft Magic with for Loops 195
A Simple for Loop . 195
Mission #55: Magic Wand . 196
The range() Function . 198
Mission #56: Magic Stairs 199
Playing Around with range() 200
Other List Functions . 201
Mission #57: Pillars . 202
Mission #58: Pyramid 203
Looping Over a Dictionary . 205
Mission #59: Scoreboard . 205
for-else Loops 206
Breaking a for-else Loop 207
Mission #60: The Diamond Prospector 207
Nested for Loops and Multidimensional Lists . 208
Thinking in Two Dimensions 209
Accessing Values in 2D Lists 213
Mission #61: Pixel Art 214
Generating 2D Lists with Loops 216
Mission #62: A Weather-Worn Wall . 217
Thinking in Three Dimensions . 218
Outputting 3D Lists . 219
Accessing Values in 3D Lists 223
Mission #63: Duplicate a Building . 225
What You Learned 230
11 Saving and Loading Buildings with
Files and Modules 231
Using Files . 232
Opening a File 232
Writing to and Saving a File . 233
Reading a File . 234
Reading a Line of a File 234
Mission #64: To-Do List 235
Part 1: Writing the To-Do List . 235
Part 2: Displaying the To-Do List . 237
Using Modules 238
The pickle Module 238
Importing pickle . 238
Importing One Function with the from Clause . 240
Importing All Functions with * 241
Giving a Module a Nickname . 241
Mission #65: Save a Building . 242
Part 1: Saving the Building 242
Part 2: Loading the Building 245
Storing Lots of Data with the shelve Module 247
Opening a File with shelve 247
Adding, Modifying, and Accessing Items with shelve 247
Mission #66: Save a Collection of Structures . 248
Part 1: Saving a Structure to a Collection 248
Part 2: Loading a Structure from a Collection . 249
Installing New Modules with pip . 252
Using pip on Windows . 252
Using pip on a Mac or Raspberry Pi . 253
Using a Module from pip: Flask 253
Mission #67: Position Website 255
What You Learned 256
12 Getting Classy with Object-Oriented
Programming 257
Object-Oriented Basics 258
Creating a Class . 258
Creating an Object 259
Accessing Attributes . 259
Mission #68: Location Objects 260
Understanding Methods . 261
Mission #69: Ghost House 263
Returning Values with Methods . 266
Mission #70: Ghost Castle 266
Creating Multiple Objects 269
Mission #71: Ghost Town . 269
Class Attributes . 271
Understanding Inheritance 273
Inheriting a Class . 274
Adding New Methods to Subclasses 275
Mission #72: Ghost Hotel . 275
Overriding Methods and Attributes 278
Mission #73: Ghost Tree 280
What You Learned 282

1 comment: