Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing up the danielbates demos to work with the latest version of MCPI #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 0 additions & 131 deletions classroom-code/examples/danielbates_minecraft_basic.ipynb

This file was deleted.

81 changes: 46 additions & 35 deletions classroom-code/examples/danielbates_setblockdemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down