Monday, 19 January 2015

MineCard Generator: see your name in blocks.

Ok, this whole project came about because we like to make cards for people. Christmas cards, birthday cards, new baby cards... you get the idea.

Over the last couple of years, whenever my sons have been asked what they think their friend would like as a theme for a birthday card, the answer has always been Minecraft. That's actually quite good news because a simple but cool picture for a card is the person's name created in Minecraft blocks.


Last year we ended up making loads of these and it got me thinking that there must be a way of automating the process using the Python API for Minecraft Pi Edition.  So we knocked up a simple script to allow the user to type in a name and a choice of block and then it would generate the block structure in Minecraft automagically. Working out the mechanics of creating each letter of the alphabet was a fun way to pass a wet Sunday afternoon. The result was a simple command line program that creates words in the Minecraft world (as long as they only contain the letters a-z).


I was quite happy with that but I couldn't help thinking that it should be possible to add even more automation: you still had to take the screenshot and then copy the resulting file off manually.

Then I got thinking about making some kind of web app...

So over the last few months I've been gradually putting all the elements together. Here's a high level design of how it works.


Using GoogleAppEngine as the web host, I have created a simple page where you can enter your text and select a block with which to build the letters. The service then uses xmpp to contact my Pi, which is running a listener and then uses the Minecraft API to create the message in blocks. After taking a screenshot and cropping appropriately, the final image is uploaded to DropBox (via the Python API) and the link passed back to the GoogleAppEngine service which displays it to the user.

Because I don't want to tie up a monitor permanently, it runs headless (although you have to start everything off with a monitor attached). However I want to be able to see what's going on so it displays some status information on the excellent Pimoroni Display-o-tron 3000. The white led bar across the bottom indicates the CPU load (running Minecraft all the time results in CPU load always being >70%) while the lcd portion of the dot3k lights up and displays the text and block choice of the latest message along with a count of the total number of requests that have been processed.




The complete operation takes about 60-90 seconds. this is mostly due to the time taken for the screenshot (the excellent Raspi2png is the only method of taking Pi screenshots I've found that actually captures the Minecraft window - most others only show a black rectangle) and then cropping out the window titlebar. I also check the message text for naughty words which adds an additional small delay.

Here is a movie of the whole shebang in operation. Or you can try it yourself here!


I think as a proof of concept it works quite well.  You could of course achieve the same functionality in lots of different ways, but I wanted to focus on easy-to-use services and tools that could be duplicated in an education environment for no cost. If you wanted to scale it better, it seems like a good project to implement using the Pi compute module.

Further work

  • Allow the user to select their own block type. 
  • Host the uploaded image directly in GAE rather than using DropBox
  • Add the ability to select different locations in the Minecraft world (with different scenary options)

No comments:

Post a Comment