Tuesday, 21 May 2013

Minecraft: Pi Edition - 2 Games by Nicholas Harris

Nicholas Harris is a regular commenter and reader of the minecraft posts on <Stuff about="code" /> and he let me know that he was working on a program for minecraft, he also agreed to let me include a post about what he has done.   Check out the Minecraft - API Basics comments section for a description of Nicholas's development.

Nicholas has pulled together one mother of a minecraft program which encompasses a load of different games, utilities and building tools.  Including a script to create a horse, characters from the alphabet, a crazy utility which makes you fall through the earth and die, but perhaps most impressively 2 games of his own invention:
  • Arena's starts with you stood in an empty room and the objective is to not fall to your death while the floor beneath you gradually disappears
  • Dodge puts you at one end of a line of furnaces which spew there contents towards you and you have to stay out of the way.
They both show a great deal of originality and thought, not to mention coding skill.



If you fancy trying out Nicholas's program, follow the instructions below to download, setup and run.

Create a directory for the program

mkdir ~/minecraft-nicholas
cd ~/minecraft-nicholas

Download Nicholas's program


Copy the minecraft api python library

cp -r ~/mcpi/api/python/mcpi ~/minecraft-nicholas/minecraft

Start up Minecraft and run Nicholas's program

python ~/minecraft-nicholas/api.py

Commands
The program uses a command line interface to start up the games and utilities, so use:
  • /help to give you a list of the commands 
  • /arena to start the arena game 
  • /dodgegame to start the dodge game.


I think its great when people take the initiative and create something cool off their own back and I couldn't be happier that the drivel I write is actually useful to someone! 

Tuesday, 14 May 2013

Raspberry Pi - Minecraft - Blocks into bombs using events

Up to now I hadn't had a need to make use of the "Event" methods in Minecraft's API and I wanted to learn a little more about how it worked, so I could include some information in my Minecraft API Tutorial.

I wanted to do something fun with it, so I decided to see if I could make some bombs!  The concept is really simple, when you hit a block (right click with the sword), it turns it into a mini bomb, flashing for a few seconds, before exploding and destroying all the blocks around it.  Boom!

With this and the programmable cannon I wrote, I'm really getting quite destructive.



The block event methods in the API are pretty easy to understand, after you have made a connection to the minecraft server:

mc = minecraft.Minecraft.create()

You can call the mc.events.pollBlockHits() method which returns you a list of BlockEvent objects.  These objects represent the blocks position (x,y,z) and face which have been hit since it was last run.  So, if you hit 2 blocks in between connecting to the minecraft server and running the command you would get a list with 2 BlockEvent objects in it, if you hadn't hit any you would get an empty list.

By creating a simple loop you can monitor the block events and then take whatever action you want:

while True:
    #Get the block hit events
    blockHits = mc.events.pollBlockHits()
    # if a block has been hit
    if blockHits:
        # for each block that has been hit
        for blockHit in blockHits:
            # do something with the block
            print blockHit.pos.x
            print blockHit.pos.y
            print blockHit.pos.z
            print blockHit.face
            print blockHit.type
            print blockHit.entityId

The bombs are created by using a class which when passed a block position, it flashes the block, by setting the block to AIR and then back again, for a number of seconds (the fuse) and then creating a sphere of AIR destroying all blocks around it.

I used pythons threading module and run the Bomb class as a daemon (i.e. outside my main program) as I wanted to be able to create multiple bombs at the same time.

Download and run
You can download the code direct from githubhttps://github.com/martinohanlon/minecraft-bombs, so run minecraft, open/create a world and follow the instructions:

sudo apt-get install git-core
cd ~
git clone https://github.com/martinohanlon/minecraft-bombs.git
cd minecraft-bombs
python minecraft-bombs.py

The code
If you want learn and have a go yourself, here's how:

Create a directory for the program

mkdir ~/minecraft-bombs

Copy the python api class library from minecraft to the programs directory

cp -r ~/mcpi/api/python/mcpi ~/minecraft-bombs/minecraft

Create minecraft-bombs.py python program

nano ~/minecraft-bombs/minecraft-bombs.py

or open Idle and save minecraft-bombs.py to the minecraft-bombs directory

Code

#www.stuffaboutcode.com
#Raspberry Pi, Minecraft Bombs - Turn any block into a bomb!

