TeachCraft Lessons


Individual Preparation

  • Complete the steps lists on "Get Started for Individuals" or "Get Started for Educators". After completing, you will have access to a TeachCraft Minecraft Server, have Minecraft v1.8.8 installed, and have a coding environment setup with TeachCraft-Examples downloaded.
  • Open Minecraft, and go to Multiplayer, then Direct Connect, then type in your server's IP address and hit connect.

Server Preparation (Only needs to be done once, skip if using demo server)

  • Now swap to your coding environment. Open up the file lesson1_setup.py from TeachCraft-Examples, and replace "" with your server IP, and "steve" with your character name. Save, then execute this file (on Cloud9 hit run, or locally in your terminal run python lesson1_setup.py).
  • After running the file above, you will see output that tells you to run a command on your server that starts with "setworldspawn" followed by three numbers. Copy/paste that command into your server console (use TeachCraft RCON console if TeachCraft server. Skip this step if using TeachCraft demo server).
  • Now in your server console, run kill @p to reset everyone's inventories and put them back in the spawn point, ready for lesson 1. (Skip if demo server)

TeachCraft Lesson 1

Variables, teleporting and the coordinate system

Welcome to Minecraft, and Python Programming! To start things off... it appears we find ourselves in a bit of a pickle.

We're stuck in a bedrock prison! We can see the world beyond us, but it's just out of reach. In our inventory, we find a sword, a bow, and an arrow... useful tools, but they can't help us out of this trap!

Bedrock is an indestructible minecraft block, so we can't break our way out. We have no blocks in our inventory to build a stepping stone to get out either. The only way to get out of this trap is to use Python programming!

The minecraft coordinate system is a three integer vector, using parameters X, Y, and Z.

The Y axis controls the height (up and down), while the X and Z axis control the East/West and North/South directions.

Step 1: Find our position

The very first thing we want to do with Python is figure out what our X/Y/Z location is. To do that, we're going to use the code on the right.

The first two lines import the minecraft library, and connect to your world. You will need to replace the IP address with your world's IP address, and the name with your player name.

The next line, mc.player.getPos(), retrieves our position and stores it in the variable we named 'pos'. We then print the X, Y, and Z coordinates from this variable to our terminal.

Go ahead and copy/paste the code on the right into your script.py file (from the TeachCraft-Examples repository you downloaded). Fix the IP Address and username to your own, and then hit "Run" to execute it when you're ready (or run python script.py in your terminal).

Sample Code

from mcpi import minecraft
mc = minecraft.Minecraft.create(address="", name="steve")

pos = mc.player.getTilePos()
print("x", pos.x)
print("y", pos.y)
print("z", pos.z)

Output will be something like:

x -3
y 0
z -3

Step 2: Teleport ourselves

At this point, we have our position saved into a variable we named pos. We now want to make use of the function mc.player.setPos(x, y, z) to teleport ourselves to a new location! This function takes as input the x, y, and z coordinates we want to teleport to!

If we add the line mc.player.setPos(pos.x, pos.y, pos.z) to the end of our application, our character will teleport... to the same exact location we are already in. Indeed, we likely won't even notice a change.

Observe the code on the right. In it, we call mc.player.setPos(pos.x, pos.y+100, pos.z). The important change is the +100 we are passing to the y position. This changes our position to the same x coordinate, same z coordinate, and a y coordinate that is 100 blocks different that our current position. Copy/paste it into your script.py file, change the ip and username, and then run it and see what happens!

Sample Code

from mcpi import minecraft
mc = minecraft.Minecraft.create(address="", name="steve")

pos = mc.player.getTilePos()
mc.player.setPos(pos.x, pos.y+100, pos.z)

Your Challenge: Escape!

You may have noticed, you died! This is because you teleported 100 blocks into the air, then fell back down to the exact same spot you were before. And as it turns out, you can't fly - so you died, respawned, and find yourself still in the trap!

Your Challenge: Find out what tweaks you need to make to the code to teleport yourself out of the trap! Once you escape, you'll be able to say "Hello world" to the bright new world you escaped to explore...

© 2017 TeachCraft

Disclaimer: Teachcraft products and services are not an official Minecraft product or service, nor approved by or associated with Mojang.