Introduction: Real World Minecraft

About: DIY, electronics...and loves getting creative...

We all Know Minecraft is an awesome game, and Raspberry Pi has made it more awesome. With the Minecraft API we can now write simple python scripts to interface read world sensors and buttons to the Minecraft world.

Step 1: What You Need

1. Bread board ( I am using a tiny breadboard, that is on a dev board ignore all components that are not on the bread board)
2. Switch / Button ( you can use an arcade button for more fun!!)
3. Wires
4. Raspberry Pi
5. 10k or 12 K Resistor
6. 330OHM Resistor
7. LED

Step 2: The Bread Board

Connect the button in a Active Low configuration.

Ignore all components that are not on the bread board :-)

Step 3: Connect Your Pi

Make sure your hook up the VCC to 3.3v and not to the 5v, a wrong connection would damage the Pi.

VCC = PIN1
DATA = PIN 16 (GPIO 23)
GND =GND

Look at step 2 for schematic.

Step 4: Instal Minecraft Pi

I would like to thank Martin O'Hanlon from StuffAboutcode for his awesome tutorial on Minecraft API, which helped me to come up with this tutorial...
You can install the Minecraft on the Pi using the following commands.
NOTE: You should use the latest build of Raspbian to have Minecraft working, if you are using the ada-fruit distro, you would need to update your firmware with the following command
sudo apt-get update && sudo apt-get install raspberrypi* raspi-config

Boot your pi, and login

type startx to go to the desktop
open terminal (icon should be on the desktop)

cd /Desktop
wget https://s3.amazonaws.com/assets.minecraft.net/pi/minecraft-pi-0.1.1.tar.gz
tar -zxvf minecraft-pi-0.1.1.tar.gz
cd mcpi

now run Minecraft....
./minecraft-pi

This automatically installs the API too, you can check out the API in the /api folder under /mcpi.

Step 5: Python Time

Now lets get Python libraries installed... for GPIOs...

Install python-dev and PRi-GPIO...(its better to do this from the default terminal, and not from the desktop)

sudo apt-get update
sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio

Make a folder for your project

cd ~
mkdir minecraftstuff

Copy required libraries to your folder
cp -r ~/mcpi/api/python/mcpi ~/minecraftstuff/minecraft

and start writing your code

OR just clone my repo

git clone https://github.com/sajingeo/minecraftrpi

Step 6: Hello World

Get my code from git hub (helloworld.py)

This would print helloworld on screen, when you press the button

NOTE:when minecraft is running, open another terminal window and run the script

sudo python helloworld.py

Understanding the Code :

import minecraft.minecraft as minecraft
import minecraft.block as block
import time
import RPi.GPIO as GPIO
import os

Import all necessary libraries for the project , RPi.GPIO is used to control the GPIO, and minecraft libraries are used to create blocks and talk to the minecraft world.

GPIO.setmode(GPIO.BCM)
Setup the GPIO driver, enable software control of the GPIOs

GPIO.setup(23,GPIO.IN)
setup GPIO 23 as input. for the button

mc= minecraft.Minecraft.create()
create a Minecraft object

GPIO.input(23)==False
to check if the button is pressed( Active Low)

mc.postToChat("Hello World!!")
print Hello world to Minecraft console

Step 7: Adding a Fire Button

Get my code from git hub (fire.py)

This would create a TORCH(if it is getting dark) block on pressing the button, you can also create blocks like TNT and FIRE .

NOTE:when minecraft is running, open another terminal window and run the script

sudo python fire.py

Step 8: Glowing LEDs

Get my code to glowLEDs here (connect your LED to GPIO 24 -- refer schematic)

Getting the poll function working was a pain, here i am creating a TNT block, and when the player's xPosition Matches with the TNT's x pos, the LED GLOWSSSS.....

Step 9: Adding a Move Button

Get my code from git hub (move.py)

This would move the X-position of your character when your press the button.

NOTE:When minecraft is running, open another terminal window and run the script

sudo python move.py

Step 10: Endless Possibilities

- Buttons to build structures like buildings

- Use pollBlockHits() to glow an LED when you press a button.

- Open you garage door from Minecraft world

- Use Accelerometer to navigate the Minecraft world

- Use Light sensors to control day and night in the Minecraft world

And don't forget to have fun guys...

Game.Life 3 Contest

Participated in the
Game.Life 3 Contest