forked from eutro/MultiblockTweaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModMach2GTCE.py
67 lines (43 loc) · 2.09 KB
/
ModMach2GTCE.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
import re
import sys
def get_stack(match: re.Match):
return match.group("stack")
textIn = "".join(sys.stdin.readlines())
importPattern = re.compile("import mods\\.modularmachinery\\.RecipeBuilder(\\.newBuilder as (\\w+))?;")
search = importPattern.findall(textIn)
assert len(search) != 0
altName = "RecipeBuilder.newBuilder"
for s in search:
if len(s) > 1:
altName = s[1]
buildCallRegex = re.compile("\n(?P<comment>//.+\\W+)?" +
altName +
"\\((?P<qmark>[\\\"'])(?P<recipeId>[a-zA-Z1-9_\\-]*)(?P=qmark),\\W*"
"(?P<qmark2>[\\\"'])(?P<machineId>[a-zA-Z1-9_\\-]*)(?P=qmark2),\\W*"
"(?P<duration>\\d+)\\)(?P<extraCalls>(.|\\n)+?)\\.build\\(\\);")
regexes = (
(re.compile("\\.addItemInput\\((?P<stack>.+?)\\)"), "inputs"),
(re.compile("\\.addFluidInput\\((?P<stack>.+?)\\)"), "fluidInputs"),
(re.compile("\\.addItemOutput\\((?P<stack>.+?)\\)"), "outputs"),
(re.compile("\\.addFluidOutput\\((?P<stack>.+?)\\)"), "fluidOutputs")
)
energyRegex = re.compile("\\.addEnergyPerTick(?P<direction>Input|Output)\\((?P<val>\\d+)\\)")
ourBuilds = []
for buildCall in buildCallRegex.finditer(textIn):
comment = buildCall.group("comment")
build = comment if comment is not None else ""
build += buildCall.group("machineId") + (".recipeMap\n"
" .recipeBuilder()\n")
build += " .duration({0})\n".format(buildCall.group("duration"))
calls = buildCall.group("extraCalls")
energyM = list(energyRegex.finditer(calls))[-1]
energy = int(energyM.group("val")) / 4 * (1 if energyM.group("direction") == "Input" else -1)
build += " .EUt({0})\n".format(str(int(energy)))
for regex, function in regexes:
spaces = len(function) * " "
params = ",\n {0} ".format(spaces).join(map(get_stack, regex.finditer(calls)))
if params != "":
build += " .{0}({1})\n".format(function, params)
build += " .buildAndRegister();\n"
ourBuilds.append(build)
print("\n".join(ourBuilds))