-
Notifications
You must be signed in to change notification settings - Fork 22
/
content.py
76 lines (71 loc) · 2.63 KB
/
content.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
70
71
72
73
74
75
76
def preprocess(lines, flags):
output = []
skip_level = 0
for line in lines:
line = line.split("//")[0].strip() # Remove comment
if line == "":
continue
if line[0] == "#":
if line.startswith("#ifdef"):
cond = line[7:].strip()
if skip_level > 0 or cond not in flags:
skip_level += 1
elif line.startswith("#else"):
if skip_level == 0:
skip_level = 1
elif skip_level == 1:
skip_level = 0
elif line.startswith("#endif"):
if skip_level > 0:
skip_level -= 1
continue
if skip_level == 0:
output.append(line)
return output
def get_id(name_id_mapping, name):
try:
# if the name of the node is known then return the location with the name_id_mapping list
return name_id_mapping.index(name)
except:
# else add the name of the node to the list then return the location
name_id_mapping.append(name)
return len(name_id_mapping)-1
def read_content(flags):
with open("map_content.txt", "r") as f:
lines = f.readlines()
lines = preprocess(lines, flags)
# if you map to air, then unknown blocks will be ignored
name_id_mapping = ["air"]
# name_id_mapping = ["mcblock:unknown"]
bd = {} # bd is block data, and keeps a list of the node names in the block
# iterate through all the lines in the map_content.txt file
for line in lines:
s = line.split("\t")
if len(s) >= 2:
r = s[1].split(" ")
if len(r) == 0:
print(line)
raise ValueError("Malformed data")
name = r[0]
param2 = 0
for i in range(1, len(r)):
if r[i] != "":
param2 = int(r[i])
break
t = s[0].split(" ")
if len(t) == 2:
for data in t[1].split(","):
key = (int(t[0]), int(data))
if key not in bd:
bd[key] = (get_id(name_id_mapping, name), param2)
elif len(t) == 1:
for data in range(16):
key = (int(t[0]), data)
if key not in bd:
bd[key] = (get_id(name_id_mapping, name), param2)
#blocks_len = max([i[0] for i in bd.keys()])+1
blocks_len = 4096
blocks = [[(0, 0)]*16 for i in range(blocks_len)]
for (id, data), value in bd.items():
blocks[id][data] = value
return name_id_mapping, blocks