diff --git a/picomc/instance.py b/picomc/instance.py index d374e26..6a038b7 100644 --- a/picomc/instance.py +++ b/picomc/instance.py @@ -123,7 +123,7 @@ def launch(self, account, version=None, verify_hashes=False): os.makedirs(gamedir, exist_ok=True) java = self.get_java() - java_info = assert_java(java) + java_info = assert_java(java, vobj.java_version) libraries = vobj.get_libraries(java_info) vobj.prepare_launch(gamedir, java_info, verify_hashes) @@ -146,7 +146,7 @@ def launch(self, account, version=None, verify_hashes=False): def extract_natives(self): vobj = self.launcher.version_manager.get_version(self.config["version"]) - java_info = assert_java(self.get_java()) + java_info = assert_java(self.get_java(), vobj.java_version) vobj.download_libraries(java_info, verify_hashes=True) libs = vobj.get_libraries(java_info) ne = NativesExtractor( diff --git a/picomc/java/javainfo.py b/picomc/java/javainfo.py index 50b7bae..383cf60 100644 --- a/picomc/java/javainfo.py +++ b/picomc/java/javainfo.py @@ -46,10 +46,31 @@ def get_java_info(java): return res -def assert_java(java): +def check_version_against(version: str, wanted): + component = wanted["component"] + wanted_major = str(wanted["majorVersion"]) + + major, minor, *_ = version.split(".") + + if component == "jre-legacy": + return major == "1" and minor == wanted_major + else: + return major == wanted_major + + +def wanted_to_str(wanted): + component = wanted["component"] + major = str(wanted["majorVersion"]) + + if component == "jre-legacy": + return f"1.{major}.0" + else: + return str(major) + + +def assert_java(java, wanted): try: jinfo = get_java_info(java) - badjv = not jinfo["java.version"].startswith("1.8.0") bitness = jinfo.get("sun.arch.data.model", None) if bitness and bitness != "64": logger.warning( @@ -62,12 +83,24 @@ def assert_java(java): ) ) - if badjv: + if not check_version_against(jinfo["java.version"], wanted): logger.warning( - "Minecraft uses java 1.8.0 by default." - " You may experience issues, especially with older versions of Minecraft." + "The version of Minecraft you are launching " + "uses java {} by default.".format(wanted_to_str(wanted)) ) + logger.warning( + "You may experience issues, especially with older versions of Minecraft." + ) + + major = int(jinfo["java.version"].split(".")[0]) + if major < wanted["majorVersion"]: + logger.error( + "Note that at least java {} is required to launch at all.".format( + wanted_to_str(wanted) + ) + ) + return jinfo except FileNotFoundError: diff --git a/picomc/version.py b/picomc/version.py index 4faad0d..ee08bd1 100644 --- a/picomc/version.py +++ b/picomc/version.py @@ -70,6 +70,11 @@ def argumentadd(d1, d2): ), } +LEGACY_JAVA_VERSION = { + "component": "jre-legacy", + "majorVersion": 8, +} + class VersionSpec: def __init__(self, vobj, version_manager): @@ -109,6 +114,12 @@ def initialize_fields(self): self.arguments = self.attr_reduce("arguments", argumentadd) except AttributeError: pass + + # TODO maybe we could detect extremely old versions of Minecraft and + # put an appropriate version of java here in that case + self.javaVersion = self.attr_override( + "javaVersion", default=LEGACY_JAVA_VERSION + ) self.mainClass = self.attr_override("mainClass") self.assetIndex = self.attr_override("assetIndex", default=None) self.assets = self.attr_override("assets", default="legacy") @@ -141,6 +152,8 @@ def __init__(self, version_name, launcher, version_manifest): self.jarname = self.vspec.jar self.jarfile = self.versions_root / self.jarname / "{}.jar".format(self.jarname) + self.java_version = self.vspec.javaVersion + def get_raw_vspec(self): vspec_path = ( self.versions_root / self.version_name / "{}.json".format(self.version_name)