-
Notifications
You must be signed in to change notification settings - Fork 303
Add --fabric.addMods / -Dfabric.addMods for adding extra path separator separated mods, list file if prefixed with @ #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
602cee2
b30fc64
b2014c8
7c8ed22
3f48a94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * Copyright 2016 FabricMC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package net.fabricmc.loader.impl.discovery; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
|
|
||
| import net.fabricmc.loader.impl.FabricLoaderImpl; | ||
| import net.fabricmc.loader.impl.util.Arguments; | ||
| import net.fabricmc.loader.impl.util.SystemProperties; | ||
| import net.fabricmc.loader.impl.util.log.Log; | ||
| import net.fabricmc.loader.impl.util.log.LogCategory; | ||
|
|
||
| public class ArgumentModCandidateFinder implements ModCandidateFinder { | ||
| private final boolean requiresRemap; | ||
|
|
||
| public ArgumentModCandidateFinder(boolean requiresRemap) { | ||
| this.requiresRemap = requiresRemap; | ||
| } | ||
|
|
||
| @Override | ||
| public void findCandidates(ModCandidateConsumer out) { | ||
| String list = System.getProperty(SystemProperties.ADD_MODS); | ||
| if (list != null) addMods(list, "system property", out); | ||
|
|
||
| list = FabricLoaderImpl.INSTANCE.getGameProvider().getArguments().remove(Arguments.ADD_MODS); | ||
| if (list != null) addMods(list, "argument", out); | ||
| } | ||
|
|
||
| private void addMods(String list, String source, ModCandidateConsumer out) { | ||
| for (String pathStr : list.split(File.pathSeparator)) { | ||
| if (pathStr.isEmpty()) continue; | ||
|
|
||
| if (pathStr.startsWith("@")) { | ||
| Path path = Paths.get(pathStr.substring(1)); | ||
|
|
||
| if (!Files.isRegularFile(path)) { | ||
| Log.warn(LogCategory.DISCOVERY, "Missing/invalid %s provided mod list file %s", source, path); | ||
| continue; | ||
| } | ||
|
|
||
| try (BufferedReader reader = Files.newBufferedReader(path)) { | ||
| String fileSource = String.format("%s file %s", source, path); | ||
| String line; | ||
|
|
||
| while ((line = reader.readLine()) != null) { | ||
| line = line.trim(); | ||
| if (line.isEmpty()) continue; | ||
|
|
||
| addMod(pathStr, fileSource, out); | ||
| } | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(String.format("Error reading %s provided mod list file %s", source, path), e); | ||
| } | ||
| } else { | ||
| addMod(pathStr, source, out); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void addMod(String pathStr, String source, ModCandidateConsumer out) { | ||
| Path path = Paths.get(pathStr); | ||
| boolean isDir; | ||
|
|
||
| if (!Files.exists(path)) { | ||
| Log.warn(LogCategory.DISCOVERY, "Missing %s provided mod path %s", source, path); | ||
| } else if ((isDir = Files.isDirectory(path)) && !Files.isRegularFile(path.resolve("fabric.mod.json")) | ||
| || !isDir && !DirectoryModCandidateFinder.isValidFile(path)) { | ||
| Log.warn(LogCategory.DISCOVERY, "Incompatible path in %s provided mod path %s (must be a directory with a fabric.mod.json or a non-hidden jar file", source, path); | ||
| } else { | ||
| out.accept(path, requiresRemap); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,8 +88,6 @@ public void acceptOptions(List<String> localArgs, File gameDir, File assetsDir, | |
| if (getEnvironmentType() == EnvType.CLIENT && !arguments.containsKey("assetsDir") && assetsDir != null) { | ||
| arguments.put("assetsDir", assetsDir.getAbsolutePath()); | ||
| } | ||
|
|
||
| FabricLauncherBase.processArgumentMap(arguments, getEnvironmentType()); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -118,6 +116,7 @@ public void injectIntoClassLoader(LaunchClassLoader launchClassLoader) { | |
| throw new RuntimeException("Could not locate Minecraft: provider locate failed"); | ||
| } | ||
|
|
||
| arguments = null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why null out the arguments? Just because they're not needed anymore?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe to allow garbage collection?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just to trap any accidental reuse |
||
| FabricLoaderImpl loader = FabricLoaderImpl.INSTANCE; | ||
| loader.setGameProvider(provider); | ||
| loader.load(); | ||
|
|
@@ -127,7 +126,6 @@ public void injectIntoClassLoader(LaunchClassLoader launchClassLoader) { | |
|
|
||
| if (!isDevelopment) { | ||
| // Obfuscated environment | ||
| Launch.blackboard.put(SystemProperties.DEVELOPMENT, false); | ||
|
|
||
| try { | ||
| String target = getLaunchTarget(); | ||
|
|
@@ -164,7 +162,7 @@ public void injectIntoClassLoader(LaunchClassLoader launchClassLoader) { | |
|
|
||
| @Override | ||
| public String[] getLaunchArguments() { | ||
| return isPrimaryTweaker ? arguments.toArray() : new String[0]; | ||
| return isPrimaryTweaker ? FabricLoaderImpl.INSTANCE.getGameProvider().getLaunchArguments(false) : new String[0]; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.