In these instructions any coding or typing into the computer is written
like this #messages about the command will be like this
on a new line.
Spaces in between characters are important so
python buildMyHouse.py
is not the same as
python build My House.py
Capital letters are also important and should be used when appropriate. Keep an eye out for changes in Capital letters.
After typing a line of instruction hit Enter key and the instruction will run.
Run Minecraft
From December 2014 Minecraft was installed on the Raspbian operating system as standard. It can be started by using the Menu drop down list from the top left of the screen. These instructions reflect this change as the school Raspberry Pis have all been updated.
Now Minecraft should be running and can be played with as normal. Use the mouse to create a world (or move right by England football shirts pressing D to open an old one). It is in creative mode only and has a limited size like the original pocket edition. The Minecraft window can be moved around the screen by grabbing with the mouse the window just underneath the top of the visible window. Try and place the Minecraft window to the upper right leaving plenty of screen space available to use.
Press Tab to release the mouse so that it can be used on the Pi. Just click inside the game to go back into it.
Run an LXTerminal
Open an LXTerminal and organise the screen so that the game and this terminal can be seen. You will be using this terminal to talk to Minecraft. In this exercise the commands are not recorded so once the Pi is switched off all is forgotten.
We need to run Python so that commands will be understood. So in the LXTerminal type:
python
Now we can start to program into the game. The Python interpreter should be running now and the start of a new line will be like this
>>>
The LXTerminal is waiting for you to give an instruction using Python language.
Try something simple like:
2+2
Or how about:
print("Hello, world!")
For Minecraft we start by importing some Minecraft modules that contain some instructions for Python about the game. Type these in with Enter after each line. Watch out for the Capital letter.
from mcpi import minecraft
from mcpi import block
mc=minecraft.Minecraft.create()
The last line opens a means of communicating with the game calling it mc. The mc is a variable and you have called it mc but it could be called anything you like in practice. Steve would work just as well as mc, just as long as all the commands needing mc are replaced with Steve.
Test it!
Now things will start to happen. Keep an eye on the game as you press enter after each line.
mc.postToChat(“Hello, world!“)
You should now see a line of text appear on the Minecraft game. Try typing the same again but with your own message. A tip for you though. Instead of retyping every line again in the LXTerminal try using the up arrow on the keyboard. It will cycle through the lines you have previously written. These can be easily edited to make a new command.
To communicate with Minecraft the commands begin with mc. So to find the position of the block the player is standing on would need:
mc.player.getTilePos()
which will give something like this
vec3(5,6,7)
Finding the player position within the game is very useful when building something. By knowing where Steve is standing it is quite easy to start the build a short distance away from where ever he is. If you used any random coordinates to place some blocks down you may have to walk a way through the world to find them.
We find the getTilePos command more useful than getting the players position:
mc.player.getPos()
The coordinates are retrieved as a series of three numbers x, y and z. Where x and z are the block distance on the ground from AC Milan football shirts the centre of the game. The y coordinate is the height above, or below, the centre of the game. These all refer to a three dimensional graph in maths so it is good practice for you!
The spaces within the brackets here are not important but good Python practice. It makes it easier for you to read but note there are no spaces for the code outside the brackets.
To place a block of TNT (no. 46) at a position where x is 5, y is 12 and z is 6 would need:
mc.setBlock(5, 12, 6, 46)
or use by using the block name such as this in capitals:
mc.setBlock(5, 12, 6, block.GRASS.id)
To place a whole block of blocks at a position x,y,z would need:
mc.setBlocks(x, y, z, x2, y2, z2, blockID)
Here the program will place the first block and fill the space up to the second block. Notice the slightly different name setBlocks with an s. If that is only two blocks away then that will be just three blocks needed. Like the picture below. But if the second block was a hundred blocks away it will place those just as fast!
Minecraft Steve has placed three blocks x+5 blocks away Barcelona football shirts from him. If his coordinates are 0,0,0 then the coordinates of the yellow blocks(the z, y, z) could be 5,0,0 and the x2, y2, z2 are 5,0,2. The use of Lego as a way of understanding the positions of blocks is a useful aid.
Try to place a single block a few x blocks away from your Steve player. Get your Steve tile position using the command above. Add a say three to the x number and use the setBlock command to place a block of your choice there. Now try changing the z and then the y coordinates too. Change the block Manchester United football shirts ID as well for different blocks. And if you are feeling really clever build a block of blocks with stone and fill it inside with ones or air or maybe water. What happens if you go over and mine those blocks? And for those with a destructive way use the TNT with a one after it, like this:
mc.setblock(x, y, z, 46, 1)
The TNT can then be made to explode by hitting it. If you place a large block of blocks down you’ll probably really Real Madrid football shirts slow your game down. But of course you’d never do that, would you?!
Here is a block of wood planks 10 x 10 x 10 with a block of water placed inside 9 x 9 x 9. |
The block ID numbers are:
0 => “Air” | 1 => “Stone” | 2 => “Grass” |
3 => “Dirt” | 4 => “Cobblestone” | 5 => “WoodenPlank” |
6 => “Sapling” | 7 => “Bedrock” | 8 => “Water” |
9 => “StationaryWater” | 10 => “Lava” | 11 => “StationaryLava” |
12 => “Sand” | 13 => “Gravel” | 14 => “GoldOre” |
15 => “IronOre” | 16 => “CoalOre” | 17 => “Wood” |
18 => “Leaves” | 19 => “Sponge” | 20 => “Glass” |
21 => “LapisLazuliOre” | 22 => “LapisLazuliBlock” | 23 => “Dispenser” |
24 => “Sandstone” | 25 => “NoteBlock” | 26 => “Bed” |
27 => “PoweredRail” | 28 => “DetectorRail” | 29 => “StickyPiston” |
30 => “Cobweb” | 31 => “TallGrass” | 32 => “DeadShrub” |
35 => “Wool” | 37 => “YellowFlower” | 38 => “CyanFlower” |
39 => “BrownMushroom” | 40 => “RedMushroom” | 41 => “BlockofGold” |
42 => “BlockofIron” | 44 => “StoneSlab” | 45 => “Brick” |
46 => “TNT” | 47 => “Bookcase” | 48 => “MossStone” |
49 => “Obsidian” | 50 => “Torch” | 51 => “Fire” |
52 => “MobSpawner” | 53 => “WoodenStairs” | 56 => “DiamondOre” |
57 => “BlockofDiamond” | 58 => “Workbench” | 59 => “Wheat” |
60 => “Farmland” | 61 => “Furnace” | 62 => “Furnace” |
63 => “Sign” | 64 => “WoodDoor” | 65 => “Ladder” |
66 => “Rails” | 67 => “CobblestoneStairs” | 68 => “Sign” |
71 => “IronDoor” | 73 => “RedstoneOre” | 78 => “Snow” |
79 => “Ice” | 80 => “SnowBlock” | 81 => “Cactus” |
82 => “ClayBlock” | 83 => “SugarCane” | 85 => “Fence” |
87 => “Netherrack” | 88 => “SoulSand” | 89 => “Glowstone” |
96 => “Trapdoor” | 98 => “StoneBricks” | 99 => “BrownMushroom” |
100 => “RedMushroom” | 102 => “GlassPane” | 103 => “Melon” |
105 => “MelonVine” | 107 => “FenceGate” | 108 => “BrickStairs” |
109 => “StoneBrickStairs” | 112 => “NetherBrick” | 114 => “NetherBrickStairs” |
128 => “SandstoneStairs” | 155 => “BlockofQuartz” | 156 => “QuartzStairs” |
245 => “StoneCutter” | 246 => “GlowingObsidian” | 247 => “NetherReactorCore” |