To build our pyramid we will use a simple model (not perfect but easy to code):
Simplistic model of pyramid
import mcpi.minecraft as minecraft
import mcpi.block as block
mc = minecraft . Minecraft ()
#Here we store the current position of the player
x , y , z = mc . player . getPos ()
#We don't want to spawn stuff on the player itself so we will take a position just near him
x = x + 1
z = z + 1
#We will use only one variable that will change the color, the size and height of the current surface
i = 0
#The size of our pyramid
size = 16
width = 16
while i < size :
#We need two coordinates for each level of the pyramid - Sand is 12
mc . setBlocks ( x + i , y + i , z + i , x + width * 2 - i , y + i , z + width * 2 - i , 12 )
i = i + 1
Here is what you should get:
pyramid of sand
Now we’ll create a pyramid of wool alternating colors.
import mcpi.minecraft as minecraft
import mcpi.block as block
mc = minecraft . Minecraft ()
#Here we store the current position of the player
x , y , z = mc . player . getPos ()
#We don't want to spawn stuff on the player itself so we will take a position just near him
x = x + 1
z = z + 1
#We will use only one variable that will change the color, the size and height of the current surface
i = 0
#There are 16 color of wool so this is the size we'll choose
size = 16
while i < size :
#We need two coordinates for the surface and we rotate the color of the wool (35)
mc . setBlocks ( x + i , y + i , z + i , x + size * 2 - i , y + i , z + size * 2 - i , 35 , i % 16 )
#This commented line would give you instead a cube
#mc.setBlocks(x+i,y+i,z+i,x+size,y+i,z+size,35,i%16)
i = i + 1
This should give you this:
16 colored stage pyramid of wool
We tried to make the same pyramid going in diagonal on x and z. It end up being not so easy.
To break down the algorythm, the idea is to create first a diagonal,
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
mc = minecraft . Minecraft ()
#Here we get the player position
x , y , z = mc . player . getPos ()
#We'll use reference near this position
x = x + 2
z = z + 2
#We will set the number of blocks we want in a variable
size = 8
#We will use a i to store the number we already built.
i = 0
while i < size :
mc . setBlock ( x + i , y , z + i , 24 )
i = i + 1
time . sleep ( 1 )
Pierced Pyramid in Diagonal - First line
then to have this diagonal repeated on the same level (this will give you a air/sandtone chess board in diagonal)
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
mc = minecraft . Minecraft ()
#Here we get the player position
x , y , z = mc . player . getPos ()
x = x + 2
z = z + 2
#We will set the number of blocks we want in a variable
size = 8
#We will use a j to store the number of diagonal we already built.
i = 0
while i < size :
j = 0
#We will use a j to store the number of block in the current diagonal we already built
while j < size :
mc . setBlock ( x + i - j , y , z + i + j , 24 )
time . sleep ( 0.1 )
j = j + 1
i = i + 1
Pierced Pyramid in Diagonal - Floor
then to loop of this at each level knowing we want it to be smaller .
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
mc = minecraft . Minecraft ()
#Here we get the player position
x , y , z = mc . player . getPos ()
x = x + 2
z = z + 2
#We will set the number of blocks we want in a variable
size = 8
#We will use a k for the size
k = 0
while k < size :
i = 0
#We will use i to repeat our diagonal
while i < size - k :
j = 0
#We will use j to loop over one of our diagonal
while j < size - k :
mc . setBlock ( x + i - j , y + k , z + i + j + k , 24 )
#We use a timer so we can see the pyramid drawing slowly
time . sleep ( 0.05 )
j = j + 1
i = i + 1
k = k + 1
This should give you this:
Pierced Pyramid in Diagonal