#import the minecraft.py module from the minecraft directory
import minecraft.minecraft as minecraft
#import minecraft block module
import minecraft.block as block
#import time, so delays can be used
import time
#import threading, so threads can be used
import threading

class ExplodingBlock(threading.Thread):

    def __init__(self, pos, fuseInSecs, blastRadius):
        #Setup object
        threading.Thread.__init__(self)
        self.pos = pos
        self.fuseInSecs = fuseInSecs
        self.blastRadius = blastRadius

    def run(self):
        #Open connect to minecraft
        mc = minecraft.Minecraft.create()

        #Get values
        pos = self.pos
        blastRadius = self.blastRadius

        #Explode the block!
        # get block type
        blockType = mc.getBlock(pos.x, pos.y, pos.z)
        # flash the block
        for fuse in range(0, self.fuseInSecs):
            mc.setBlock(pos.x, pos.y, pos.z, block.AIR)
            time.sleep(0.5)
            mc.setBlock(pos.x, pos.y, pos.z, blockType)
            time.sleep(0.5)
        # create sphere of air
        for x in range(blastRadius*-1,blastRadius):
            for y in range(blastRadius*-1, blastRadius):
                for z in range(blastRadius*-1,blastRadius):
                    if x**2 + y**2 + z**2 < blastRadius**2:
                        mc.setBlock(pos.x + x, pos.y + y, pos.z + z, block.AIR)

if __name__ == "__main__":

    time.sleep(5)
    #Connect to minecraft by creating the minecraft object
    # - minecraft needs to be running and in a game
    mc = minecraft.Minecraft.create()

    #Post a message to the minecraft chat window 
    mc.postToChat("Minecraft Bombs, Hit (Right Click) a Block, www.stuffaboutcode.com")

    #loop until Ctrl C
    try:
        while True:
            #Get the block hit events
            blockHits = mc.events.pollBlockHits()
            # if a block has been hit
            if blockHits:
                # for each block that has been hit
                for blockHit in blockHits:
                    #Create and run the exploding block class in its own thread
                    # pass the position of the block, fuse time in seconds and blast radius
                    # threads are used so multiple exploding blocks can be created
                    explodingBlock = ExplodingBlock(blockHit.pos, 3, 3)
                    explodingBlock.daemon
                    explodingBlock.start()
            time.sleep(0.1)
    except KeyboardInterrupt:
        print("stopped")

Wednesday, 17 April 2013

Raspberry Pi - Minecraft Cannon

I had this idea about using Minecraft: Pi Edition and its API to show how trigonometry, mechanics and mathematics can actually be useful and given that everyone likes to blow stuff up....  I thought I would make a cannon. 
A cannon which could point in any direction (0-360 degrees), angle upwards (0-90 degrees) and when fired would send a cannon ball upwards, falling in-line with the laws of gravity and then explode when it hit the ground.

http://youtu.be/6NHorP5VuYQ

I liked the idea of a command line interface, its a cannon after all they are not meant to be hi-tech devices, to control the cannon you use the following commands:
  • start - create [start-up] the cannon
  • rotate [0-360 degress] - rotate the cannon
  • tilt [0-90 degress] - tilt the cannon upwards
  • fire - FIRE!
  • exit - exit and clear the cannon

The code contains 4 classes written in Python:
  1. CannonCommands - used to control the command line interface, based on python's cmd module
  2. MinecraftDrawing - a generic class I'm building up which supports many generic drawing functions (drawLine, drawFace, drawSphere, etc)
  3. MinecraftCannon - a class which controls the building and changing of the cannon base and its gun, this contains all the code required to 'point' the gun to a specific point on the a sphere based on the direction and tilt angles
  4. MinecraftBullet - a class which controls the flight of the bullet through the air and its eventual explosion, including the maths to manage general mechanics of velocity and gravity

Download and run
You can download the code direct from github, https://github.com/martinohanlon/minecraft-cannon, so run minecraft, open/create a world and follow the instructions:

sudo apt-get install git-core
cd ~
git clone https://github.com/martinohanlon/minecraft-cannon.git
cd minecraft-cannon
python minecraft-cannon.py


Saturday, 13 April 2013

Minecraft: Pi Edition - 3d Models - Version 2

