Introduction

There’s plenty of lava in the minecraft world if you dig deep enough, but hardly any on the surface! Let’s change that by building our very own volcano!

The Challenge

Your challenge, should you choose to accept it, is to build an erupting volcano in the minecraft world… Start nice and simple by building a pyramid shape and then add a sprinkling of random gravel to make it look realistic. Once you are done, get the lava flowing.

Step1. Create the base

volcanopic1

The first thing you need to do is to create the base of the pyramid. See if you can fill in the ?’s to build the base.

x = 0
y = 1
z = 0
mc.setBlocks(x,y,z,x+?,?,?,block.STONE)

Step2. (easy version)

Build the rest of the volcano

The easy way to add the rest of the volcano is to just copy the code that you used above on to the next line and keep adding lines of code until you have a full volcano. Have a go and see if you can build the rest of the volcano!

Step 2.  (hard version)

The easy version is okay for small volcanoes, but what about a really big volcano? Things soon start getting out of hard so really we want to use a loop instead! See if you can complete this while loop to build your volcano.

layer = 1
While layer < 5::
	startx, = x + layer
	endx =  x + ?? -  layer # what number goes here?
	y = layer
	startz = startx 
	endz = ??? # What variable name goes here?
	mc.setBlocks(startx, y, startz, endx, y, endz, block.STONE)
	layer += ??#what number goes here?

Step 3. Add random blocks of gravel

Your volcano is  probably looking more like a pyramid at the moment so we want to sprinkle some random blocks of gravel on top. See if you can convert the pseudo code below to get your code working!

Import the random moduleLoop 100 times:

x =  random number  between the startx and endx of the base.

Z =  random number between the startz and endz of the base

Drop a gravel block at z, 50, z

 

 

Never used the random function before? Don’t worry, it’s easy! Try the code below. The only thing to be aware of is that the code below will generate a random number between 0-9, not 0-10!!!

import random
number = random.randint(0,10) 
print(number)

Step 4. Make your volcano erupt!

Okay, this last bit is easy! Just add a loop that puts a block of lava at the top of your volcano once every second!

Extensions

  • Make a volcano that only erupts every so often…
  • Make a volcano only out of randomly placed blocks with the pyramid

Complete Code

import minecraft as minecraft, block,time,random
mc = minecraft.Minecraft.create()

layers = 10 # How high our volcano is going to be
vec = (0,0,0) # the starting point for our volcano
mc.setBlocks(0,0,0,100,100,100,block.AIR) # let's make some space for our volcano

for layer in range(0,layers): # Build the volcano
	mc.setBlocks(layer + vec[0],layer + vec[1],layer + vec[2],vec[0] + (2*layers)-layer,vec[1] + layer,vec[2] + (2*layers)-layer,block.STONE)
	time.sleep(1)

count = 0
while count < (layers*layers*3): # Add some random blocks on the top to make it look a bit more real
	x = random.randint(vec[0],vec[0]+(2*layers)+1)
	z = random.randint(vec[2],vec[2]+(2*layers)+1)
	mc.setBlock(x,layers+10,z,block.GRAVEL)
	time.sleep(0.01)
	count+=1

while True: # Get the lava flowing!
	mc.setBlocks(vec[0]+int(layers)-1,vec[1]+layers,layers-1,vec[0]+int(layers),vec[1]+layers,layers+1,block.LAVA_FLOWING) # This is not a new line! 
	time.sleep(1)

 

 

Recommended reading