Skip navigation

STEM Academy

3 Posts authored by: Rushy element14 Team


We can use the programming language Python to interact with the Minecraft world in a few short lines of code.

First, we have to do a bit of setting up. To keep our code separate to the original code in the MCPI folder, we will make a new directory to keep all of our code in. In LXTerminal, type mkdir python This will make a directory called python. To use the MCPI API we will have to copy that folder over to our new directory. Make sure that you are in your new directory (cd python) and then type the following command: cp -r ~mcpi/api/python/* . Include the full-stop one space after the *!

Finally, we are ready to start coding. By default, the API only uses Python 2. x but you can change this to allow Python3 use as well by following this link, however, I will not be going in to that today, for now, we will stick with Python 2. I will also be using the command line text editor nano but you can use other text editors if you wish.

Our first task is to make the file that we will run. Make sure that you are in your new directory, then type cd mcpi followed by sudo nano This should open up an empty file in nano. The first two lines of code are import minecraft and then import block underneath it. Next, we have to connect to our Minecraft world which we do by typing mc = minecraft.Minecraft.create() This first example will simply place a block at a set of co-ordinates, so first, we will define three variables, one under the other, called x, y and z. The code could look a bit like this:

x = 5
y = 0
z = 5

Now that we have our co-ordinates, we just need to place the block. Our last line of text will be mc.setBlock(x, y, z, block.STONE) Note, this is case sensitive so make sure that everything is capitalised correctly if you get an error message. The final file should look like this:

mport minecraft

import block

mc = minecraft.Minecraft.create()

x = 5

y = 0

z = 5

mc.setBlock(x, y, z, block.STONE)

Now we can just save the file (press ctrl x, then press y to save changes and then enter) and get Minecraft running. These programs will not work unless Minecraft is running and a world is loaded. Open up another LXTerminal window, type cd mcpi and then ./minecraft-pi to get Minecraft going and then load into a world. Now, press the tab key to release the mouse from Minecraft, go back to our other LXTerminal window and type python block_placer . This should run the file and at the co-ordinate 5, 0, 5 there should now be a block of stone.

That’s it for the basic python stuff. In the next tutorial, we will move on to some more complicated code and look at how to build structures and some of the other useful commands we can use.

Written By Mathew Monk MinecraftMastery | @minecraftmasterybook

minecraft-banner-3_3510581_3522898.jpgNow that you have installed Minecraft, it is probably important to learn how to play it. If you are looking for how to install Minecraft: Pi Edition, please follow the previous guide. For those of you who have played Minecraft on a Mac or PC before then you can skip this section as the controls and principles of this version are similar enough for you to pick it up. If this is your first time playing Minecraft on a computer, keep reading!


When you start up Minecraft, you will be greeted with an option to either “Start Game” or “Join Game”. For now, we will select “Start Game”. Just a word of warning, the cursor can be a bit off sometimes so be patient! If this is the first time that you are running Minecraft on the Pi, then you will only have one option- “Create New”. Click this, and it will tell you that it is building the world and there should be a progress bar. If Minecraft has been run on that Pi before, then you can either double-click a world to load it or you can also select “Create New”.

Once you loaded up your world, you will need to now how to move. Minecraft uses the “WASD” controls, which means that you use the “WASD” keys to move. W is forward, A is left, S is back and D is right. As well as this, you can also crouch by holding down the shift key, jump by pressing space bar, and fly by quickly double tapping the space bar. When in flying mode, hold space bar to ascend and hold shift to descend: the other direction keys stay the same.

Being able to run/fly around the world is fun, but it’s even better if you can place/destroy things. When looking at a block, hold down left-click to destroy the block. You will also notice that you have a bar at the bottom of your screen. The highlighted box is what your character is currently holding and each box represents a block or item. If you right-click while looking at another block and while holding a block, you will place it. In this version, you are always in creative mode, which means you have unlimited resources. You can swap between the nine items in your “hot bar” (the name of the bar a the bottom of the screen) by either scrolling or pressing the number key corresponding to that item/block’s position. For example, if I had stone in my sixth slot, I could select it by pressing 6.


Having nine items soon gets boring, so why not have more. To do this, select the slot you want to put your new item/block in using the scroll wheel or the number keys, then press the “e” key. This brings your inventory screen up, where every block/item in the game that is available to you is displayed. Simply click the item that you want and it will now be in the highlighted slot in your inventory.

That concludes the section on regular (so called vanilla) Minecraft for the Pi. Next time, we will get stuck into using python to change things in the Minecraft world.

Written By Mathew Monk MinecraftMastery | @minecraftmasterybook


If you haven’t heard of Minecraft before, it is a game developed by Mojang and originally created by Markus “Notch” Persson. Quite simply, it is a game about placing different types of blocks. Although it may sound a bit dull, Minecraft is one of the most popular games on PC (and has since come to consoles) because of the creativity involved of making anything from complex contraptions (using something called “Redstone“) to massive buildings and even whole countries. Sadly, the Raspberry Pi version has to be limited as the Raspberry Pi itself is limited and therefore uses a C rendition of the originally Java based, mobile version of the game. All of the Minecraft: Pi Edition information from this guide is sourced from

First things first, this is for the Raspbian (wheezy) Operating System on the Raspberry Pi. Also note that XWindows must be running (type startx into the LXTerminal to do this). XWindows may be already start by default with your Pi and if not you can change this by typing sudo raspi-config . The first task is to actually download Minecraft for the Raspberry Pi. So, to start off,  type wget into LXTerminal and your download should begin.

Now that you have the file on your Raspberry Pi, and you have made sure that XWindows is running (see above) you need to type the following command into LXTerminal to unpack the tar.gz file- tar -zxvf  rasp-pi-minecraft Lots of file/file paths should show up in your window (see picture below). If it does not, make sure you have spelt everything correctly.


That’s everything that has to be downloaded! All that’s left now is to run Minecraft. To do this, first we need to change our current working directory in LXTerminal to mcpi- simply type cd mcpi The final step is to start the Minecraft program by typing ./minecraft-pi Make sure you put the ./ at the start! If everything went well, you should now have an instance of Minecraft running on your Raspberry Pi.

Written By Mathew Monk MinecraftMastery | @minecraftmasterybook