Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Basic Minecraft Programming Examples...

In the last post we reviewed how to set up Python for Minecraft.  Once you have it up and running, jump right in and try these two simple scripts that not only demonstrate what Python-for-Minecraft programs look like, but are also both really useful when you're actually playing.


Example 1:  Teleport to your starting location (or any location)

As most Minecrcaft newbies and veterans alike can tell you, sometimes you just want to go back to your "home base" (wherever in your world that might be) without needing to hike all the way there or even needing to figure out where it is.  Wouldn't it be helpful to have an easy way to teleport there whenever you wanted?

As soon as you start a new game, click on "F3" to see lots of in-game details display on the screen.  Pay particular attention to the three "Block" numbers (or XYZ numbers).  Then try this...

from mcpi.minecraft import Minecraft
mc = Minecraft.create()

# Replace these numbers with your three starting "Block" numbers

x = 20
y = 80
z = 16

mc.player.setTilePos(x, y, z)


Example 2:  Instantly build a shelter

Most players have to spend their first day gathering materials to build a shelter before nightfall.  But you can try this instead whenever you want to instantly build yourself a cobblestone shelter right next to your present location.  You can even build it in the sky!

# Get player's location and Build a hollow cuboid

from mcpi.minecraft import Minecraft
mc = Minecraft.create()
pos = mc.player.getPos()

x = pos.x
y = pos.y
z = pos.z
width = 10
height = 5
length = 6
blockType = 4
air = 0

mc.setBlocks(x, y, z, x + width, y + height, z + length, blockType)
mc.setBlocks(x+1, y+1, z+1, x + width-1, y + height-1, z + length-1, air)

The result...






This post first appeared on The Nerfherder, By Rob Domanski, please read the originial post: here

Share the post

Basic Minecraft Programming Examples...

×

Subscribe to The Nerfherder, By Rob Domanski

Get updates delivered right to your inbox!

Thank you for your subscription

×