HMCL icon indicating copy to clipboard operation
HMCL copied to clipboard

Forge 1.17 和 OptiFine H1 Pre2 更低版本一起安装不会显示不兼容

Open MrShieh-X opened this issue 3 years ago • 1 comments

问题描述

安装 1.17.1(因为1.17没有Forge)时,如果 Forge 与 OptiFine H1 Pre2 更低版本 同时安装,判断该版本是否安装了 Forge 且 OptiFine 版本是否低于 H1 Pre2 的判断有问题。
但是这个问题只会出现在安装新版本时同时安装两者的情况,如果安装了 Forge 之后再安装 OptiFine 则不会出现这个问题,会正常提示

Minecraft 1.17.1 下,仅 OptiFine H1 Pre2 及以上版本能兼容 Forge。你可以从 OptiFine 测试版中选择最新版本。

问题后果

若同时安装时不提示不兼容,则启动就会出现以下错误

[main/ERROR]: Found 1 services that failed to load : [OptiFine] Exception in thread "main" cpw.mods.modlauncher.InvalidLauncherSetupException: Invalid Services found OptiFine at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.TransformationServicesHandler.validateTransformationServices(TransformationServicesHandler.java:111) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:50) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.run(Launcher.java:87) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:77) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) at [email protected]/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:90)

问题原因

从代码角度来看,出现BUG的地方是org.jackhuang.hmcl.download.optifine.OptiFineInstallTask的方法public void execute(),具体代码:

if (LibraryAnalyzer.BOOTSTRAP_LAUNCHER_MAIN.equals(originalMainClass)) {
    // OptiFine H1 Pre2+ is compatible with Forge 1.17
    if (buildofVer.compareTo(VersionNumber.asVersion("20210924-190833")) < 0) {
          throw new UnsupportedInstallationException(UnsupportedInstallationException.FORGE_1_17_OPTIFINE_H1_PRE2);
    }
}

因为org.jackhuang.hmcl.download.DefaultGameBuilderbuildAsync函数中的remoteVersions是个HashSet,OptiFine的安装顺序永远提前于 Forge,所以,同时安装时,变量originalMainClass无论你要不要安装 Forge,他都是net.minecraft.client.main.Main,而不会是cpw.mods.bootstraplauncher.BootstrapLauncher,从而判断不成立。
那为什么另一种安装方式(安装了 Forge 后安装 OptiFine)不会出现错误呢?那是因为那种安装方式在安装 Forge 后,mainClass被设为cpw.mods.bootstraplauncher.BootstrapLauncher,使判断成立。

解决方式

~~同时安装时,如果安装了 Forge 1.17,mainClass 设为 Forge 的 mainClass,即cpw.mods.bootstraplauncher.BootstrapLauncher。~~ 排序remoteVersions,将 OptiFine 的安装顺序无论如何都放在最后。

MrShieh-X avatar May 15 '22 05:05 MrShieh-X

应该使用更好的方法解决该问题

huanghongxun avatar May 18 '22 07:05 huanghongxun

image OptiFine 官方直接说不兼容了,这是正常现象

burningtnt avatar May 05 '24 08:05 burningtnt