Martin O'Hanlon (Birmingham, UK) describes himself as a professional geek and amateur snowboarder. Martin blogs about technology, Minecraft and Raspberry Pi at stuffaboutco.de.
David Whale (Essex, UK) is a professional software engineer. He regularly volunteers for The Institution of Engineering and Technology, which provides support at many schools, public workshops and tech camps.
THIS BOOK IS going to help you learn how to write programs or mods that interact with your Minecraft world, allowing you to do some very exciting things. You use a programming language called Python to do it. This way of controlling the Minecraft world from a Python program was first created for Minecraft: Pi Edition on the Raspberry Pi. If you don't have a Raspberry Pi but have Minecraft for Windows or Apple Mac instead, that's okay; you just need to do some extra work on the setup before you get started, which this adventure shows you how to do.
Python is the programming language used in this book.
This book is full of adventures that teach you how to write programs for the Minecraft game. It's packed with all sorts of things you can do with Minecraft to entertain your friends and make the game even more fun to play. You will discover some pretty flashy ways to move your player around, and before long you'll be finding it easy to build whole cities and Minecraft creations that have never been seen before.
The Python programming language comes with a code editor called IDLE, which you will use to create, edit and run the programs you create in these adventures.
The Python programming language is used throughout the world in business and education. It is extremely powerful but also easy to learn. You can find out more about Python at
When computer programmers learn a new programming language or a new way of doing something, they always start by writing a "hello world" program. This is a really simple program that displays "hello world" on the screen, to make sure everything is installed and working properly.
In this first adventure, you set up your computer to allow you to write a program that displays the text "Hello Minecraft World" on the Minecraft chat (see Figure 1-1).
FIGURE 1-1 Hello Minecraft World
To do the Minecraft programming in this book, you need one of these three types of computer: a PC running Microsoft Windows; an Apple Mac running macOS X; or a Raspberry Pi running Raspbian with Pixel. The way you set up your computer depends on which sort of computer you have but, once you have set it up, you program Minecraft in exactly the same way on all of them. To make it easier for you to set up your computer, you can download a starter kit from
https://adventuresinminecraft.github.io. The starter kits have been tested to make sure all the adventures in this book work properly.
You'll see that your starter kit contains a
README file, which you should have a look at. It describes what the kit contains and how it was created; you could use this information to set up your own computer from scratch, although this is not recommended. You'll get a lot more out of it by following the instructions in this book.
Make sure you follow the instructions for your type of computer, either "Setting Up Your Raspberry Pi for Programming Minecraft" or "Setting Up Your PC or Apple Mac for Programming Minecraft".
It's essential that you to set up your computer correctly; otherwise you could get yourself into quite a muddle. So please make sure that you follow the instructions very carefully!
Setting Up Your Raspberry Pi to Program Minecraft
If you are using a Raspberry Pi, Minecraft is installed already; you just need to download the Raspberry Pi starter kit. Everything you need to complete Adventures in Minecraft is in a folder called
MyAdventures. You also will save your Minecraft programs in this folder.
To see a video of how to set up your Raspberry Pi, visit the companion website at
The Raspberry Pi's graphical user interface (GUI), known as Pixel, is used throughout Adventures in Minecraft. The GUI is installed on Raspbian, but depending on how you have set up your Raspberry Pi, it may not load the GUI when it boots up. You may instead start with a login and command prompt.
If your Raspberry Pi is set up to start at a command prompt, you need to log in, type
startx and then press Enter to load the GUI when the command prompt appears.
Start Adventures in Minecraft with a new installation of Raspbian so you can be sure that your Raspberry Pi is set up correctly. Visit
www.raspberrypi.org/help/ for information on setting up your Raspberry Pi and installing Raspbian.
Downloading the Starter Kit
Once your Raspberry Pi has booted up and the GUI has started, you can download the starter kit for Raspberry Pi by following these steps:
- Open a terminal, click Menu (the Raspberry Pi icon in the top left)???Accessories???Terminal.
- Change the directory to the Desktop by typing the following command (see Figure 1-2) and pressing Enter:
- Download the starter kit entering the following command and pressing Enter:
FIGURE 1-2 Download the Raspberry Pi starter kit.
https://adventuresinminecraft.github.io as there may be future updates and help available.
Starting Minecraft on Your Raspberry Pi
After you have downloaded the starter kit, you can run the game and have a go before moving on to creating your first program.
In future adventures, the instructions tell you to start Minecraft. If you ever need a reminder of how to start Minecraft on the Raspberry Pi, just refer to this section.
To start Minecraft, follow these steps:
- Select Menu???Games???Minecraft Pi.
- Start a new world by selecting Start Game???Create New.
- That's it! Now you can start playing Minecraft.
FIGURE 1-3 Start Minecraft and create a new world.
The main menu has two options: Start Game to build a new or enter an existing Minecraft world and Join Game to join another player's world. (See Figure 1-3.)
Once your Raspberry Pi is set up and you have Minecraft running, you can skip the next section (unless you want to set up Minecraft on a PC or Mac as well as on your Raspberry Pi) and go straight to the "Creating a Program" section later in this adventure.
Setting Up Your PC or Apple Mac to Program Minecraft
Whether you are using a Windows PC or a Mac, you need to make sure Minecraft is installed and working on your computer. If you don't have a copy of Minecraft and a user ID to play it, visit
www.minecraft.net to purchase the game. If you encounter any problems installing, running or playing Minecraft, help is on hand; just visit
To program the full version of Minecraft on the PC and Apple Mac, you need to use a Minecraft server and the RaspberryJuice plugin, which is included in the Starter Kit you download later in this section
RaspberryJuice is a Minecraft server plugin that allows you to write programs to change Minecraft in the same way as you can on the Raspberry Pi. A plugin is a program that runs inside the Minecraft server and lets you modify (mod) Minecraft.
You need to download the Python programming language and install it on your computer. Throughout Adventures in Minecraft you use Python version 3. The programs within Adventures in Minecraft have all been tested to work with Python version 3.6.1. Although it is not essential that you use this version, it is recommended and you must use Python 3.something.
If you want to find out more about Python, visit
www.python.org. You can download Python from
www.python.org/downloads, and the Python Wiki,
wiki.python.org, contains lots of information, tutorials and links to Python community websites.
Setting up your Windows PC or Apple Mac to create your first Minecraft program requires three steps:
- Download and extract the PC or Apple Mac starter kit, which contains a preconfigured Minecraft server with the RaspberryJuice plugin and a folder called
MyAdventures where you will save your Minecraft programs.
- Download and install the Python programming language.
- Configure Minecraft and connect it to the server.
To see a video of how to set up your Windows PC or Apple Mac, visit the companion website at...