Skip to content

Commit fad05cc

Browse files
committed
[Feat] (launch): Add mod loader env
1 parent 43f860d commit fad05cc

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

FCLCore/src/main/java/com/tungsten/fclcore/launch/DefaultLauncher.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.tungsten.fclauncher.utils.Architecture;
3232
import com.tungsten.fclcore.auth.AuthInfo;
3333
import com.tungsten.fclauncher.utils.FCLPath;
34+
import com.tungsten.fclcore.download.LibraryAnalyzer;
3435
import com.tungsten.fclcore.game.Argument;
3536
import com.tungsten.fclcore.game.Arguments;
3637
import com.tungsten.fclcore.game.GameRepository;
@@ -445,6 +446,8 @@ public FCLBridge launch() throws IOException, InterruptedException {
445446

446447
String[] finalArgs = rawCommandLine.toArray(new String[0]);
447448

449+
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(version, repository.getGameVersion(version).orElse(null));
450+
448451
FCLConfig.Renderer renderer = options.getRenderer();
449452
FCLConfig config = new FCLConfig(
450453
context,
@@ -456,6 +459,14 @@ public FCLBridge launch() throws IOException, InterruptedException {
456459
);
457460
config.setUseVKDriverSystem(options.isVKDriverSystem());
458461
config.setPojavBigCore(options.isPojavBigCore());
462+
config.setInstalledModLoaders(new FCLConfig.InstalledModLoaders(
463+
analyzer.has(LibraryAnalyzer.LibraryType.FORGE),
464+
analyzer.has(LibraryAnalyzer.LibraryType.NEO_FORGE),
465+
analyzer.has(LibraryAnalyzer.LibraryType.OPTIFINE),
466+
analyzer.has(LibraryAnalyzer.LibraryType.LITELOADER),
467+
analyzer.has(LibraryAnalyzer.LibraryType.FABRIC),
468+
analyzer.has(LibraryAnalyzer.LibraryType.QUILT)
469+
));
459470
return FCLauncher.launchMinecraft(config);
460471
}
461472

FCLauncher/src/main/java/com/tungsten/fclauncher/FCLConfig.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,58 @@ public String toString() {
5151
}
5252
}
5353

54+
public static class InstalledModLoaders {
55+
private final boolean installForge;
56+
private final boolean installNeoForge;
57+
private final boolean installOptiFine;
58+
private final boolean installLiteLoader;
59+
private final boolean installFabric;
60+
private final boolean installQuilt;
61+
62+
public InstalledModLoaders(boolean installForge, boolean installNeoForge, boolean installOptiFine, boolean installLiteLoader, boolean installFabric, boolean installQuilt) {
63+
this.installForge = installForge;
64+
this.installNeoForge = installNeoForge;
65+
this.installOptiFine = installOptiFine;
66+
this.installLiteLoader = installLiteLoader;
67+
this.installFabric = installFabric;
68+
this.installQuilt = installQuilt;
69+
}
70+
71+
public boolean isInstallForge() {
72+
return installForge;
73+
}
74+
75+
public boolean isInstallNeoForge() {
76+
return installNeoForge;
77+
}
78+
79+
public boolean isInstallOptiFine() {
80+
return installOptiFine;
81+
}
82+
83+
public boolean isInstallLiteLoader() {
84+
return installLiteLoader;
85+
}
86+
87+
public boolean isInstallFabric() {
88+
return installFabric;
89+
}
90+
91+
public boolean isInstallQuilt() {
92+
return installQuilt;
93+
}
94+
}
95+
5496
private final Context context;
5597
private final String logDir;
5698
private final String javaPath;
5799
private final String workingDir;
58100
private final Renderer renderer;
59101
private final String[] args;
102+
60103
private boolean useVKDriverSystem = false;
61104
private boolean pojavBigCore = false;
105+
private InstalledModLoaders installedModLoaders = null;
62106

63107
public FCLConfig(Context context, String logDir, String javaPath, String workingDir, Renderer renderer, String[] args) {
64108
this.context = context;
@@ -109,4 +153,11 @@ public boolean isPojavBigCore() {
109153
return pojavBigCore;
110154
}
111155

156+
public void setInstalledModLoaders(InstalledModLoaders installedModLoaders) {
157+
this.installedModLoaders = installedModLoaders;
158+
}
159+
160+
public InstalledModLoaders getInstalledModLoaders() {
161+
return installedModLoaders;
162+
}
112163
}

FCLauncher/src/main/java/com/tungsten/fclauncher/FCLauncher.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,30 @@ private static void addCommonEnv(FCLConfig config, HashMap<String, String> envMa
192192
}
193193
}
194194

195+
private static void addModLoaderEnv(FCLConfig config, HashMap<String, String> envMap) {
196+
if (config.getInstalledModLoaders() == null)
197+
return;
198+
199+
if (config.getInstalledModLoaders().isInstallForge()) {
200+
envMap.put("INST_FORGE", "1");
201+
}
202+
if (config.getInstalledModLoaders().isInstallNeoForge()) {
203+
envMap.put("INST_NEOFORGE", "1");
204+
}
205+
if (config.getInstalledModLoaders().isInstallOptiFine()) {
206+
envMap.put("INST_LITELOADER", "1");
207+
}
208+
if (config.getInstalledModLoaders().isInstallLiteLoader()) {
209+
envMap.put("INST_FABRIC", "1");
210+
}
211+
if (config.getInstalledModLoaders().isInstallFabric()) {
212+
envMap.put("INST_OPTIFINE", "1");
213+
}
214+
if (config.getInstalledModLoaders().isInstallQuilt()) {
215+
envMap.put("INST_QUILT", "1");
216+
}
217+
}
218+
195219
private static void addRendererEnv(FCLConfig config, HashMap<String, String> envMap) {
196220
FCLConfig.Renderer renderer = config.getRenderer() == null ? FCLConfig.Renderer.RENDERER_GL4ES : config.getRenderer();
197221
if (renderer == FCLConfig.Renderer.RENDERER_CUSTOM) {
@@ -295,6 +319,7 @@ private static void addRendererEnv(FCLConfig config, HashMap<String, String> env
295319
private static void setEnv(FCLConfig config, FCLBridge bridge, boolean render) {
296320
HashMap<String, String> envMap = new HashMap<>();
297321
addCommonEnv(config, envMap);
322+
addModLoaderEnv(config, envMap);
298323
if (render) {
299324
addRendererEnv(config, envMap);
300325
}
@@ -366,7 +391,7 @@ private static void setupGraphicAndSoundEngine(FCLConfig config, FCLBridge bridg
366391
long handle = bridge.dlopen(RendererPlugin.getSelected().getPath() + "/" + RendererPlugin.getSelected().getGlName());
367392
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
368393
try {
369-
Os.setenv("RENDERER_HANDLE",handle+"",true);
394+
Os.setenv("RENDERER_HANDLE",handle + "",true);
370395
} catch (ErrnoException ignore) {
371396
}
372397
}

0 commit comments

Comments
 (0)