generateQuilt.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import json
  2. import os
  3. from meta.common import ensure_component_dir, polymc_path, upstream_path, transform_maven_key
  4. from meta.common.quilt import JARS_DIR, INSTALLER_INFO_DIR, META_DIR, INTERMEDIARY_COMPONENT, LOADER_COMPONENT, \
  5. USE_QUILT_MAPPINGS
  6. from meta.model import MetaVersion, Dependency, Library, MetaPackage, GradleSpecifier
  7. from meta.model.fabric import FabricJarInfo, FabricInstallerDataV1, FabricMainClasses
  8. PMC_DIR = polymc_path()
  9. UPSTREAM_DIR = upstream_path()
  10. ensure_component_dir(LOADER_COMPONENT)
  11. ensure_component_dir(INTERMEDIARY_COMPONENT)
  12. def load_jar_info(artifact_key) -> FabricJarInfo:
  13. return FabricJarInfo.parse_file(os.path.join(UPSTREAM_DIR, JARS_DIR, f"{artifact_key}.json"))
  14. def load_installer_info(version) -> FabricInstallerDataV1:
  15. return FabricInstallerDataV1.parse_file(os.path.join(UPSTREAM_DIR, INSTALLER_INFO_DIR, f"{version}.json"))
  16. def process_loader_version(entry) -> (MetaVersion, bool):
  17. should_recommend = "-" not in entry["version"] # dont recommend pre releases as per SemVer
  18. jar_info = load_jar_info(transform_maven_key(entry["maven"]))
  19. installer_info = load_installer_info(entry["version"])
  20. v = MetaVersion(name="Quilt Loader", uid=LOADER_COMPONENT, version=entry["version"])
  21. v.release_time = jar_info.release_time
  22. v.requires = [Dependency(uid=INTERMEDIARY_COMPONENT)]
  23. v.order = 10
  24. v.type = "release"
  25. if isinstance(installer_info.main_class, FabricMainClasses):
  26. v.main_class = installer_info.main_class.client
  27. else:
  28. v.main_class = installer_info.main_class
  29. v.libraries = []
  30. v.libraries.extend(installer_info.libraries.common)
  31. v.libraries.extend(installer_info.libraries.client)
  32. loader_lib = Library(name=GradleSpecifier.from_string(entry["maven"]),
  33. url="https://maven.quiltmc.org/repository/release")
  34. v.libraries.append(loader_lib)
  35. return v, should_recommend
  36. def process_intermediary_version(entry) -> MetaVersion:
  37. jar_info = load_jar_info(transform_maven_key(entry["maven"]))
  38. v = MetaVersion(name="Quilt Intermediary Mappings", uid=INTERMEDIARY_COMPONENT, version=entry["version"])
  39. v.release_time = jar_info.release_time
  40. v.requires = [Dependency(uid='net.minecraft', equals=entry["version"])]
  41. v.order = 11
  42. v.type = "release"
  43. v.libraries = []
  44. v.volatile = True
  45. intermediary_lib = Library(name=GradleSpecifier.from_string(entry["maven"]),
  46. url="https://maven.quiltmc.org/repository/release")
  47. v.libraries.append(intermediary_lib)
  48. return v
  49. def main():
  50. recommended_loader_versions = []
  51. recommended_intermediary_versions = []
  52. with open(os.path.join(UPSTREAM_DIR, META_DIR, "loader.json"), 'r', encoding='utf-8') as f:
  53. loader_version_index = json.load(f)
  54. for entry in loader_version_index:
  55. version = entry["version"]
  56. print(f"Processing loader {version}")
  57. v, should_recommend = process_loader_version(entry)
  58. if not recommended_loader_versions and should_recommend: # newest stable loader is recommended
  59. recommended_loader_versions.append(version)
  60. v.write(os.path.join(PMC_DIR, LOADER_COMPONENT, f"{v.version}.json"))
  61. if USE_QUILT_MAPPINGS:
  62. with open(os.path.join(UPSTREAM_DIR, META_DIR, "hashed.json"), 'r', encoding='utf-8') as f:
  63. intermediary_version_index = json.load(f)
  64. for entry in intermediary_version_index:
  65. version = entry["version"]
  66. print(f"Processing intermediary {version}")
  67. v = process_intermediary_version(entry)
  68. recommended_intermediary_versions.append(version) # all intermediaries are recommended
  69. v.write(os.path.join(PMC_DIR, INTERMEDIARY_COMPONENT, f"{v.version}.json"))
  70. package = MetaPackage(uid=LOADER_COMPONENT, name='Quilt Loader')
  71. package.recommended = recommended_loader_versions
  72. package.description = "The Quilt project is an open, community-driven modding toolchain designed primarily for Minecraft."
  73. package.project_url = "https://quiltmc.org/"
  74. package.authors = ["Quilt Project"]
  75. package.write(os.path.join(PMC_DIR, LOADER_COMPONENT, "package.json"))
  76. if USE_QUILT_MAPPINGS:
  77. package = MetaPackage(uid=INTERMEDIARY_COMPONENT, name='Quilt Intermediary Mappings')
  78. package.recommended = recommended_intermediary_versions
  79. package.description = "Intermediary mappings allow using Quilt Loader with mods for Minecraft in a more compatible manner."
  80. package.project_url = "https://quiltmc.org/"
  81. package.authors = ["Quilt Project"]
  82. package.write(os.path.join(PMC_DIR, INTERMEDIARY_COMPONENT, "package.json"))
  83. if __name__ == '__main__':
  84. main()