Help with programming minecraft!


10 posts
by thejrcrafter » Mon Feb 11, 2013 9:32 pm
Could somebody please explain to me how to do these through an ssh tunnel (i am a complete python noob):

1. initialize the coding environment (what to import in the python console, how to connect to minecraft)
2. placing a block, placing larger figures like cubes
3. creating my own functions, like one to auto- create a cube of a specified size (do i need to make a separate script, or can i do it directly in the console?)
4. how to move the character
i think that's it. i really wish mojang would make a quick user's guide on how to do this.
thank you!
Posts: 28
Joined: Sun Dec 09, 2012 9:15 pm
by radcom123 » Mon Feb 11, 2013 9:54 pm
1. You need to be running minecraft pi on the pi its self before you start plenty of info there.
2. now open a command prompt and cd into the api directory which should be something like "/home/pi/mcpi/api/python/mcpi"
2. At the command prompt type "python" some text is displayed and your prompt becomes >>>
3. Now type "import minecraft as minecraft" and press enter
4. type "mc = Minecraft.create()" press enter
5. now type "mc.postToChat("Hello, Minecraft!")"
6. to place a block type "mc.setBlock(0,5,0,46)" then press enter in this exampe a tnt block is placed at hight 5 above the spawn(0,0,0) the command works like this (x,y,z,blockid,[data])

hope this gets you started
Last edited by radcom123 on Mon Feb 11, 2013 10:08 pm, edited 1 time in total.
Posts: 3
Joined: Thu Aug 30, 2012 1:04 am
by thejrcrafter » Mon Feb 11, 2013 10:03 pm
after step 4, i get the error:

Code: Select all
Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
NameError: name 'Minecraft' is not defined


i made sure that my case was all correct, i was in the correct directory, but for some reason it is not working. i have tried many times. please help!
i am usin python 2.7.3 rc2
Posts: 28
Joined: Sun Dec 09, 2012 9:15 pm
by thejrcrafter » Mon Feb 11, 2013 10:12 pm
Ok, I got it working. the reason it did not work was because i did not specify that the Minecraft class was in minecraft.py, so in order to actually define the 'mc' variable, i had to do:

Code: Select all
mc = minecraft.Minecraft.create()


but since i already imported minecraft.py, i thought i didnt have to specify that Minecraft was in minecraft.py? oh well.
and minecraft.py is the only thing i had t import, right? is there any reason i would need to import the other files in the api folder, or are they imported for me?
Posts: 28
Joined: Sun Dec 09, 2012 9:15 pm
by LetHopeItsSnowing » Tue Feb 12, 2013 8:20 am
Check out my blog post on how to get started with the minecraft API http://www.stuffaboutcode.com/2013/01/r ... asics.html, hopefully it will give you a starting point.

Ive also created a couple of projects like a game of hide and seek, http://www.stuffaboutcode.com/2013/01/raspberry-pi-minecraft-hide-and-seek.html and an auto bridge, http://www.stuffaboutcode.com/2013/02/raspberry-pi-minecraft-auto-bridge.html

Martin
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"
User avatar
Posts: 206
Joined: Sat May 26, 2012 6:40 am
Location: UK
by thejrcrafter » Wed Feb 13, 2013 1:48 am
okay, thanks. in theory, it should be possible to run multiple minecraft python 'services' at a time- say, one for the bridge, another for the clock program in the forums, one for general building use, etc?
and i could run all of these 'services' on a separate computer and connect to my pi's ip to cut down on the cpu load right?
Posts: 28
Joined: Sun Dec 09, 2012 9:15 pm
by LetHopeItsSnowing » Wed Feb 13, 2013 2:21 pm
Yes you can multiple services and yes you can run them from another computer. However I suspect the bottleneck will be the minecraft server running on the Pi itself, even though you have off-loaded the running of the scripts to do stuff in minecraft, the changes to the minecraft world will still be happening on the Pi.

Give it a stress test, see what performance you can get from it!
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"
User avatar
Posts: 206
Joined: Sat May 26, 2012 6:40 am
Location: UK
by thejrcrafter » Wed Feb 13, 2013 8:17 pm
wow, that was a big difference!
my "stress" test was this:

clear from (64,64,64) to (-64,-64,-64)
run 3 advanced digital clock instances (the post for that is in the forum)
time how long it takes to make a menger sponge with a depth of 3.

The menger sponge code (and a lot more) is in the first post in
raspberrypi.org/news/page/7
the actual commang i used was (the code is imported as form)
form.fillshape(form.mengersponge(3),form.shift(myPosition),block.STONE)

When on the raspberry pi through ssh, it took 1:07.68 to build the menger sponge.
When the programs ran on my laptop (minecraft was still on the pi), it took 12.91 seconds!

And this is with 3 samba shares and a CUPS server running in the background.
So running remotely rather than on the Pi and ssh'ing is actually about 5.5x faster.
Posts: 28
Joined: Sun Dec 09, 2012 9:15 pm
by OldRobot » Fri Feb 15, 2013 9:13 pm
I made a video showing how to do very basic pi programming at runtime

It poor quality but it may help some people?

http://www.youtube.com/watch?v=H7hzURJmV5Y
Posts: 1
Joined: Fri Feb 15, 2013 8:46 pm
by LetHopeItsSnowing » Fri Feb 15, 2013 9:40 pm
Im genuinely quite surprised.. I'll give it a go myself and let you know my results.
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"
User avatar
Posts: 206
Joined: Sat May 26, 2012 6:40 am
Location: UK