Tetris in the Minecraft World

Not sure if this has been done before on the Pi version of Minecraft, but anyway to demonstrate the awesomeness of code reuse, here is a very simple re-engineering of my last bit of madness, Tetris on LEDs.

My previous project contained the following function which simply took a pygame Surface and rendered it to the PiLite:

This version replaces that simple function, with this even simpler function:

# Blit a pygame surface onto the Minecraft world
# Anything but BLACK gets rendered as stone, everything else as air
def mc_blit(surface):
w,h=surface.get_size()
for y in range(14):
for x in range(9):
if x>=w or surface.get_at((x,y))==BLACK:
mc.setBlock(MC_X,MC_Y+HEIGHT-y,MC_Z+x,AIR)
else:
mc.setBlock(MC_X,MC_Y+HEIGHT-y,MC_Z+x,ROCK)

This function renders the exact same game into the Pi version of the Minecraft world!

Apart from this function, the main tetris algorithm is identical to my previous project!

Unfortunately this is a bit slower than PiLite rendering, so it kills the frame rate a bit!

How do I run this on my Pi?

OK, I’m going to assume you know how to use git and github – if you don’t it’s time you learnt! I’m also going to assume you’re used to using the command line.

There are a couple of things you may need to do to get this to run.

First you need to make sure Minecraft Pi and the API are installed properly, by typing this into a terminal:

Then you need to start up minecraft, and go to the “X,Y,Z” coordinates in your minecraft world which match these lines in my code:

# Minecraft render offset
MC_X=40
MC_Y=1
MC_Z=10

(Alternatively, you can edit the tetris-mc.py file and move the tetris game wherever you want in your world!)

Once you’ve got minecraft ready, press Tab to release the mouse, then switch to your terminal window and run tetris-mc.py using:

python tetris-mc.py

from the directory you downloaded the file into.

OK, you’re done!

Note that when you run the python script, it creates a tiny window which needs to have focus for the keyboard controls to work.

If you need to go back to minecraft to rotate or whatever to get a better view, the easiest thing to do is go back to the terminal, hit Ctrl-C to exit, and then run the script again.

What next?

Well, that’s up to you dear reader! I’m probably done with rendering tetris on to different devices (who am I kidding?) so come on, what else can you render tetris on?

Take my code, hack it about, get it to render on something really weird, and share it with the world! (And let me know, so I can tell you how great you are!)

Alternatively, what other games are playable at such a ridiculously low framerate that you could implement on pygame (or borrow someone else’s implementation) and hack it about so it can be rendered on the PiLite or in Minecraft using one of my functions?