diff --git a/classroom-code/examples/danielbates_minecraft_basic.ipynb b/classroom-code/examples/danielbates_minecraft_basic.ipynb deleted file mode 100644 index edf2215..0000000 --- a/classroom-code/examples/danielbates_minecraft_basic.ipynb +++ /dev/null @@ -1,131 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Don't execute this directory -- this is a support script for danielbates_setblockdemo.py\n", - "\n", - "import sys\n", - "\n", - "# Add some common locations where the main API might be. Feel free to add/change\n", - "# these to suit you.\n", - "sys.path.append(\"mcpi\")\n", - "sys.path.append(\"api/python/mcpi\")\n", - "sys.path.append(\"mcpi/api/python/mcpi\")\n", - "\n", - "# Attempt to import Mojang's API.\n", - "try:\n", - "\timport connection\n", - "\timport minecraft\n", - "except ImportError:\n", - "\tprint \"Unable to find Minecraft API. Please place minecraft_basic.py in the mcpi directory.\"\n", - "\texit()\n", - "\n", - "_server = None\n", - "_blockedit = None\n", - "_playeredit = None\n", - "\n", - "def connect(ip=\"127.0.0.1\", port=4711):\n", - "\tglobal _server, _blockedit, _playeredit\n", - "\t\n", - "\ttry:\n", - "\t\t_server = connection.Connection(ip, port)\n", - "\t\t_blockedit = minecraft.Minecraft(_server)\n", - "\t\t_playeredit = _blockedit.player\n", - "\texcept Exception:\n", - "\t\tprint \"Unable to connect to Minecraft server at {0}:{1}\".format(ip,port)\n", - "\t\treturn\n", - "\n", - "\tprint \"Connected to Minecraft server at {0}:{1}\".format(ip,port)\n", - "\n", - "def setblock(x,y,z,*typedata):\n", - "\t_blockedit.setBlock(x,y,z,typedata)\n", - "\n", - "def getblock(x,y,z):\n", - "\treturn _blockedit.getBlock(x,y,z)\n", - "\n", - "def moveplayer(x,y,z):\n", - "\t_playeredit.setPos(x,y,z)\n", - "\n", - "AIR = 0\n", - "STONE = 1\n", - "GRASS = 2\n", - "DIRT = 3\n", - "COBBLESTONE = 4\n", - "WOOD_PLANK = 5\n", - "SAPLING = 6\n", - "BEDROCK = 7\n", - "WATER_FLOWING = 8\n", - "WATER = 9\n", - "LAVA_FLOWING = 10\n", - "LAVA = 11\n", - "SAND = 12\n", - "GRAVEL = 13\n", - "GOLD_ORE = 14\n", - "IRON_ORE = 15\n", - "COAL_ORE = 16\n", - "WOOD = 17\n", - "LEAVES = 18\n", - "GLASS = 20\n", - "LAPIS_ORE = 21\n", - "LAPIS = 22\n", - "SANDSTONE = 24\n", - "BED = 26\n", - "COBWEB = 30\n", - "TALL_GRASS = 31\n", - "WOOL = 35\n", - "FLOWER_YELLOW = 37\n", - "FLOWER_RED = 38\n", - "MUSHROOM_BROWN = 39\n", - "MUSHROOM_RED = 40\n", - "GOLD = 41\n", - "IRON = 42\n", - "STONE_SLAB_DOUBLE = 43\n", - "STONE_SLAB = 44\n", - "BRICK = 45\n", - "TNT = 46\n", - "BOOKSHELF = 47\n", - "MOSSY_STONE = 48\n", - "TORCH = 50\n", - "FIRE = 51\n", - "WOOD_STAIRS = 53\n", - "CHEST = 54\n", - "DIAMOND_ORE = 56\n", - "DIAMOND = 57\n", - "CRAFTING_TABLE = 58\n", - "FARMLAND = 60\n", - "FURNACE = 61\n", - "FURNACE_ACTIVE = 62\n", - "WOOD_DOOR = 64\n", - "LADDER = 65\n", - "COBBLESTONE_STAIRS = 67\n", - "IRON_DOOR = 71\n", - "REDSTONE_ORE = 73\n", - "SNOW_COVER = 78\n", - "ICE = 79\n", - "SNOW = 80\n", - "CACTUS = 81\n", - "CLAY = 82\n", - "SUGAR_CANE = 83\n", - "FENCE = 85\n", - "GLOWSTONE = 89\n", - "INVISIBLE_BEDROCK = 95\n", - "STONE_BRICK = 98\n", - "GLASS_PANE = 102\n", - "MELON = 103\n", - "FENCE_GATE = 107\n", - "GLOWING_OBSIDIAN = 246\n", - "NETHER_REACTOR_CORE = 247\n", - "UPDATE_GAME_BLOCK = 249" - ] - } - ], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/classroom-code/examples/danielbates_setblockdemo.ipynb b/classroom-code/examples/danielbates_setblockdemo.ipynb index f96fd23..47bd092 100644 --- a/classroom-code/examples/danielbates_setblockdemo.ipynb +++ b/classroom-code/examples/danielbates_setblockdemo.ipynb @@ -17,7 +17,6 @@ "#import danielbates_minecraft_basic as mc\n", "#import pygame.image # comment this out if not using images - it's slow to import. If you uncomment, uncomment the image reference below.\n", "import random\n", - "import server\n", "\n", "# TODO: use numpy matrices/vectors instead of my own ones.\n", "class coordinate3d:\n", @@ -296,7 +295,7 @@ " goody = (point.y%5 == 1) or (point.y%5 == 2)\n", " goodz = (point.z%5 == 1) or (point.z%5 == 2)\n", " if (goodx and goody) or (goodz and goody):\n", - " return mc.GLASS\n", + " return block.GLASS\n", " else:\n", " return wallmaterial\n", " return f\n", @@ -326,13 +325,13 @@ " # Just a quick hack for now - could of course add more colours\n", " # and a way of finding the nearest supported colour.\n", " if (r,g,b) == (255,255,255): # white\n", - " return mc.AIR\n", + " return block.AIR\n", " elif (r,g,b) == (0,0,0): # black\n", - " return mc.OBSIDIAN\n", + " return block.OBSIDIAN\n", " elif (r,g,b) == (188,17,66): # pink\n", - " return mc.REDSTONE_ORE\n", + " return block.REDSTONE_ORE\n", " elif (r,g,b) == (117,169,40): # green\n", - " return mc.MELON\n", + " return block.MELON\n", " else:\n", " return None\n", "\n", @@ -383,69 +382,81 @@ " transform is of type transformation - multiple transformations can be combined\n", "by multiplying them together.\n", " material or fillfunc specify which material(s) to build the shape out of.\"\"\"\n", + " global world\n", " if fillfunc == None:\n", " fillfunc = solid(material)\n", " for point in shape:\n", " point2 = transform * point\n", - " mc.setblock(int(point2.x), int(point2.y), int(point2.z), fillfunc(point))\n", + " world.setBlock(int(point2.x), int(point2.y), int(point2.z), fillfunc(point))\n", "\n", "def clear(shape, transform=identity()):\n", " \"\"\"Remove any non-air blocks in the given shape.\"\"\"\n", - " fillshape(shape,transform,mc.AIR)\n", + " fillshape(shape,transform,block.AIR)\n", "\n", "def main():\n", " \"\"\"Function used to build my demo world. Extra clearing may be required for\n", "hilly worlds.\"\"\"\n", - " mc.connect(server.address)\n", + " global world\n", + " world = mc.Minecraft.create()\n", " \n", " # Create a large empty space with a neat, grassy floor. Takes a long time!\n", + " print \"Clear large empty space.\"\n", " clear(cuboid(100,10,120))\n", - " fillshape(floor(100,120), shift(0,-1,0), material=mc.GRASS)\n", + " fillshape(floor(100,120), shift(0,-1,0), material=block.GRASS)\n", "\n", " # Introduce basic shapes/transformations/fill functions.\n", - " fillshape(arrow, material=mc.STONE)\n", - " fillshape(arrow, shift(6,0,0), mc.STONE)\n", - " fillshape(arrow, shift(12,0,0)*rotationx(90), mc.STONE)\n", - " fillshape(arrow, shift(18,0,0)*rotationx(45), mc.STONE)\n", - " fillshape(arrow, shift(24,0,0), fillfunc=chequers(mc.WOOD, mc.STONE))\n", + " print \"Demo basic shapes, transformations and fill functions.\"\n", + " fillshape(arrow, material=block.STONE)\n", + " fillshape(arrow, shift(6,0,0), block.STONE)\n", + " fillshape(arrow, shift(12,0,0)*rotationx(90), block.STONE)\n", + " fillshape(arrow, shift(18,0,0)*rotationx(45), block.STONE)\n", + " fillshape(arrow, shift(24,0,0), fillfunc=chequers(block.WOOD, block.STONE))\n", "\n", " # Introduce generator functions.\n", - " fillshape(cuboid(4,4,4), shift(30,0,0), mc.STONE)\n", - " fillshape(cuboid(3,8,2), shift(36,0,0), mc.STONE)\n", + " print \"Demo generator functions.\"\n", + " fillshape(cuboid(4,4,4), shift(30,0,0), block.STONE)\n", + " fillshape(cuboid(3,8,2), shift(36,0,0), block.STONE)\n", "\n", " # Show other simple shapes.\n", - " fillshape(sphere(5), shift(45,5,0), mc.STONE)\n", - " fillshape(pyramid(5), shift(50,0,0), mc.STONE)\n", - " fillshape(cylinder(5,4), shift(65,0,0), mc.STONE)\n", - " fillshape(cone(5,5), shift(75,0,0), mc.STONE)\n", + " print \"Demo some shapes.\"\n", + " fillshape(sphere(5), shift(45,5,0), block.STONE)\n", + " fillshape(pyramid(5), shift(50,0,0), block.STONE)\n", + " fillshape(cylinder(5,4), shift(65,0,0), block.STONE)\n", + " fillshape(cone(5,5), shift(75,0,0), block.STONE)\n", " \n", " # Show some fill functions.\n", - " fillshape(cuboid(4,4,4), shift(80,0,5), fillfunc=chequers(mc.GOLD, mc.IRON))\n", - " fillshape(pyramid(5), shift(80,0,10), fillfunc=randomfill([mc.SAND, mc.SANDSTONE]))\n", - " fillshape(hollowcuboid(4,6,4), shift(80,0,22), mc.WOOD_PLANK)\n", - " fillshape(building(2,6,2), shift(80,0,30), fillfunc=officeblock(mc.COBBLESTONE))\n", + " print \"Demo some fill functions.\"\n", + " fillshape(cuboid(4,4,4), shift(80,0,5), fillfunc=chequers(block.GOLD_BLOCK, block.IRON_BLOCK))\n", + " fillshape(pyramid(5), shift(80,0,10), fillfunc=randomfill([block.SAND, block.SANDSTONE]))\n", + " fillshape(hollowcuboid(4,6,4), shift(80,0,22), block.WOOD_PLANKS)\n", + " fillshape(building(2,6,2), shift(80,0,30), fillfunc=officeblock(block.COBBLESTONE))\n", "\n", " # Line drawing.\n", - " fillshape(line(80,0,40,85,5,45), material=mc.WOOL)\n", - " fillshape(line(80,0,40,80,2,50), material=mc.WOOL)\n", - " fillshape(line(80,2,50,85,5,45), material=mc.WOOL)\n", + " print \"Drawing with lines.\"\n", + " fillshape(line(80,0,40,85,5,45), material=block.WOOL)\n", + " fillshape(line(80,0,40,80,2,50), material=block.WOOL)\n", + " fillshape(line(80,2,50,85,5,45), material=block.WOOL)\n", " \n", " # Fun lava sphere.\n", - " fillshape(sphere(10), shift(80,10,60), mc.GLASS)\n", - " fillshape(sphere(9), shift(80,10,60), mc.LAVA)\n", + " print \"Creating Lava Sphere encased in glass.\"\n", + " fillshape(sphere(10), shift(80,10,60), block.GLASS)\n", + " fillshape(sphere(9), shift(80,10,60), block.LAVA)\n", "\n", " # Fractals - far easier to code than to build by hand.\n", - " fillshape(mengersponge(0), shift(70,0,75), mc.IRON)\n", - " fillshape(mengersponge(1), shift(66,0,75), mc.IRON)\n", - " fillshape(mengersponge(2), shift(56,0,75), mc.IRON)\n", - " fillshape(mengersponge(3), shift(28,0,75), mc.IRON)\n", + " print \"Fun with Fractals. Easier to code than build by hand.\"\n", + " fillshape(mengersponge(0), shift(70,0,75), block.IRON_BLOCK)\n", + " fillshape(mengersponge(1), shift(66,0,75), block.IRON_BLOCK)\n", + " fillshape(mengersponge(2), shift(56,0,75), block.IRON_BLOCK)\n", + " fillshape(mengersponge(3), shift(28,0,75), block.IRON_BLOCK)\n", "\n", " # Maze.\n", - " fillshape(maze(25,25), shift(0,0,75), mc.STONE)\n", + " print \"Making Maze.\"\n", + " fillshape(maze(25,25), shift(0,0,75), block.STONE)\n", "\n", " # Picture - can use the same technique to draw text.\n", "# fillshape(cuboid(24,30,1), shift(0,0,30), fillfunc=image(\"pi.png\",24,30))\n", "\n", + " print \"Demos Finished! Check out how they were made to improve your coding skills.\"\n", "\n", "\n", "if __name__ == \"__main__\":\n",