I created a program, which using the Minecraft: Pi Edition API, takes 3d models and creates them in Minecraft, but version 1 only created the models as wire-frames and only in one block.

Version 2 is now out which uses the same concept of taking a 3d model as an obj file and using the api to render it in Minecraft but it now draw's complete polygons rather than wire-frames and gives the ability to specify a minecraft block for each material, allowing models to be created completely and in 'colour'.

The first model to try, well that of a Raspberry Pi of course!  Thanks to mnt and his Sketchup model of a Raspberry Pi which I exported as an obj file and my program made in Minecraft.




Adding the use of materials to the program was relatively easy, the obj file specifies which material should be used for a face (or faces), my program just uses a python dictionary object to specify the mapping between material and block type/data in python e.g. MATERIALS= {"Material1": [block.STONE, None], "Material2": [block.WOOL.id, 0]}, using polygons rather wire-frames was much more difficult.

To support drawing polygons, which when put together would create 3d polyhedrons I wrote a MinecraftDrawing class to implement the following algorithm:

  • Find all the points on all the edges of the polygon (red lines)
  • Draw lines between the edges of the polygon
    • Sort all the points by the dimensions (x,y,z)
    • Draw lines using a 3d version of the bresenham line algorithm (thick black lines)
This was complicated due to the Minecraft 'screen' being 3d, not 2d and google totally failing me in finding some example code!  So I had to write it myself, ridiculous!

I ended up creating several versions of this function, trying to create a more performant version, but as the faces became more complicated (i.e. bigger with more than 3 points) my performant versions ended up missing blocks, so I settled on a simple implementation that was slow but always filled the gap!

I'll get the code onto github shortly and update the post.

I then went on to re-draw the space shuttle and manhattan of previous posts.

Space Shuttle
Manhattan

Tuesday, 9 April 2013

Minecraft: Pi Edition - API Tutorial

This is part of an article I wrote on Minecraft: Pi Edition for the Issue 11 of The Mag Pi, a magazine written by Raspberry Pi enthusiasts.  I highly recommend you give The Mag Pi a go, its always full of interesting and relevant articles.


This article builds on my first post Raspberry Pi - Minecraft - API Basics, which describes the basics of how to use the API.

Install Minecraft
If you haven't done so already, head over to this post for how to Install Minecraft on the Raspberry Pi.

The API
The API allows you to write programs which control, alter and interact with the minecraft world, unlocking a whole load of minecraft hacking.  How about creating massive structures at the click of a button or a bridge which automatically appears under your feet allowing you to walk across massive chasms or a game of minesweeper, a huge real time clock, a programmable directional cannonturn blocks into bombs or the game snake?




Minecraft is a world of cubes or blocks, all with a relative size of 1m x 1m x 1m, and every block has a position in the world of x, y, z; x and z being the horizontal positions and y being the vertical.


The API works by changing the ‘server’, which runs underneath the game, allowing you to interact with these blocks and the player, such as:

  • Get the player’s position
  • Change (or set) the player’s position
  • Get the type of block
  • Change a block
  • Change the camera angle
  • Post messages to the player

Libraries
You can interact with the server directly by sending a message to it, but the nice people at Mojang also provide libraries for python and java which simplify and standardise using the API.

The libraries are installed along with the game in the mcpi/api/java and mcpi/api/python directories.

The following example is written in Python and uses Mojang’s python api library, the first task is to create a directory for your API program and copy the python library to it.

API Example

Create Directory
We need to create a directory to put our program and api library into.

mkdir ~/minecraft-magpi

Copy Python Library
We will be using the python api library supplied with the game and need to copy it into our directory.

cp -r ~/mcpi/api/python/mcpi ~/minecraft-magpi/minecraft

Create program
Open Idle (or your favourite editor) and create a program file called minecraft-magpi.py in the ~/minecraft-magpi directory

We are going to need 3 modules, the minecraft.py and block.py modules from the minecraft directory containing the library we just copied and the standard time module so we can introduce delays into our program.

import minecraft.minecraft as minecraft
import minecraft.block as block
import time

Next, we need to use the Minecraft class in the python library to create a connection to the game’s server, this object will also be how we interact with the game and will provide access to all the functions.  When your program runs this statement, Minecraft will have to be running and you will need to be in a game, otherwise you will get errors.

