generateFabric.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.fabric import JARS_DIR, INSTALLER_INFO_DIR, META_DIR, INTERMEDIARY_COMPONENT, LOADER_COMPONENT
  5. from meta.model import MetaVersion, Dependency, Library, MetaPackage, GradleSpecifier
  6. from meta.model.fabric import FabricJarInfo, FabricInstallerDataV1, FabricMainClasses
  7. PMC_DIR = polymc_path()
  8. UPSTREAM_DIR = upstream_path()
  9. ensure_component_dir(LOADER_COMPONENT)
  10. ensure_component_dir(INTERMEDIARY_COMPONENT)
  11. def load_jar_info(artifact_key) -> FabricJarInfo:
  12. return FabricJarInfo.parse_file(os.path.join(UPSTREAM_DIR, JARS_DIR, f"{artifact_key}.json"))
  13. def load_installer_info(version) -> FabricInstallerDataV1:
  14. return FabricInstallerDataV1.parse_file(os.path.join(UPSTREAM_DIR, INSTALLER_INFO_DIR, f"{version}.json"))
  15. def process_loader_version(entry) -> MetaVersion:
  16. jar_info = load_jar_info(transform_maven_key(entry["maven"]))
  17. installer_info = load_installer_info(entry["version"])
  18. v = MetaVersion(name="Fabric Loader", uid="net.fabricmc.fabric-loader", version=entry["version"])
  19. v.release_time = jar_info.release_time
  20. v.requires = [Dependency(uid='net.fabricmc.intermediary')]
  21. v.order = 10
  22. v.type = "release"
  23. if isinstance(installer_info.main_class, FabricMainClasses):
  24. v.main_class = installer_info.main_class.client
  25. else:
  26. v.main_class = installer_info.main_class
  27. v.libraries = []
  28. v.libraries.extend(installer_info.libraries.common)
  29. v.libraries.extend(installer_info.libraries.client)
  30. loader_lib = Library(name=GradleSpecifier.from_string(entry["maven"]), url="https://maven.fabricmc.net")
  31. v.libraries.append(loader_lib)
  32. return v
  33. def process_intermediary_version(entry) -> MetaVersion:
  34. jar_info = load_jar_info(transform_maven_key(entry["maven"]))
  35. v = MetaVersion(name="Intermediary Mappings", uid="net.fabricmc.intermediary", version=entry["version"])
  36. v.release_time = jar_info.release_time
  37. v.requires = [Dependency(uid='net.minecraft', equals=entry["version"])]
  38. v.order = 11
  39. v.type = "release"
  40. v.libraries = []
  41. v.volatile = True
  42. intermediary_lib = Library(name=GradleSpecifier.from_string(entry["maven"]), url="https://maven.fabricmc.net")
  43. v.libraries.append(intermediary_lib)
  44. return v
  45. def main():
  46. recommended_loader_versions = []
  47. recommended_intermediary_versions = []
  48. with open(os.path.join(UPSTREAM_DIR, META_DIR, "loader.json"), 'r', encoding='utf-8') as f:
  49. loader_version_index = json.load(f)
  50. for entry in loader_version_index:
  51. version = entry["version"]
  52. print(f"Processing loader {version}")
  53. v = process_loader_version(entry)
  54. if not recommended_loader_versions: # first (newest) loader is recommended
  55. recommended_loader_versions.append(version)
  56. v.write(os.path.join(PMC_DIR, LOADER_COMPONENT, f"{v.version}.json"))
  57. with open(os.path.join(UPSTREAM_DIR, META_DIR, "intermediary.json"), 'r', encoding='utf-8') as f:
  58. intermediary_version_index = json.load(f)
  59. for entry in intermediary_version_index:
  60. version = entry["version"]
  61. print(f"Processing intermediary {version}")
  62. v = process_intermediary_version(entry)
  63. recommended_intermediary_versions.append(version) # all intermediaries are recommended
  64. v.write(os.path.join(PMC_DIR, INTERMEDIARY_COMPONENT, f"{v.version}.json"))
  65. package = MetaPackage(uid=LOADER_COMPONENT, name='Fabric Loader')
  66. package.recommended = recommended_loader_versions
  67. package.description = "Fabric Loader is a tool to load Fabric-compatible mods in game environments."
  68. package.project_url = "https://fabricmc.net"
  69. package.authors = ["Fabric Developers"]
  70. package.write(os.path.join(PMC_DIR, LOADER_COMPONENT, "package.json"))
  71. package = MetaPackage(uid=INTERMEDIARY_COMPONENT, name='Intermediary Mappings')
  72. package.recommended = recommended_intermediary_versions
  73. package.description = "Intermediary mappings allow using Fabric Loader with mods for Minecraft in a more compatible manner."
  74. package.project_url = "https://fabricmc.net"
  75. package.authors = ["Fabric Developers"]
  76. package.write(os.path.join(PMC_DIR, INTERMEDIARY_COMPONENT, "package.json"))
  77. if __name__ == '__main__':
  78. main()