diff --git a/examples/build some walls.ipynb b/examples/build some walls.ipynb new file mode 100644 index 0000000..58dd1c5 --- /dev/null +++ b/examples/build some walls.ipynb @@ -0,0 +1,262 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:a1094e48e4df4bb77e52eeeb2d3bbe9867d229129d9939665deaa66b4fc9e2b6" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Change the Minecraft world using Python" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "The Pyramid" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This program links Python to Minecraft and uses that link to change things in the Minecraft world. In the game, move your player to an open area, then work your way through the blocks of code below." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "First, we need to bring in some libraries of code that actually do the linking. Python does this with the `import` command." + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import mcpi.minecraft as minecraft\n", + "import mcpi.block as block\n", + "from time import sleep" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 51 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Connect to the Minecraft server, store the connection in a variable named `world`:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "world = minecraft.Minecraft.create()" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 52 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next, set some variables to customize the pyramid. You might come back here later to change these values to build bigger pyramids, smaller pyramids, or ones made out of different stuff." + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "height = 45\n", + "length=82\n", + "material = block.COBBLESTONE" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 53 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Find out where the player is in the world. Store the current position in variables named `x`, `y`, and `z`:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "[play_x, play_y,play_z] = world.player.getPos()\n", + "[play_x, play_y, play_z]\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 54, + "text": [ + "[277.87700842393065, 0.0, 382.2357187923274]" + ] + } + ], + "prompt_number": 54 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, get busy building the pyramid." + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Wall 1\n", + "level = 1\n", + "\n", + "x=0\n", + "y=0\n", + "z=0\n", + "for x in range(0, length):\n", + " # print x+play_x\n", + " for y in range(0, height):\n", + " # print y+play_y\n", + " world.setBlock(x+play_x,y+play_y,play_z, block.COBBLESTONE)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 55 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# This variable will track the current level being created inside the loop\n", + "# Wall 2\n", + "level = 1\n", + "\n", + "x=0\n", + "y=0\n", + "z=0\n", + "for z in range(0, length):\n", + " # print x+play_x\n", + " for y in range(0, height):\n", + " # print y+play_y\n", + " world.setBlock(play_x,y+play_y,z+play_z, block.COBBLESTONE)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 56 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# This variable will track the current level being created inside the loop\n", + "# Wall 3\n", + "level = 1\n", + "\n", + "x=0\n", + "y=0\n", + "z=0\n", + "for z in range(0, length):\n", + " # print x+play_x\n", + " for y in range(0, height):\n", + " # print y+play_y\n", + " world.setBlock(play_x+length,y+play_y,z+play_z, block.COBBLESTONE)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 57 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Wall 4\n", + "level = 1\n", + "\n", + "x=0\n", + "y=0\n", + "z=0\n", + "for x in range(0, length):\n", + " # print x+play_x\n", + " for y in range(0, height):\n", + " # print y+play_y\n", + " world.setBlock(x+play_x,y+play_y,play_z+length, block.COBBLESTONE)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 58 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finally, move the player to best seat in the house:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Put the player on top of the pyramid!\n", + "#world.player.setPos( x, y + height, z )\n", + "#world.postToChat(\"Done building pyramid!\")" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 59 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you built a pyramid from TNT, now might be a good time to equip yourself with a flint and steel to make sparks fly!" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Advanced Exercises and Questions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. What would you change to build a pyramid out of glass?\n", + "1. How would you make a taller or shorter pyramid?\n", + "1. Can you build a pyramid upside down? With the narrow end at the bottom and the wide end on top?\n", + "1. Can you fill a pyramid with air? *Hint: Maybe this is a two step process...*" + ] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file