简化 DefaultLauncher#getEnvVars (#6197)

Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
辞庐
2026-09-03 21:56:15 +08:00
committed by GitHub
parent 9ebf29d060
commit 00cd20a6e9
2 changed files with 28 additions and 28 deletions
@@ -17,13 +17,27 @@
*/
package org.jackhuang.hmcl.addon.mod;
import org.jetbrains.annotations.NotNullByDefault;
import org.jetbrains.annotations.Nullable;
@NotNullByDefault
public enum ModLoaderType {
UNKNOWN,
FORGE,
CLEANROOM,
NEO_FORGE,
FABRIC,
QUILT,
LITE_LOADER,
LEGACY_FABRIC
UNKNOWN(null),
FORGE("INST_FORGE"),
CLEANROOM("INST_CLEANROOM"),
NEO_FORGE("INST_NEOFORGE"),
FABRIC("INST_FABRIC"),
QUILT("INST_QUILT"),
LITE_LOADER("INST_LITELOADER"),
LEGACY_FABRIC("INST_LEGACYFABRIC");
private final @Nullable String envVarName;
ModLoaderType(@Nullable String envVarName) {
this.envVarName = envVarName;
}
public @Nullable String getEnvVarName() {
return envVarName;
}
}
@@ -18,6 +18,7 @@
package org.jackhuang.hmcl.launch;
import org.glavo.uuid.UUIDs;
import org.jackhuang.hmcl.addon.mod.ModLoaderType;
import org.jackhuang.hmcl.auth.AuthInfo;
import org.jackhuang.hmcl.game.*;
import org.jackhuang.hmcl.util.Lang;
@@ -799,30 +800,15 @@ public class DefaultLauncher extends Launcher {
}
}
if (instance.hasComponent(GameComponentType.FORGE)) {
env.put("INST_FORGE", "1");
}
if (instance.hasComponent(GameComponentType.CLEANROOM)) {
env.put("INST_CLEANROOM", "1");
}
if (instance.hasComponent(GameComponentType.NEO_FORGE)) {
env.put("INST_NEOFORGE", "1");
}
if (instance.hasComponent(GameComponentType.LITELOADER)) {
env.put("INST_LITELOADER", "1");
}
if (instance.hasComponent(GameComponentType.FABRIC)) {
env.put("INST_FABRIC", "1");
for (ModLoaderType modLoader : instance.getModLoaders()) {
if (modLoader.getEnvVarName() != null) {
env.put(modLoader.getEnvVarName(), "1");
}
}
if (instance.hasComponent(GameComponentType.OPTIFINE)) {
env.put("INST_OPTIFINE", "1");
}
if (instance.hasComponent(GameComponentType.QUILT)) {
env.put("INST_QUILT", "1");
}
if (instance.hasComponent(GameComponentType.LEGACY_FABRIC)) {
env.put("INST_LEGACYFABRIC", "1");
}
env.putAll(options.getEnvironmentVariables());