The Raspberry PI version of Minecraft lets you script in Python, making fractal designs, drawings, turtle graphics, simple games, etc. The same thing can be done on a desktop version with my Raspberry Jam Mod (here is my Instructable on how to use it), as well as with a server-side mod. There is a great book by Whale and O'Hanlon on Python scripting for Minecraft, and O'Hanlon's site has a lot of information.

I now made a mod that lets you do all this with the Android Pocket Edition of Minecraft. The code runs more slowly than the desktop edition, but you can still draw knots, fractals, L-system based plants, have fun with turtle graphics, etc. Source code is here and an installer is on Google Play.

In this Instructable I will explain how to install my mod and get started with Python coding for Minecraft on Pocket Edition on a phone or tablet. (A Bluetooth keyboard is recommended, but not necessary.)

You will need an Android 2.3 or higher device (but devices from the 2.3 era may be too slow for the more complex scripts) a copy of Minecraft PE, and some free software.

Step 1: Prerequisites

Install the following apps, available on Google Play (they're also all up in the Amazon Appstore):

Step 2: Install Raspberry Jam Mod

  1. Run Raspberry Jam Mod.
  2. If it finds that the prerequisites are all installed, it will give you a big "Install!" button. Beside it, you can also choose what to do with existing QPython scripts.
  3. Tap on "Install".
  4. You will get BlockLauncher's script import screen. Tap on "Import".
  5. Turn your device to landscape (sometimes BlockLauncher may crash in portrait) and start BlockLauncher (I recommend from now on using BlockLauncher to start Minecraft).
  6. Tap on the wrench button (middle of top of screen).
  7. Tap on "Manage ModPE Scripts".
  8. Tap on "raspberryjampe.js" and then on "Enable".
  9. Press back, and everything is installed.

Step 3: Run a Sample Script in QPython

  1. Create a world in Minecraft (making sure you start Minecraft with BlockLauncher): I recommend a Creative world, with "Flat" in advanced options.
  2. Press your device's Home button and run QPython.
  3. Swipe the QPython main screen to the left.
  4. Tap on "Programs".
  5. Choose a script, I'll suppose "borromean.py".
  6. You can now choose "Open" to view it, and then the play button to run it, or "Run" to run it directly. Either way, you will get a text console screen when the script is running.
  7. Switch back to Minecraft (on my phone that's a long-tap on home, and on my tablet that's the multi-app button).
  8. The script will now be running. Look up to see what it's doing. You may need to back away to see better.

Step 4: Run a Sample Script From Inside Minecraft

You can also run a script right from within Minecraft (started within BlockLauncher). Just tap on the chat button in the upper right corner, and once you get the keyboard (you may need to tap on the keyboard icon), type

/py scriptname

and press next or enter. (Omit the ".py" extension.) This will launch the script inside QPython (you can press the back button several times to switch back to Minecraft to watch it run; make sure you allow the console to continue running in the background). The script must be found in your internal storage's com.hipipal.qpyplus/scripts folder. You can also include commandline arguments (e.g., to draw an icosahedron, do /py polyhedron 14 and to do a dodecahedron do /py polyhedron 14 faces).

In addition to the /py (or /python if you want to type more) command, my Raspberry Jam Mod PE includes commands:

/time set x

to set the time, and

/tp x y z

to teleport, where (x,y,z) are coordinates (with 0,0,0 being the spawn point). You can also do relative coordinates by using ~. E.g., /tp ~ ~10 ~ moves 10 blocks up. (And if ~ is hard to type on your keybaord, you can use any letter in its place!)

Step 5: Create a Simple Script

Make sure Minecraft is running (via BlockLauncher) with a world loaded.

In QPython's main screen, swipe to the right and choose "Editor". Press the big "+" button in the upper right corner and choose "Blank file".

To save yourself typing, tap on the Snippets icon (the second-last icon on the bottom line). Choose "Minecraft turtle".

You will get some boilerplate code.

Before the last postToChat line, type:

for i in range(5):

Then tap on the disk icon to save the script as sample.py, making sure to put it in the scripts folder. Then press the play button. When you switch to Minecraft, you should see a five-sided star made of gold bricks.

To learn how to make various more complicated scripts, see my big Python coding for Minecraft Instructable (one note: t.turtle(x) will only work for x=None or x=PLAYER). (Though beware that some of the scripts there may be too complex for a mobile device. For instance, the Menger sponge needs one less level.)

Step 6: Interactive Python Console

You can also run Python code interactively by launching the console.py or turtleconsole.py script (with QPython or via /py console or /py turtleconsole) and typing Python commands into chat, ending with 'quit'. The console.py script initializes an mc global variable which is an instance of Minecraft() and the turtleconsole.py script initializes t which is an instance of Turtle().

One trick: the chat doesn't let you enter an empty line, which in a Python interactive session is needed to get out of an indented block. To register an empty line, just enter a single space on a line.


<p>I posted a new version of the mod to Google Play. It works with the latest qpython (/py) as well as qpython3 (/p3).</p>
Help, I'm tails2007 and it tells me to disconnect from the server help<br>
What tells you this?
<p>I don't know if you can run javascript mods for Minecraft PE for iOS. Try googling. Probably requires a jailbreak. If you can, you can install raspberryjammod.js. There is also apparently a python interpreter for iOS. You'd have to run the scripts from within the interpreter: the /py command won't work.</p><p>But I know nothing about iOS, and don't have any iOS devices.</p>
<p>Wow... Amazing. Could you do it for iOS devices?</p>

About This Instructable




More by arpruss:Use 3D printer as a plotter/cutter Finger extensor exerciser 3D printable cookie cutters with Inkscape and OpenSCAD 
Add instructable to: