Lesson 17: Hot or Cold?

Find the hidden lever


After finding the hidden Python temple, we will use code to tell us the distance to the hidden lever and open the temple gate.


import mcpi.minecraft as minecraft
import mcpi.block as block
import time
import math


mc = minecraft.Minecraft.create()

startPos = mc.player.getPos()

status = "notFound"

while (status == "notFound"):
	
	playerPos = mc.player.getPos()
	distance = math.sqrt((playerPos.x - (startPos.x-8)) ** 2 + 
	(playerPos.z - (startPos.z-24)) ** 2 + 
	(playerPos.y - (startPos.y+13))**2)
	
	
	if distance < 3:
		mc.postToChat("Found it")
		status = "Found"
	elif distance < 12:
		mc.postToChat("You're on Fire " + str(int(distance)))
	elif distance < 25:
		mc.postToChat("Warm " + str(int(distance)))
	elif distance < 50:
		mc.postToChat("Cold " + str(int(distance)))
	elif distance < 100:
		mc.postToChat("Freezing " + str(int(distance)))
		
	time.sleep(.1)
	 
		
mc.postToChat("You found the block!")