-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathminecraft_map.py
69 lines (56 loc) · 1.3 KB
/
minecraft_map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from mcpi import minecraft
from sense_hat import SenseHat
from time import sleep
def get_blocks(size):
global known_blocks
x, y, z = mc.player.getTilePos()
y -= 1
n0 = (size - 1) / 2
n1 = ((size + 1) / 2)
if size % 2 == 0:
n1 += 1
blocks = []
for dx in range(x-n0, x+n1):
for dz in range(z-n0, z+n1):
b = (dx, dz)
try:
block = known_blocks[b]
except KeyError:
block = mc.getBlock(dx, y+0, dz)
known_blocks[b] = block
blocks.append(block)
return blocks
def lookup_colour(block):
if block in colours:
return colours[block]
else:
return white
def map_blocks_to_colours(blocks):
return [lookup_colour(block) for block in blocks]
mc = minecraft.Minecraft.create()
sense = SenseHat()
known_blocks = {}
# blocks
air = 0
grass = 2
water = 9
sand = 12
# colours
white = (150, 150, 150)
green = (0, 150, 0)
blue = (0, 0, 150)
yellow = (150, 150, 0)
black = (0, 0, 0)
# block: colour
colours = {
air: white,
grass: green,
water: blue,
sand: yellow,
}
player_pos = 27
while True:
blocks = get_blocks(8)
pixels = map_blocks_to_colours(blocks)
pixels[player_pos] = black # denote player as black pixel
sense.set_pixels(pixels)