-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmca_strings.py
More file actions
71 lines (61 loc) · 2.23 KB
/
mca_strings.py
File metadata and controls
71 lines (61 loc) · 2.23 KB
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
#!/bin/python3
from anvil import Region
from nbt import nbt
import argparse
found = set()
def harvest_region(file):
region = Region.from_file(file)
for x in range(32):
for y in range(32):
harvest_chunk(region.chunk_data(x,y))
def harvest_chunk(chunk: nbt.TAG_COMPOUND):
if chunk == None:
return
for tag in chunk.tags:
if tag.name == "Level":
harvest_level(tag)
def harvest_level(level: nbt.TAG_COMPOUND):
for tag in level.tags:
if tag.id == 9 and tag.name == "TileEntities":
harvest_tile_entities(tag)
def harvest_tile_entities(entities: nbt.TAG_COMPOUND):
if len(entities.tags) != 0:
for entity in entities.tags:
if entity.id != 0:
harvest_tile_entity(entity)
def harvest_tile_entity(entity: nbt.TAG_COMPOUND):
id = entity.get("id").value
x = entity.get('x').value
y = entity.get('y').value
z = entity.get('z').value
if id == "minecraft:sign":
print(f"Sign at {x} {y} {z}: {{")
print(f" {extract_sign_text(entity.get('Text1').value)}")
print(f" {extract_sign_text(entity.get('Text2').value)}")
print(f" {extract_sign_text(entity.get('Text3').value)}")
print(f" {extract_sign_text(entity.get('Text4').value)}")
print(f"}}")
else:
print(f"Tile Entity at {x} {y} {z}: {{")
harvest_tag(entity)
print(f"}}")
def extract_sign_text(json: str):
return json[9:-2]
def harvest_tag(tag: nbt.TAG):
if tag == None:
return
if tag.id == 8: # String
log_string(tag.name, tag.value)
elif tag.id == 10 or tag.id == 9: # Compound or List
for t in tag.tags:
harvest_tag(t)
def log_string(name, value):
if not (name,value) in found:
found.add((name,value))
print(f"\"{name}\": \"{value}\"")
if __name__=="__main__":
parser = argparse.ArgumentParser(prog="mca_strings", description="Harvest all unique String Tags from a MC Region file.")
parser.add_argument("region_file", type=argparse.FileType('rb'), nargs="+")
for rf in parser.parse_args().region_file: #["regions/r.-1.-1.mca"]
print(f"DEBUG: Region file: {rf.name}")
harvest_region(rf)