Thursday, July 28, 2016

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...




  

2 Comments:

At 4:41 AM, Blogger Sri akshaya said...


This content creates a new hope and inspiration with in me. Thanks for sharing article like this. The way you have stated everything above is quite awesome. Keep blogging like this.
Content marketing services in chennai

 
At 4:55 AM, Blogger Suseela Susiee said...



That is very interesting; you are a very skilled blogger. I have shared your website in my social networks..!


Online Reputation Management

 

Post a Comment

<< Home