Minecraft Text Generator

RPi Kitchen written in blocks

Using block-type 1 to automatically write text from a Python file.

A few more experiments with the Minecraft API and Python has brought be to this point… combining figlet with Python to create a minecraft text generator. More information on figlet can be found at www.figlet.org.

First… install figlet on your Raspberry Pi using:

sudo apt-get install figlet

Then test figlet by using:

figlet "hello world"

The basic structure of the program requires:

  • A connection to the Minecraft API.
  • Input the phrase to be rendered into a string variable.
  • Send the string to the operating system to be processed by figlet using the banner font.
  • Read the response back into a string variable and then split it into individual lines.
  • Work along each line creating a block or air depending on whether figlet added a “#” symbol to represent part of the text.

The screenshots were generated by raspi2png using the instructions from Raspberry Pi Spy.

The Python program is shown below:

from mcpi import minecraft
import commands
mc = minecraft.Minecraft.create()
mc.postToChat('Python is now in control!')

wr_str = raw_input('What would you like to write? ') # ask the user what they'd like to write at the current position

cmd = 'figlet -f banner '+wr_str # create an operating system command

line = commands.getoutput( cmd ) # send cmd as a command to the operating system and receive the result.

list_line = line.rstrip().split('\n') # split the result from 'figlet' into separate lines (right strip new line feeds)
print 'Your text has been converted to'
print line

startx,starty,startz = mc.player.getPos() #get the player's position

starty=starty+10 #lift the starty so that it's not written under your feet!

for row in list_line: # one row at a time from list_line (the result from figlet)
    starty=starty-1 # work down from the top
    for letter in row: # work along each row - check each character. If it's a '#' then print a block else leave it as air
        column = column+1
        if letter == '#':

Something that looks rather nice is to replace the “air” blocks (code 0 in the penultimate line) with something like 22 which translates to Lapis Lazuli. Alternatively, use 8 for the block type, which becomes water which flows from the words shown.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s