How to get started with Minecraft on Raspberry Pi

Download and install Minecraft on the Raspberry Pi

Minecraft has steadily taken over the world since its release in 2009, and has become a runaway success across many different platforms, including the PC, Xbox 360 and PS3.

If you’ve never played Minecraft before, the basic premise is to mine various materials with which you can build objects in the game world. Mining is quite easy but it’s essential to survive, and you can mine wood, stone, coal and metals. From these mined materials you can make houses, bridges, weapons, tools and even furniture for your home.

There is another side to Minecraft, though, and this is what we are focusing on in this tutorial. Minecraft also has a creative mode, where you are free to build whatever you want, with no monsters or night-time to threaten you.

This is the version that has been made available for the Raspberry Pi. In this version of the game, you’re free to build anything you want, just like with a large box of Lego. Of course, it could become tedious building everything brick by brick, but fear not, because help is at hand, and it’s in the form of the Python programming language.

Download and install Minecraft on the Raspberry Pi

How to get started with Minecraft on Raspberry Pi

1. Download the archive

To get your copy of Minecraft, download the archive to your Raspberry Pi. Make sure you remember where you saved it, because we will need to use it in the next step.

How to get started with Minecraft on Raspberry Pi

2. Open the terminal

Extract the Minecraft archive contents to your Raspberry Pi via the terminal. On the desktop, double-click on the LXTerminal icon, then navigate to the place where you downloaded the archive.

To do this, use the cd command to change the directory – for example, cd /home/pi/.

How to get started with Minecraft on Raspberry Pi

3. Extract the archive

Use the terminal to extract the archive:

tar -zxvf minecraft-pi-0.1.1.tar.gz

Press [Enter] and you’ll see lots of text whizz along the screen. This is the command’s way of telling us that it is working. Once complete, the command returns you to a prompt.

Create your own Minecraft server

Here’s how to share your world with friends around the globe by creating your own Minecraft . This method relies on either a static IP address for your home network, or the use of a dynamic DNS service.

If you wish to share the world with your friends on the same network, this is not necessary and you can just give your friends the IP address of your Raspberry Pi, which you can find out by running ifconfig in a terminal.

If you are connected via ethernet, look for eth0; if connected wirelessly, look for wlan0. Once you have found either of these, the IP address should be visible, and this is what your friends need to join your server.

How to get started with Minecraft on Raspberry Pi

Overclock your Raspberry Pi to Medium. Change the memory split to 16MB. Reboot your Raspberry Pi. Download and install Java. Download and install Minecraft Server. Run the Minecraft Server using a bash script called start.sh. In a terminal, type nano start.sh. In nano, type:

/opt/jdk1.8.0/bin/java -Xms256M -Xmx496M

-jar /home/pi/spigot.jar nogui

Build better Minecraft worlds

Here’s how to create your own custom Minecraft world on a Raspberry Pi.

How to get started with Minecraft on Raspberry Pi

1. Run Minecraft

During the extraction of the archive, a new folder was created, and it’s called mcpi. We need to change our directory to mcpi so use the cd command again. Once done, use a command called ls to list the contents of the directory. Look for minecraft-pi – this is the Minecraft application.

How to get started with Minecraft on Raspberry Pi

2. Play around

To launch Minecraft, enter the following in a terminal: ./minecraft-pi. Have a play with Minecraft, create a new world and when it’s ready, use the [W], [A], [S] and [D] keys to move around.

The mouse changes where you look, and the left mouse button destroys blocks, whereas the right one places a block.

How to get started with Minecraft on Raspberry Pi

3. Get the minecraft-api.py file

In Minecraft, to create objects, we must build them brick by brick. But if we use Python, we can make lots of things quickly.

We need to use the minecraft-api.py file and an application called IDLE. A link to IDLE can be found via the icon on the desktop.

How to get started with Minecraft on Raspberry Pi

4. Copy files

Make a directory called minecraft-api in your home directory and copy the contents of /home/pi/mcpi/api/python/mcpi (including any folders) to minecraft-api. The easiest way to do this is to use LXTerminal and type

cp -r /mcpi/api/python/mcpi /minecraft-api/minecraft

cp means to copy the files and the -r switch instructs the copy to include any sub directories. Also copy the downloaded tutorial file into this directory, ready for the next step.

How to get started with Minecraft on Raspberry Pi

5. Add a welcome message

Open the minecraft-api.py file in the IDLE editor and take a look at the code. First, let’s change the code that says mc.postToChat (“Hello World”) to say “Welcome to the game”.

Save your work, start a new Minecraft session using any world, then in IDLE click on ‘run’ which is in the Run menu. You should see your text on the screen.

How to get started with Minecraft on Raspberry Pi

6. Drop in your player

Our player has a position, controlled via XYZ co-ordinates. We can check where our player is by using mc.player.getPos() and saving the output to a variable called playerPos, ready for use later.

Another idea is to use mc.player.SetTilePos(x,y,z) to drop your player into the game. We changed y to 50, and the player drops into the world.

Advanced world building in Minecraft

Here’s some advanced things you can do with the Raspberry Pi version of Minecraft to turn the worlds you build into games in their own right.

How to get started with Minecraft on Raspberry Pi

1. Build the platforms

Now we build our platforms. To make it easier for ourselves, we used a for loop, which loops round a set number of times.

for more in range(0,21):

In this case, it loops round 20 times and repeats this code:

mc.setBlock(playerPos.x + more, playerPos.y + more, playerPos.z +

more, block.WOOD_PLANKS)

This code uses the player’s position as a starting point, then builds blocks of wood, one block ahead, above and to the side each loop, creating a sweeping staircase.

How to get started with Minecraft on Raspberry Pi

2. Choose your material

After the blocks of wood have been built, we want to use a different block. We chose diamond, but there are lots to choose from. Open a terminal and go to /home/pi/minecraft-api/minecraft – you will find block.py.

Open this in a text editor and you see all the blocks you can use. Why not change block.DIAMOND_BLOCK for deadly LAVA?

How to get started with Minecraft on Raspberry Pi

3. Make a clock

We wanted to make this a challenge, so we decided to introduce a countdown clock. To set the clock, we created a variable called clock and gave it the value of 30; this is an integer value.

We then created a while loop, that has the condition of

while clock > 0:

This compares the value of clock and if it is greater than 0, it runs some code.

How to get started with Minecraft on Raspberry Pi

4. Start the countdown

The code that is run is only three lines long, but it repeats until clock is equal to 0:

mc.posttoChat(clock)

time.sleep(1)

clock = clock – 1

Firstly, it posts the contents of the variable clock on the screen, then waits for one second. If we didn’t do this, the countdown would be really fast.

Lastly, we change the value of our variable clock by instructing it to take the current value of the variable and then subtract 1 from it.

Related