-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
generateFabric.py
executable file
·128 lines (115 loc) · 5.5 KB
/
generateFabric.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/python3
from fabricutil import *
from jsonobject import *
from datetime import datetime
from pprint import pprint
import os, copy
# turn loader versions into packages
loaderRecommended = []
loaderVersions = []
intermediaryRecommended = []
intermediaryVersions = []
def mkdirs(path):
if not os.path.exists(path):
os.makedirs(path)
mkdirs("multimc/net.fabricmc.fabric-loader")
mkdirs("multimc/net.fabricmc.intermediary")
def loadJarInfo(mavenKey):
with open("upstream/fabric/jars/" + mavenKey.replace(":", ".") + ".json", 'r', encoding='utf-8') as jarInfoFile:
return FabricJarInfo(json.load(jarInfoFile))
def processLoaderVersion(loaderVersion, it, loaderData, metadataVersion):
'TODO: use min_java_version to fill in the equivalent of it in the final file(s) bonce we have that in place'
verStable = it["stable"]
if (len(loaderRecommended) < 1) and verStable:
loaderRecommended.append(loaderVersion)
versionJarInfo = loadJarInfo(it["maven"])
version = MultiMCVersionFile(name="Fabric Loader", uid="net.fabricmc.fabric-loader", version=loaderVersion)
version.releaseTime = versionJarInfo.releaseTime
version.requires = [DependencyEntry(uid='net.fabricmc.intermediary')]
version.order = 10
version.type = "release"
if isinstance(loaderData.mainClass, dict):
version.mainClass = loaderData.mainClass["client"]
else:
version.mainClass = loaderData.mainClass
version.libraries = []
if metadataVersion == 1:
version.libraries.extend(loaderData.libraries.common)
version.libraries.extend(loaderData.libraries.client)
elif metadataVersion == 2:
version.libraries.extend(list(map(FabricLibrary.toMmcLibrary, loaderData.libraries.common)))
version.libraries.extend(list(map(FabricLibrary.toMmcLibrary, loaderData.libraries.client)))
loaderLibName = GradleSpecifier(it["maven"])
loaderLib = MultiMCLibrary(
name=loaderLibName,
downloads = MojangLibraryDownloads(
artifact = MojangArtifact(
sha1 = versionJarInfo.sha1,
size = versionJarInfo.size,
url="https://maven.fabricmc.net/" + loaderLibName.getPath(),
),
),
)
version.libraries.append(loaderLib)
loaderVersions.append(version)
def processIntermediaryVersion(it):
intermediaryRecommended.append(it["version"])
versionJarInfo = loadJarInfo(it["maven"])
version = MultiMCVersionFile(name="Intermediary Mappings", uid="net.fabricmc.intermediary", version=it["version"])
version.releaseTime = versionJarInfo.releaseTime
version.requires = [DependencyEntry(uid='net.minecraft', equals=it["version"])]
version.order = 11
version.type = "release"
version.libraries = []
version.volatile = True
mappingLibName = GradleSpecifier(it["maven"])
mappingLib = MultiMCLibrary(
name=mappingLibName,
downloads = MojangLibraryDownloads(
artifact = MojangArtifact(
sha1 = versionJarInfo.sha1,
size = versionJarInfo.size,
url="https://maven.fabricmc.net/" + mappingLibName.getPath(),
),
),
)
version.libraries.append(mappingLib)
intermediaryVersions.append(version)
with open("upstream/fabric/meta-v2/loader.json", 'r', encoding='utf-8') as loaderVersionIndexFile:
loaderVersionIndex = json.load(loaderVersionIndexFile)
for it in loaderVersionIndex:
version = it["version"]
with open("upstream/fabric/loader-installer-json/" + version + ".json", 'r', encoding='utf-8') as loaderVersionFile:
ldata = json.load(loaderVersionFile)
metadataVersion = ldata['version']
if metadataVersion == 1:
ldata = FabricInstallerDataV1(ldata)
elif metadataVersion == 2:
ldata = FabricInstallerDataV2(ldata)
else:
raise UnknownVersionException("Unsupported Fabric format version: %d. Max supported is: 2" % (metadataVersion))
processLoaderVersion(version, it, ldata, metadataVersion)
with open("upstream/fabric/meta-v2/intermediary.json", 'r', encoding='utf-8') as intermediaryVersionIndexFile:
intermediaryVersionIndex = json.load(intermediaryVersionIndexFile)
for it in intermediaryVersionIndex:
processIntermediaryVersion(it)
for version in loaderVersions:
outFilepath = "multimc/net.fabricmc.fabric-loader/%s.json" % version.version
with open(outFilepath, 'w') as outfile:
json.dump(version.to_json(), outfile, sort_keys=True, indent=4)
sharedData = MultiMCSharedPackageData(uid = 'net.fabricmc.fabric-loader', name = 'Fabric Loader')
sharedData.recommended = loaderRecommended
sharedData.description = "Fabric Loader is a tool to load Fabric-compatible mods in game environments."
sharedData.projectUrl = "https://fabricmc.net"
sharedData.authors = ["Fabric Developers"]
sharedData.write()
for version in intermediaryVersions:
outFilepath = "multimc/net.fabricmc.intermediary/%s.json" % version.version
with open(outFilepath, 'w') as outfile:
json.dump(version.to_json(), outfile, sort_keys=True, indent=4)
sharedData = MultiMCSharedPackageData(uid = 'net.fabricmc.intermediary', name = 'Intermediary Mappings')
sharedData.recommended = intermediaryRecommended
sharedData.description = "Intermediary mappings allow using Fabric Loader with mods for Minecraft in a more compatible manner."
sharedData.projectUrl = "https://fabricmc.net"
sharedData.authors = ["Fabric Developers"]
sharedData.write()