mc = minecraft.Minecraft.create()

Using our minecraft object, mc, we can then interact with the game and send the player a message.  We will also put a delay in using the time.sleep() function otherwise the whole program will run too fast for us to see what’s going on.

mc.postToChat("Hello Minecraft World")
time.sleep(5)

Using the program built so far, you can test to make sure everything is working.  Load up minecraft and create a (or enter an existing) world then if you’re using Idle pick 'Run, Run Module'  from the menu.  If all has been setup correctly you will see the “Hello Minecraft World” message in the game.


Interacting with the player is done through the player class of the mc object allowing us to find the position and change the position of the player.  The next block of code finds the players position using the getPos() command, which returns an object of x,y and z coordinates, the setPos() command is then used to move the player 50 blocks up, by adding 50 to the player’s y coordinate.  We then add a delay, so there is enough time for your player to fall down to the ground!

playerPos = mc.player.getPos()
mc.player.setPos(playerPos.x, playerPos.y + 50, playerPos.z)
mc.postToChat("Dont look down")
time.sleep(5)

You can use the position of the player as a starting point for interacting blocks, this way you can find out what block the player is standing on or place blocks around the player, there is however a challenge, the x, y and z coordinates returned by the getPos() function are decimals (aka floats), as your player can be in the middle of a block, but to interact with blocks we need to use whole numbers (aka integers), so we need to use the function getTilePos(), which returns the block (or tile) he’s standing on.

The code below gets the players tile position, it then calls the minecraft API’s getBlock() function to find out the type of block the player is standing on (by minusing 1 from the y co-ordinate) before using setBlock() to create blocks of the same type the player is standing on around him.  So if your player is standing on DIRT, he will end up with DIRT surrounding him, however if he is standing on STONE, STONE will appear.

playerTilePos = mc.player.getTilePos()
blockBelowPlayerType = mc.getBlock(playerTilePos.x, playerTilePos.y - 1, playerTilePos.z)
mc.setBlock(playerTilePos.x + 1, playerTilePos.y + 1, playerTilePos.z, blockBelowPlayerType)
mc.setBlock(playerTilePos.x, playerTilePos.y + 1, playerTilePos.z + 1, blockBelowPlayerType)
mc.setBlock(playerTilePos.x - 1, playerTilePos.y + 1, playerTilePos.z, blockBelowPlayerType)
mc.setBlock(playerTilePos.x, playerTilePos.y + 1, playerTilePos.z - 1, blockBelowPlayerType)
mc.postToChat("Trapped you")
time.sleep(5)


We have now trapped our player within 4 blocks (providing he doesn’t break out!), in order to set him free we need to remove a block.  Removing blocks is done using setBlock(), but rather than making the block solid like WOOD or STONE we set it to AIR.

mc.setBlock(playerTilePos.x + 1, playerTilePos.y + 1, playerTilePos.z, block.AIR)
mc.postToChat("Be free")
time.sleep(5)

A full list of all the available blocks can be found in either the minecraft api specification or in the block.py module in the python api library ~/mcpi/api/python/mcpi/block.py.

The API also allows you to set many blocks at a time, allowing you to create cuboids very quickly using the setBlocks() command.  It works by specifying 2 sets of x,y,z coordinates which it then fills the gap between the 2 coordinates with a certain block you pass as the final parameter.  The code below will create a diamond floor underneath our player 50 blocks (across) x 1 block (up) x 50 blocks (along), with our player in the middle (i.e. 25 behind and to the left, 25 in front and to the right).

mc.setBlocks(playerTilePos.x - 25, playerTilePos.y - 1, playerTilePos.z - 25, playerTilePos.x + 25, playerTilePos.y -1, playerTilePos.z + 25, block.DIAMOND_BLOCK)
mc.postToChat("Now thats a big diamond floor!")


To recap on the functions covered in this article:
  • postToChat(message) - communicate with the player(s) in the game
  • getBlock(x, y, z) - get a block type for a specific position
  • setBlock(x, y, z, blockType, blockData) - set (change) a block to a specific blockType
  • setBlocks(x1, y1, z1, x2, y2, z2, blockType, blockData) - set lots of blocks all at the same time by providing 2 sets of co-ordinates (x, y, z) and fill the gap between with a blockType
  • player.getPos() - get the precise position of a player
  • player.setPos(x, y, z) - set (change) the players position
  • player.getTilePos() - get the position of the block where the player current is
