-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMaterialNames.py
78 lines (57 loc) · 2.33 KB
/
MaterialNames.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
77
78
import re
def generate_line(line, materialType, legacyId, currentId, legacyNominal, currentNominal, stack, oldId, oldData):
base = "public static final Material<" + materialType + "> " + line + " = new Material<>("
if materialType is not "Block":
base = base + materialType + ".class, "
base = base + "\"" + legacyId + "\", "
if currentId is not "SKIPPED":
base = base + "\"" + currentId + "\", "
base = base + "\"" + legacyNominal + "\", "
if currentNominal is not "SKIPPED":
base = base + "\"" + currentNominal + "\", "
if stack is not "64":
base = base + str(stack)
if oldId is not "SKIPPED":
base = base + ", new LegacyData(" + oldId + ", "
if oldData is "SKIPPED":
if oldId is not "SKIPPED":
base = base + "0)"
else:
if oldId is not "SKIPPED":
base = base + oldData + ")"
return base + ");\n"
def resolve_arg(prompt, default):
if default is None:
arg = str(input(prompt + ": "))
while not arg:
arg = str(input(prompt + ": "))
else:
arg = str(input(prompt + ": "))
if not arg:
arg = default
print(prompt + " set to: " + str(arg))
return arg
with open('Material.java') as materials:
start = int(input("Starting Line: "))
with open('formatted.txt', mode='r+') as new:
for num, line in enumerate(materials.readlines()):
if num >= 940: break
if num < start-1: continue
if line.startswith("import") or "LEGACY_" in line: continue
test = re.findall(r'([A-Z_]{3,})', line)
if not test: continue
print(test[0])
matType = resolve_arg("Type", "Block")
legacyId = resolve_arg("LegacyId", None)
currentId = resolve_arg("CurrentId", "SKIPPED")
legacyNom = resolve_arg("LegacyNominal", None)
currentNom = resolve_arg("CurrentNominal", "SKIPPED")
stack = resolve_arg("Stack", "64")
oldId = resolve_arg("OldId", "SKIPPED")
oldData = resolve_arg("OldData", "SKIPPED")
line = generate_line(test[0], matType, legacyId, currentId, legacyNom, currentNom, stack, oldId, oldData)
print(line)
new.write(line)
new.flush()
new.close()
materials.close()