Skip to content

Commit b9106a0

Browse files
committed
Update MINECRAFT_PROGRAMMING.md
1 parent fc7da67 commit b9106a0

File tree

1 file changed

+79
-92
lines changed

1 file changed

+79
-92
lines changed

MINECRAFT_PROGRAMMING.md

Lines changed: 79 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,91 @@
11
# Minecraft Programming
22

3-
Resources
4-
=========
3+
## Resources
54

65
* Introduction to the Minecraft Python API: http://www.stuffaboutcode.com/2013/04/minecraft-pi-edition-api-tutorial.html
76
* API reference: http://www.stuffaboutcode.com/p/minecraft-api-reference.html
87

8+
## Optional: The Fence
9+
10+
*Objective:* Use if conditions to detect on what side of a fence one is. Reinforcement of coordinates from Intro.
11+
12+
File -> New -> Save: simple_fence.py
13+
14+
* Go to a flat area.
15+
* Build a small fence (as shown on the screenshot) along the *x* axis, that is *z* should not change along the wall.
16+
* Step on the fence, and walk along it, to determine its orientation. *y* will not change.
17+
* Once you know what coordinate you built it along, you're ready to write the code.
18+
19+
```python
20+
import mcpi.minecraft as minecraft
21+
import time
22+
mc = minecraft.Minecraft.create()
23+
24+
while True:
25+
time.sleep(1)
26+
pos = mc.player.getTilePos()
27+
if pos.z < z: # what's the fence z coordinate?
28+
print("North of the fence.")
29+
elif pos.z > z: # what's the fence z coordinate?
30+
print("South of the fence.")
31+
else:
32+
print("On the fence.")
33+
```
34+
35+
:bulb: Do you want to print to the Shell or to Minecraft chat?
36+
37+
![fence](https://raw.githubusercontent.com/gritcoding/minecraft/master/screenshots/fence.png)
38+
39+
40+
## Optional: The Cross
41+
42+
*Objective:* Use embedded if conditions and creative string concatenation
43+
44+
* Enhance your fence to look like a cross, like in the screenshot
45+
* Figure out where the midpoint is, that is the *x* and *z* coordinates.
46+
* You're ready to write the code.
47+
48+
File -> New -> Save: cross.py
49+
50+
```python
51+
import mcpi.minecraft as minecraft
52+
import time
53+
mc = minecraft.Minecraft.create()
54+
55+
while True:
56+
time.sleep(1)
57+
pos = mc.player.getTilePos()
58+
if pos.z operator z: # use the required operator
59+
north_south = "North"
60+
if pos.x operator x: # use the required operator
61+
print(north_south + " West")
62+
else:
63+
print(north_south + " East")
64+
elif pos.z operator z: # use the required operator
65+
north_south = "South"
66+
if pos.x operator x: # use the required operator
67+
print(north_south + " West")
68+
else:
69+
print(north_south + " East")
70+
else:
71+
print() # where am I now?
72+
```
73+
74+
* Explain string concatenation again.
75+
* Explain greater or equal versus greater.
76+
77+
![cross](https://raw.githubusercontent.com/gritcoding/minecraft/master/screenshots/cross.png)
78+
979

1080
## Anarkali
1181

12-
Anarkali (Pomegranate Blossom) lived in 17th Century India. She feel in love with the Prince and the King built a wall around her to keep her and the Prince apart.
82+
Anarkali (Pomegranate Blossom) lived in 17th Century India. She fell in love with the Prince and the King built a wall around her to keep her and the Prince apart.
1383

1484
*Objective:* Build four walls around your player when she steps onto the trap (and eventually help her escape).
1585

1686
![Anarkali](screenshots/anarkali.png)
1787

18-
Before you start, you might want to sketch it out with pencil and paper. What range of coordinates will your walls cover?
88+
:bulb: Before you start, you might want to sketch it out with pencil and paper. What range of coordinates will your walls cover?
1989

2090
File -> New -> Save: anarkali.py
2191

@@ -40,6 +110,8 @@ while True:
40110
break # end whlile loop (so we don't keep rebuilding the walls)
41111
```
42112

113+
:bulb: While you experiment, you may need to keep changing your trap position to build a new structure in a different place.
114+
43115
Make sure your walls are high enough to Anarkali can't jump out!
44116

45117
:bulb: There are faster ways to build structures. Rather than looping and setting a single block at a time, we can set a range of blocks together:
@@ -64,104 +136,19 @@ You can set player position to help Anarkali escape. Use 'time' to wait (3 secon
64136
mc.player.setPos(x+10, y+10, z+10) # move player to a new position, and watch her fall to earth
65137
```
66138

139+
:trophy: Challenge: What if Anarkali was born in Eygpt not India? Would the king build a tower, or... a Pyramid!
67140

68-
The fence, if conditions
69-
------------------------
70-
*Objective:* introduce if conditions by detecting on what side of a fence one is
71-
72-
* Go to a flat area
73-
* Build a small fence as shown on the screenshot
74-
* Step on the fence, and walk along it, to determine its orientation. It will be either *x* or *z*.
75-
* Once you know what coordinate you built it along, you're ready to write the code
76-
```python
77-
import mcpi.minecraft as minecraft
78-
import time
79-
mc = minecraft.Minecraft.create()
80-
81-
while True:
82-
time.sleep(1)
83-
pos = mc.player.getTilePos()
84-
if pos.x > -119:
85-
print("north of the fence")
86-
elif pos.x < -119:
87-
print("south of the fence")
88-
else:
89-
print("on the fence")
90-
```
91-
92-
![fence](https://raw.githubusercontent.com/gritcoding/minecraft/master/screenshots/fence.png)
93-
94-
The cross, two if conditions
95-
----------------------------
96-
*Objective:* introduce embedded if conditions and creative string concatenation
97-
98-
* Enhance your fence to look like a cross, like in the screenshot
99-
* Figure out where the midpoint is. If previously you built around the *z* coordinate, then this time your other coordinate is *x* and vice versa.
100-
* You're ready to write the code.
101-
102-
```python
103-
import mcpi.minecraft as minecraft
104-
import time
105-
mc = minecraft.Minecraft.create()
106-
107-
while True:
108-
time.sleep(1)
109-
pos = mc.player.getTilePos()
110-
if pos.x > -119:
111-
north_south = "north"
112-
if pos.z > 43:
113-
print(north_south + "/west")
114-
else:
115-
print(north_south + "/east")
116-
elif pos.x < -119:
117-
north_south = "south"
118-
if pos.z > 43:
119-
print(north_south + "/west")
120-
else:
121-
print(north_south + "/east")
122-
```
123-
124-
* Explain string concatenation again
125-
* Explain greater or equal versus greater
126-
127-
![cross](https://raw.githubusercontent.com/gritcoding/minecraft/master/screenshots/cross.png)
128-
129-
The tower
130-
---------
131-
*Objective:* introduce programmatic placement of blocks
132-
133-
You can stand anywhere for this. After running, you should see a huge tower of stone blocks either in front of you or behind you.
134-
135-
```python
136-
import mcpi.minecraft as minecraft
137-
import mcpi.block as block
138-
import time
139-
mc = minecraft.Minecraft.create()
140141

141-
pos = mc.player.getTilePos()
142-
for a in range(50):
143-
mc.setBlock(pos.x+3, pos.y+a, pos.z, block.STONE.id)
144-
```
145-
146-
![tower](https://raw.githubusercontent.com/gritcoding/minecraft/master/screenshots/tower.png)
142+
## The Bulldozer
147143

148-
* Explain the *range(50)*.
149-
* Explain the arguments we're passing to setBlock, and the coordinates.
150-
* Ask the student which coordinate should be increasing.
151-
* Extra credit
152-
* Build a fence instead of a tower
153-
154-
The bulldozer
155-
-------------
156-
*Objective:* work with more embedded loops and relative coordinates.
144+
*Objective:* Work with more embedded loops and relative coordinates.
157145

158146
* This script lets you clear a large area and leave it suitable for building.
159147
* In minecraft, an empty space is a block of type *AIR*
160148

161149
```python
162150
import mcpi.minecraft as minecraft
163151
import mcpi.block as block
164-
import time
165152
mc = minecraft.Minecraft.create()
166153

167154
player_pos = mc.player.getTilePos()

0 commit comments

Comments
 (0)