There are a few other functions available in the api which should be explored but using only the small number discussed in this article, its possible, with some imagination and a small amount of programming knowledge to create some quite fantastic constructions, tools and utilities.

I love minecraft, its a tremendously creative game and with the Pi edition’s API it opens up new level of creativity and will hopefully encourage more people to try their hand at programming.

If you want to see more examples of what I have done with Minecraft: Pi edition (e.g. a massive analogue clock, the game of snake, an auto bridge which appears under your feet or the whole of Manhattan) head over to my Minecraft page.

Monday, 1 April 2013

Minecraft: Pi Edition - Manhattan Island

How about a stroll around Manhattan?  Well a stroll around Manhattan in Minecraft, perhaps admire the Empire State Building or the pay $25 to take in the view from the "top of the rock"?

Empire State Building
View from "Top of the Rock"
I decided to see how much I could push the program I wrote which uses the API in the Pi edition of Minecraft to render 3d models in the Minecraft World.  It turns out I could push it a LOT, I fancied creating a city scene, and is any more dramatic than New York, Manhattan Island.


I found a Google sketchup model of Manhattan and using OBJexporter, exported the model to an OBJ file.

Sketchup 3d model of Manhattan
To give a scale of how massive this model is, previously the most complicated model I had produced in Minecraft was of a girls head, that took about 3 minutes to render, this took 1 hour 25 minutes, and that was after I had already cleared a suitably large area!  The Pi took it all in its stride though and while it took a long time, there were no errors or glitches.

The model is pre 9/11, so the iconic Twin Towers still dominate the skyline.

Iconic buildings
Download and run
I have updated my program to include the new york model, which you can download direct from git-hub, so run minecraft, open/create a world and follow the instructions:

sudo apt-get install git-core
cd ~
git clone https://github.com/martinohanlon/minecraft-renderObj.git
cd minecraft-renderObj
python minecraft-renderObj.py

If you want to know more about how this works and have a go yourself, head to this post, http://www.stuffaboutcode.com/2013/03/minecraft-pi-edition-create-massive-3d.html.


Tuesday, 26 March 2013

Minecraft: Pi Edition - Create Massive 3D Models

I love a massive construction in Minecraft, you know when someone creates a scale model of the earth or a house to put the Taj Mahal to shame, but I'm lazy and I'm definitely not going to spend months of my time building one.  What about a program that builds them for you.

What about a program that takes a 3d model, runs through all those points and polygons and draws a representation of the model in Minecraft.



3D Models in Minecraft
Space shuttle
A skyscraper
Cessna aeroplane
Girls head

Update - Ive pushed the boundaries of this program much further and rendered Manhattan Island in Minecraft.




How
The concept of making this work is pretty simple.

3d models can be saved as a particular type of file, an obj, which is an uncompressed text representation of the model, it describes all the points (aka vertices) as x, y, z coordinates and faces, 3 or more points which when connected create a block or polygon.

My program reads these obj files and then creates line between the points of the faces, effectively creating a wire frame representation of the model in Minecraft.  Simple eh!

The models need to be scaled appropriately to be able to fit in the minecraft world, the scales depends on the detail within the model .

At the moment the program only uses the vertices and faces within the obj files, but it certainly could be extended to create filled polygons rather than wireframe, cope with curves and potentially to use different surfaces and textures.

Update - I have created version 2 of this program, which draws filled polygons and uses the materials within obj files to pick an appropriate block, allowing the model to now be in 'colour'.

A Raspberry Pi rendered in Minecraft


Download and run
You can download the code direct from git-hub, so run minecraft, open/create a world and follow the instructions:

sudo apt-get install git-core
cd ~
git clone https://github.com/martinohanlon/minecraft-renderObj.git
cd minecraft-renderObj
python minecraft-renderObj.py

Code
I've included the code here for reference, but if you want to get it working I suggest you download the repository from github using the instructions above as you will also need other files (e.g. obj's) in to get the code working.

#www.stuffaboutcode.com
#Raspberry Pi, Minecraft - Create 3D Model from Obj file

