Python in Minecraft 1 – Placing a block

Linking to other servers

In your first script,, you created a link to the minecraft server on the local host using the command

mc = minecraft.Minecraft.create()

If you want to create a link to a minecraft server on another host, provide the IP address of the minecraft server to the create function.

mc = minecraft.Minecraft.create("")

Setting a block

This exercise will set a block at a position specified by (x,y,z) coordinates in the minceraft world. We will use the setBlock command to specify the position and type of the block. The setBlock command can be used as either




In the following example a wool block with colour orange (variation 1 for wool) is placed at x=-219, y=73, z=-222. This example uses the nano text editor which available on Mac and Linux and easier to use than vi. It has reminders at the bottom of the screen of the special key functions. To save type ctrl-o. To exit type ctrl-x.


import mcpi.minecraft as minecraft
import mcpi.block as block
mc.setBlock(-219,73,-222,, 1)

Run it while the server is running. The command will be


If you have python 2 and python 3 on the same computer (eg Mac or Linux) then the command is most likely


In minecraft, pressing F3 will let you see your coordinates so you can navigate (or teleport) to the coordinates to see the wool block you have placed.

Categories: CoderDojo