-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunkcounter.py
49 lines (33 loc) · 1.1 KB
/
chunkcounter.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
import os
import sys
from os import path
def main(args):
print(count_chunks(args[1]))
def get_region_files(world_dir):
"""Return a list of region files in the world directory."""
overworld_path = path.join(world_dir, "region")
nether_path = path.join(world_dir, "DIM1", "region")
end_path = path.join(world_dir, "DIM-1", "region")
files = []
for p in (overworld_path, nether_path, end_path):
if path.isdir(p):
files.extend([path.join(p, i) for i in os.listdir(p)])
return files
def chunks_in_region_file(filename):
"""Return the number of chunks generated in a region file."""
chunks = 0
with open(filename, 'rb') as f:
for i in range(1024):
entry = f.read(4)
if entry[-1] != 0:
chunks += 1
return chunks
def count_chunks(dirname):
"""Return the total number of chunks in a Minecraft world."""
region_files = get_region_files(dirname)
chunks = 0
for f in region_files:
chunks += chunks_in_region_file(f)
return chunks
if __name__ == '__main__':
main(sys.argv)