#import the minecraft.py module from the minecraft directory
import minecraft.minecraft as minecraft
#import minecraft block module
import minecraft.block as block
#import time, so delays can be used
import time

# return maximum of 2 values
def MAX(a,b):
    if a > b: return a
    else: return b

# return step
def ZSGN(a):
    if a < 0: return -1
    elif a > 0: return 1
    elif a == 0: return 0

# draw point
def point3d(mc, x, y, z, blockType):
    mc.setBlock(x,y,z,blockType)

# draw a line in 3d space
def line3d(mc, x1, y1, z1, x2, y2, z2, blockType):
    dx = x2 - x1
    dy = y2 - y1
    dz = z2 - z1

    ax = abs(dx) << 1
    ay = abs(dy) << 1
    az = abs(dz) << 1

    sx = ZSGN(dx)
    sy = ZSGN(dy)
    sz = ZSGN(dz)

    x = x1
    y = y1
    z = z1

    # x dominant
    if (ax >= MAX(ay, az)):
        yd = ay - (ax >> 1)
        zd = az - (ax >> 1)
        loop = True
        while(loop):
            point3d(mc, x, y, z, blockType)
            if (x == x2):
                loop = False
            if (yd >= 0):
                y += sy
                yd -= ax
            if (zd >= 0):
                z += sz
                zd -= ax
            x += sx
            yd += ay
            zd += az
    # y dominant
    elif (ay >= MAX(ax, az)):
        xd = ax - (ay >> 1)
        zd = az - (ay >> 1)
        loop = True
        while(loop):
            point3d(mc, x, y, z, blockType)
            if (y == y2):
                loop=False
            if (xd >= 0):
                x += sx
                xd -= ay
            if (zd >= 0):
                z += sz
                zd -= ay
            y += sy
            xd += ax
            zd += az
    # z dominant
    elif(az >= MAX(ax, ay)):
        xd = ax - (az >> 1)
        yd = ay - (az >> 1)
        loop = True
        while(loop):
            point3d(mc, x, y, z, blockType)
            if (z == z2):
                loop=False
            if (xd >= 0):
                x += sx
                xd -= az
            if (yd >= 0):
                y += sy
                yd -= az
            z += sz
            xd += ax
            yd += ay

# load obj into lists
def load_obj(filename) :
    V = [] #vertex
    T = [] #texcoords
    N = [] #normals
    F = [] #face indexies

    fh = open(filename)
    for line in fh :
        if line[0] == '#' : continue
        line = line.strip().split(' ')
        if line[0] == 'v' : #vertex
            V.append(line[1:])
        elif line[0] == 'vt' : #tex-coord
            T.append(line[1:])
        elif line[0] == 'vn' : #normal vector
            N.append(line[1:])
        elif line[0] == 'f' : #face
            face = line[1:]
            for i in range(0, len(face)) :
                face[i] = face[i].split('/')
                # OBJ indexies are 1 based not 0 based hence the -1
                # convert indexies to integer
                for j in range(0, len(face[i])) :
                    if face[i][j] != "":
                        face[i][j] = int(face[i][j]) - 1
                        
            F.append(face)

    return V, T, N, F

# strips the x,y,z co-ords from a vertex line, scales appropriately, rounds and converts to int
def getVertexXYZ(vertexLine, scale, startCoord, swapYZ):
    # convert, round and scale
    x = int((float(vertexLine[0]) * scale) + 0.5)
    y = int((float(vertexLine[1]) * scale) + 0.5)
    z = int((float(vertexLine[2]) * scale) + 0.5)
    # add startCoord to x,y,z
    x = x + startCoord.x
    y = y + startCoord.y
    z = z + startCoord.z
    # swap y and z coord if needed
    if swapYZ == True:
        swap = y
        y = z
        z = swap
    return x, y, z

