Minecraft Pi_ Introduction to Python

Our previous variables for the position of the player involved a bit of typing but Python has a method called unbundling that allows us to create three variables at once which will create a lot less typing. Let's start a new Python file and begin again with:

from mcpi.minecraft import  Minecraft  mc  =  Minecraft.create() Let's use the unbundling method to create three variables by typing: x, y, z = mc.player.getPos()

Finally, let's create a block nearby using the mc.setBlock() function and our new variables: mc.setBlock(x + 1, y, z, 1)

Save as block and run the program. If you look around your character there should be a stone block nearby.

Return to top