Welcome to Programming Adventures in Minecraft

Programming software is fun and what better way to learn than to do things in Minecraft! Here are some things you can do with Minecraft programming

  • Send a chat message to Alex Programmers call this "Hello World"
  • Teleport Steve to a secret location
  • ...

In [18]:
import sys
#sys.path.append('/Users/esumitra/workspaces/mc/mcpipy')

Send a chat message

Lets write our first program to send a message to the Player

Start up minecraft and type the following in a new cell

import mcpi.minecraft as minecraft
import time
mc = minecraft.Minecraft.create()
mc.postToChat("Hello kids")
time.sleep(5)

In [20]:
# Start typing below
# once you are done typing, press (Ctrl+Enter) to run the code
import mcpi.minecraft as minecraft
import time
mc = minecraft.Minecraft.create()
mc.postToChat("Hello kids")
time.sleep(5)

If everthing went well, you saw a chat message in Minecraft. You have now written your first program for Minecraft. Jump up and down three times yelling

I rock!

Now let's see what the lines in your program do.

  • In order to work with minecraft we need other programs that help us connect to our minecraft game. These programs are called libraries. We need the minecraft and time libraries, so we tell our program that we need these libraries by typing
    import mcpi.minecraft as minecraft
    import time

There are many other libraries we can use in minecraft, some interesting ones being mcpi.blocks which has programs to build with blocks and mcpi.entity which has a list of things like bats, witherskull that you can use in your programs.

A library has many functions to do things. There is a function to display a message, a function to play music files and so on.

  • We need a minecraft object to connect to our game so we create minecraft object by typing
    mc = minecraft.Minecraft.create()

The minecraft object has many functions. When a function is tied to an object is is also called a method. We need the postToChat to display a message, so we type mc.postToChat(...).

Now try to complete the tasks below in this adventure.

Good luck!

Task 1

Write a program to display Hi Brooks School in Minecraft


In [ ]:
# Program for Adventure 1 - Task 1

Task 2

Write a program to display a countdown from 5,4,3,2,1

Hint: use time.sleep(1) to pause for 1 second between displaying numbers


In [22]:
# Program for Adventure 1 - Task 2