Tuesday, 14 July 2015

Minecraft Mega Structures

My Little Minecraft Pi project!

This is my Raspberry Pi project.  It's great to use Minecraft to create buildings, but the power of doing it programmatically is that you can create whole streets and towns.  This basic Python code will produce a street of skyscrapers.  

There's a lot of potential here and I am sure it would make the basis for some great lessons. What's great fun is as soon as you show people the idea people run with it & think of all sorts of refinements.

Here's the Python code, I hope it all makes sense. 

# Setup Minecraft library
from mcpi import minecraft
mc = minecraft.Minecraft.create()
#Get player position
x, y, z = mc.player.getPos()
#Terraforming - Create air
mc.setBlocks(x-30, y, z-30, x+500, y+39, z+40, 0)
#Make a grassy area
mc.setBlocks(x-30, y-1, z-30, x+500, y-2, z+40, 2)
#Loop to create 6 buildings
for builder in range (0,5):
    # Create stone block
    mc.setBlocks(x+1, y-1, z+1, x+11, y+40, z+11, 1)
    # Make it hollow
    mc.setBlocks(x+2, y, z+2, x+10, y+39, z+10, 0)
    #Create a series of windows
    for glwin in range (0,4):
        mc.setBlocks(x+2, y+(glwin*10), z+1, x+2, y+(glwin*10+3), z+1, 20)
        mc.setBlocks(x+6, y+(glwin*10), z+1, x+6, y+(glwin*10+3), z+1, 20)
        mc.setBlocks(x+8, y+(glwin*10), z+1, x+8, y+(glwin*10+3), z+1, 20)
        mc.setBlocks(x+2, y+(glwin*10), z+11, x+3, y+(glwin*10+3), z+11, 20)
        mc.setBlocks(x+6, y+(glwin*10), z+11, x+7, y+(glwin*10+3), z+11, 20)
        mc.setBlocks(x+8, y+(glwin*10), z+11, x+9, y+(glwin*10+3), z+11, 20)
    #Create door to see inside
    mc.setBlock(x+2, y, z+1, 71)
    mc.setBlock(x+2, y+1, z+1, 71)