Python & Github

This training module is a two for one. We welcome you to learn both Python and Github by contributing to our Minecraft Burning Man project.

3.1 Learn about Github on YouTube if You Want

You can find tons of videos and full courses about GitHub by organizations such as Dev Inc., Code Course, and Udacity on YouTube if you're interested in background stories, history lessons, and want to know more than you really need to know at this point. If you do not mind one instance of fowl language, you can get the gist of Git from TheHappieCat. Do not use this at coding club meetings unless you have a mature audience. However, if you're just revved up and ready to go, you could also just skip this step and get going on GitHub and look up things as you work. Honestly, I did this 3rd route, but I looked up the videos and posted links in case anyone wants to watch them.

3.2 Get Started on Git Hub

3.2.1 Create Account
  1. Go to github.com/join
  2. Pick a username, password, and enter your email address
  3. Click "Create Account"
  4. Pick  the "Unlimited public repositories for free." plan.
  5. Click "Finish Setting Up"
  6. Optional: Download the desktop app at desktop.github.com
3.2.2 Fork It
  1. Go to github.com/coders4liberty/minecraft-burning-man
  2. If you want to work on the desktop app or on your favorite compiler or development environment, click the green "clone & download" button.
  3. Click the "fork" button in the upper right hand corner to make your own fork
  4. If you want to be extra creative, create your own branch by clicking the "branch" drop down menu type your branch name and click "Create branch: ..."
  5. Click "minecraft-burning-man.py" file.
  6. Start coding (See Python Section)

3.3 Git & Python on Codecademy

Seriously, we're playing Minecraft; you can skip these if you want and just jump into the Minecraft sections. However, it would not hurt to try them out. Git: codecademy.com/learn/learn-git Python: codecademy.com/learn/python

3.4.a Start Coding in Python with Minecraft Pi on Raspberry Pi

This is probably the easiest way to go. Most of what you need is included with the Raspbian OS image and even the Ubuntu MATE OS image. We recommend using the Raspian OS unless you're just in love with Ubuntu MATE. Another OS you may want to consider if you still want to use a drag and drop environment is Kano. You do not necessarily need to buy a Kano kit to use Kano. You can download the OS from developers.kano.me and use it on a Raspberry Pi. Simply follow the directions provided by the website you get the image from. While the resources that follow are intended for use with the Minecraft Pi, it may also be helpful on other versions as well.
3.4.a.0 Hack Minecraft on Kano
developers.kano.me If you would like to get started on Minecraft Pi using a drag and drop environment, try Hack Minecraft on Kano. To see the Python code, click Advanced and See Code. You can copy this code and upload it to Github for the project. However, you may need to change the import code to "import mcpi from mcpi" instead of "import minecraft from minecraft." You may also want to put Raspbian on a separate SD card to try out your code. I personally had difficulty running Minecraft Pi python scripts outside of the Hack Minecraft app on Kano.
3.4.a.1 Python Intro on Raspberry Pi
raspberrypi.org/learning/python-intro This is an introduction to Python that you can run in IDLE on the Raspberry Pi or any other Python compiler or development environment. If you do not have Linux, download the program at goo.gl/0ZDOdX
3.4.a.2  Minecraft Pi Walkthroughs
This is what I used when I first started coding on Minecraft. The API is super useful. Minecraft Pi: raspberrypi.org/learning/getting-started-with-minecraft-pi Stuff About Code: stuffaboutcode.com/p/minecraft.html API: stuffaboutcode.com/p/minecraft-api-reference.html (Super Useful)
3.4.a.3 Geek Gurl Diaries Hacking Minecraft
[youtube https://www.youtube.com/watch?v=videoseries?list=PLME-KWdxI8dfQ1mKqnED8eAxZIb82ju6H]

3.4.b Start Coding in Python with Minecraft on PC

3.4.b.1 Python in One Video
This video explains how to install and use Python. [youtube https://www.youtube.com/watch?v=N4mEzFDjqtA?list=PL5UzhsUHqNatSBU-mGYSMpb1ycbC9_ZYq]
3.4.b.2 Raspberry Juice
You can use the Raspberry Juice plugin to program on regular Minecraft. There are actually more commands available using Raspberry Juice. stuffaboutcode.com/2014/10/minecraft-raspberryjuice-and-canarymod.html
3.4.c. Code it and Forward it to Your Friend Who Has Minecraft
If you want to participate in the project but do not have Minecraft or a Raspberry Pi, you can write the program and share it with a friend who has Minecraft.  

3.5 Functions

To avoid building on top of another crafter's creation inadvertently, we recommend using  functions to build your creation. For example, you can create a function that you feed a set of coordinates. For example, you can make a tower using the following function:
## This function takes an (x,y,z) coordinate, a width, a length, and a height
## It creates a tower that starts at the coordinate (x,y,z) that is w wide
## l long and h high
def tower((x,y,z),(w,l,h)): 
  mc.postToChat("Tower")
##floor
  mc.setBlocks(x, y, z, x+w, y, z+l, block.STONE.id)
##ceiling
  mc.setBlocks(x,y+h-1, z,  x+w, y+h-1, z+l, block.STONE.id)
##walls lz
  mc.setBlocks(x+w, y+1, z,  x+w, y+h, z+l, block.STONE.id)

  mc.setBlocks(x,   y+1, z,  x,   y+h, z+l, block.STONE.id)
  ## adds flair
  for i in range(z, z+l, 2):
    mc.setBlock(x,   y+h+1, i, block.STONE.id)
    mc.setBlock(x+w, y+h+1, i, block.STONE.id)
##walls xw
  mc.setBlocks(x+w, y+1, z+l,  x,   y+h, z+l, block.STONE.id)
  mc.setBlocks(x,   y+1, z,    x+w, y+h, z,   block.STONE.id)
  ## adds flair
  for i in range(x, x+w, 2):
    mc.setBlock(i, y+h+1, z,   block.STONE.id)
    mc.setBlock(i, y+h+1, z+l, block.STONE.id)
You can call a function inside another function to make more complicated things. For example, this castle function calls the tower function to build a castle with four towers:
def castle((x, y, z), (w, l, h), (th, tw)):
 mc.postToChat("Castle!")
 ##inside castle
 tower((x, y, z),(w, l, h))
 ##outside castle
 tower((x - tw, y, z - tw), (w + tw + tw, l + tw + tw, h))
 ##towers
 tower((x - tw, y, z - tw), (tw, tw, th))
 tower((x + w, y, z + l), (tw, tw, th))
 tower((x - tw, y, z + l), (tw, tw, th))
 tower((x + w, y, z - tw), (tw, tw, th))
In the off chance that you built your creation in the same spot as someone else, we can move it to a different location without completely rewriting the code. If you use a function, we can just change the parameters of your function call. If you don't use a function, we would have to change each and every line of your code to move it. Hopefully, that won't happen. However, it is a good idea to get in the habit of writing functions. It makes your code more flexible, easier to alter, and adapt. And you can use the functions in other projects.

3.6 Pull Request on GitHub

When you are done programming your Minecraft Burning Man exhibit, issue a pull request on GitHub by clicking the "New pull request" button. We will review your creation and add it to our repository. Congratulations, you have completed the level 3 training!

3.7 Other Fun Stuff

Python is used in Sage Math. You can also brush up your skills on CodeCombat. If you want to use Python for developing Android Apps, iOS Apps and more, try Kivy. Onward to level 4!