How To Create A Pyramid In Minecraft With Python


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 :

Minecraft Pyramids on the Pi

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.


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.

  mc.postToChat("About to create pyramid!")

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

  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"

  # Create solid Pyramid
  print "Create Pyramid"
  for y in range(posy,posy+height):
    halfsize = halfsize-1

  # Change top block
  print "Set top block"

  print "Position player on top"

The CreatePyramid function takes some arguments. These are :

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

The full example script can be downloaded directly to your Pi using :


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 :


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

Minecraft Pyramids on the Pi

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!

Minecraft Pyramids on the Pi

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.

Minecraft Pyramids on the Pi

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.

Minecraft Pyramids on the Pi
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?


Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.