Lesson 10: Raining Sand

Sandstorm!


Using everything we have learned so far, we will create a program that makes it rain random blocks of sand from the sky! In this video we will learn about new imports,loops, counters, random numbers, and conditions!


#RAIN SAND
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
import random
mc = minecraft.Minecraft.create()
playerPos = mc.player.getPos()
counter = 0
while (True):
	# SET BLOCK COUNT
	blockCount = 5
	# POST MESSAGE
	mc.postToChat("Sand Storm!")
	# MAKE SURE THE NUMBER IS AN INTEGER
	blockCount = int(blockCount)
	#ADD TO COUNTER
	counter = counter + 1
	# RANDOMLY PLACE BLOCKS IN SKY
	while (blockCount > 1):
		blockCount = blockCount - 1
		x = random.randint(-5, 5)
		y = random.randint(10, 24)
		z = random.randint(3, 20)
		mc.setBlock(playerPos.x + x,playerPos.y + y,playerPos.z + z,12)
	if counter == 60:
		mc.postToChat("Times up!")
		break