The great thing about Minecraft on the Raspberry Pi is that you write Python scripts to manipulate the game world. This opens up a lot of creative possibilities. It can also make Python a lot more appealing to budding programmers.

In this tutorial I want to explain how to create a Pyramid using Minecraft.

Here is an example of a 10 level pyramid with a block on top :

By creating a Python function to create the Pyramid we can easily create a set of Pyramids of varying sizes at specific locations. My goal was to create the famous Pyramids of Giza without having to use a single slave or a single piece of ancient alien technology.

## Setup

To use the script below you will need to have Minecraft and the Python API setup. In the latest Raspbian image Minecraft and the API are already setup so you dive straight into the fun bit.

## The Pyramid Builder Function

Here is the Python function I used to build the pyramid :

```def CreatePyramid(posx,posy,posz,width,mybase,mywalls,mytopblock):
# Function to create a pyramid at x,y,z
# with specified width using the specified
# block materials for the base, walls and top.

# May sure width is odd number so pyramid ends
# with a single block
if width%2==0:
width=width+1

height = (width+1)/2
halfsize = int(math.floor(width/2))

print "Player : {} {} {}".format(posx,posy,posz)
print "Size : {} Height : {} Halfsize : {}".format(width,height,halfsize)

# Create base for pyramid
print "Create solid base"
mc.setBlocks(posx-halfsize-2,posy-2,posz-halfsize-2,posx+halfsize+2,posy-2,posz+halfsize+2,DIRT)
mc.setBlocks(posx-halfsize-2,posy-1,posz-halfsize-2,posx+halfsize+2,posy-1,posz+halfsize+2,mybase)

# Create solid Pyramid
print "Create Pyramid"
for y in range(posy,posy+height):
mc.setBlocks(posx-halfsize,y,posz-halfsize,posx+halfsize,y,posz+halfsize,mywalls)
halfsize = halfsize-1

# Change top block
print "Set top block"
mc.setBlock(posx,posy+height-1,posz,mytopblock)

print "Position player on top"
mc.player.setPos(posx,posy+height,posz)
```

The CreatePyramid function takes some arguments. These are :

• Position (posx, posy, posz)
• Width (in blocks)
• Materials (mybase,mywalls,mytopblock)

`wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/minecraft/pyramids.py`

The script :

• Imports the Minecraft API library
• Defines the “CreatePyramid” function
• Calls the function a number of times to create a set of pyramids of varying sizes

With Minecraft running you can execute the Python script in a terminal window using :

`python pyramids.py`

The scripts doesn’t take long to complete but it may take about 30-60 seconds for Minecraft to update. Here is the result :

Once you’ve got your Pyramid complex built you can consider how to modify it. There is plenty of scope for carving doorways and building secret passages!

I gave up on an accurate re-creation of the Giza complex because with the draw distance on the Pi version of Minecraft you can’t really fit it all in without making the Pyramids quite small.

In my script the pyramids are topped with a block of gold. You can change this or the pyramid base and wall blocks to another type. Take a look at my Minecraft Block ID Reference for ideas.

By changing the parameters passed to the “CreatePyramid” function at the end of the script you can change the size and position of the pyramids. By adding or removing calls to the function you can adjust the number built.

## What Next

Once you can build a pyramid you could hide an object in a random one and see how long it takes to find. Maybe you could adjust the function to automatically add some tunnels underneath the pyramids and build a secret network?

Share.