# main program
if __name__ == "__main__":


    #Load objfile and set constants

    # COORDSSCALE = factor to scale the co-ords by
    # STARTCOORD = where to start the model, the relative position 0
    # CLEARAREA1/2 = 2 points the program should clear an area in between to put the model in
    # SWAPYZ = True to sway the Y and Z dimension
    # BLOCKTYPE = type of block to build the model in

    # Cube
    #COORDSSCALE = 10
    #STARTCOORD = minecraft.Vec3(0,10,0)
    #BLOCKTYPE = block.STONE
    #SWAPYZ = False
    #vertices,textures,normals,faces = load_obj("cube.obj")

    # Shuttle
    #COORDSSCALE = 4
    #STARTCOORD = minecraft.Vec3(-60,0,20)
    #CLEARAREA1 = minecraft.Vec3(-30, 5, -30)
    #CLEARAREA2 = minecraft.Vec3(-90, 30, 30)
    #BLOCKTYPE = block.WOOL
    #SWAPYZ = True
    #vertices,textures,normals,faces = load_obj("shuttle.obj")

    # Shyscraper
    COORDSSCALE = 1.4
    STARTCOORD = minecraft.Vec3(0,10,15)
    CLEARAREA1 = minecraft.Vec3(-30, -3, -15)
    CLEARAREA2 = minecraft.Vec3(30, 65, 35)
    BLOCKTYPE = block.IRON_BLOCK
    SWAPYZ = False
    vertices,textures,normals,faces = load_obj("skyscraper.obj")

    # Head
    #COORDSSCALE = 3
    #STARTCOORD = minecraft.Vec3(0,-431,-60)
    #CLEARAREA1 = minecraft.Vec3(-30, -30, -30)
    #CLEARAREA2 = minecraft.Vec3(30, 65, -110)
    #BLOCKTYPE = block.GOLD_BLOCK
    #SWAPYZ = False
    #vertices,textures,normals,faces = load_obj("head.obj")

    # Cessna
    #COORDSSCALE = 2
    #STARTCOORD = minecraft.Vec3(-75, 25, -60)
    #CLEARAREA1 = minecraft.Vec3(-30, 15, -30)
    #CLEARAREA2 = minecraft.Vec3(-100, 65, -90)
    #BLOCKTYPE = block.WOOD_PLANKS
    #SWAPYZ = False
    #vertices,textures,normals,faces = load_obj("cessna.obj")
    
    #Connect to minecraft by creating the minecraft object
    # - minecraft needs to be running and in a game
    mc = minecraft.Minecraft.create()

    #Post a message to the minecraft chat window 
    mc.postToChat("Hi, Minecraft 3d model maker, www.stuffaboutcode.com")
    
    # clear a suitably large area
    mc.setBlocks(CLEARAREA1.x, CLEARAREA1.y, CLEARAREA1.z, CLEARAREA2.x, CLEARAREA2.y, CLEARAREA2.z, block.AIR)
    time.sleep(3)

    # loop through faces
    for face in faces:
        #persist the first vertex of the face
        firstVertex = face[0]
        #get the x,y,z co-ords of the first vertex
        firstVertexX, firstVertexY, firstVertexZ = getVertexXYZ(vertices[firstVertex[0]], COORDSSCALE, STARTCOORD, SWAPYZ)
        #last vertex is current none
        lastVertex = None

        # loop through vertex's in face and draw lines between them
        for vertex in face:
            vertexX, vertexY, vertexZ = getVertexXYZ(vertices[vertex[0]], COORDSSCALE, STARTCOORD, SWAPYZ)
            
            if lastVertex != None:
                # got 2 vertices, draw a line between them
                line3d(mc, lastVertexX, lastVertexY, lastVertexZ, vertexX, vertexY, vertexZ, BLOCKTYPE)

            #persist the last vertex found    
            lastVertex = vertex
            lastVertexX, lastVertexY, lastVertexZ = vertexX, vertexY, vertexZ        

        # draw a line between the last and first vertex's
        line3d(mc, lastVertexX, lastVertexY, lastVertexZ, firstVertexX, firstVertexY, firstVertexZ, BLOCKTYPE)

    mc.postToChat("Model complete, www.stuffaboutcode.com")

Credits and useful links
I got a number of obj files from this website - http://people.sc.fsu.edu/~jburkardt/data/obj/obj.html

I got the basic code to parse an obj file here - http://programminglinuxgames.blogspot.co.uk/2010/09/parsing-wavefront-obj-file-format-using.html

I used this C code as the basis for my python function to draw line in 3d - http://www.luberth.com/plotter/line3d.c.txt.html

Short link to this post - http://bit.ly/14mzPXY