Hardware Reference
In-Depth Information
Start up Minecraft, IDLE, and if you are working on a PC or a Mac, start up the Bukkit
server too. You should have had a bit of practice with starting everything up by now,
but refer back to Adventure 1 if you need any reminders.
1.
Start by opening IDLE and creating a new file. Save the file as
LinesCirclesAndSpheres.py
in the
MyAdventures
folder.
2.
Next, import the
minecraft
,
block
,
minecraftstuff
and
time
modules by
typing the following lines:
import mcpi.minecraft as minecraft
import mcpi.block as block
import mcpi.minecraftstuff as minecraftstuff
import time
3.
Create the connection to Minecraft:
mc = minecraft.Minecraft.create()
4.
Use the
minecraftstuff
module to create a
MinecraftDrawing
object by
typing:
mcdrawing = minecraftstuff.MinecraftDrawing(mc)
DIGGING INTO THE CODE
MinecraftDrawing
is a class in the
minecraftstuff
module. Classes are
part of a special method of programming called “Object Oriented” which is a
way of grouping similar functions and data together—in this case, Minecraft
drawing functions and data—so they are easier to understand and use. When
you use a class and give it a name (e.g.
mcdrawing
) you create an object. This
is known as instantiation. An object is similar to a variable but rather than just
holding values (or data), it also has functions!
Object Oriented Programming (OOP) is a complex subject and volumes of
topics have been written on what it is and how to use it successfully, there is,
however, a useful introduction to using classes in Python at
en.wikibooks.org/
You can look at the code in
minecraftstuff
by opening the
minecrafts-
tuff.py
file in the
MyAdventures/mcpi
folder using IDLE.