th75FIB2E1

Python programming 4

on November 23 | in Technology | by | with No Comments

Programming Minecraft

Python is a very powerful programming langauge. In the last Python programming post, I showed you how to create a game. In this one, I can show you how to create programs for one of the most popular games ever: Minecraft. Now, there are two options for this. If you have a Raspberry Pi computer, you can simply open up a terminal window (menu > acsessories > LXTerminal) and type
‘sudo apt-get install minecraft-pi’.

If, however you have Minecraft but you do not have a Raspberry Pi, you can still do it. Visit https://github.com/martinohanlon/mcpi, and click Download Zip. When it asks you what you want to do with it, select Save. Go to your Downloads folder and click on the file called “mcpi-master.zip”. Left-click it and select the option to extract the folders. Copy it to the folder that you want to save your programs in. Go into it. This is where you will need to save all your Minecraft programs. Here is an example to post to the minecraft chat:

from mcpi import minecraft
mc = minecraft.Minecraft.create()
mc.postToChat(‘hello minecraft world’)

Now, just making messages is boring after a while. In fact, it’s very boring after a couple of minutes. Wouldn’t you like it if you could have a house built for you using code? What about a huge block of diamonds appearing in front of you in Survival? Imagine if nobody could destroy your world? It would be incredible if you could make 100 chickens appear in front of you, all ready to eat? Or if lava could not damage you? All these things and more are possible with python and Minecraft. As an example, we will make you have infinite TNT blocks with this code. Right-click a block and a TNT block will magicaly appear on top with this code, with indents appearing as ~ :

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

while True:
~~~~for hit in mc.events.pollBlockHits():
~~~~~~~~mc.setBlock(hit.pos.x,hit.pos.y,hit.pos.z, block.TNT.id, 1)

This is just one example. What you can make in minecraft in one day has just been multiplied by a lot!

Pin It

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

« »

Scroll to top