Minecraft: PI – Create Blocks

Devin picked up “Learn to Program with Minecraft” at the Pacific Science Center in Seattle.

After the first 3 chapters, Devin has the player teleporting and spawning a grid of melons.

# Import the minecraft library and refer with an easy alias
import mcpi.minecraft as minecraft

# connect to the minecraft client
mc = minecraft.Minecraft.create()

# example of using variables
x = 0
y = 0
z = 0
width = 3
height = 3
length = 3

# use the minecraft variable to interact with the player and set the position of the player
mc.player.setTilePos(x, y + 2 * height, z)

# assign the mellon to the blockType variable
blockType = 103

# set a specific type of block at a single location
#mc.setBlock(x, y, z, blockType)

# set a range of tiles
mc.setBlocks(x, y, z, x + width - 1, y + height - 1, z + length - 1, blockType)

# post to the minecraft chat window
msg = "melons boom!!!!!!!!!!!!!!!"
mc.postToChat(msg)