Make MOD_CLASSES available to the forge development environment as well.
Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
1d1133123b
commit
8b74b32909
3 changed files with 28 additions and 21 deletions
|
@ -24,20 +24,21 @@ import cpw.mods.modlauncher.api.IEnvironment;
|
|||
import cpw.mods.modlauncher.api.ITransformingClassLoader;
|
||||
import cpw.mods.modlauncher.api.ITransformingClassLoaderBuilder;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static net.minecraftforge.fml.loading.LogMarkers.CORE;
|
||||
|
@ -85,6 +86,26 @@ public abstract class FMLCommonLaunchHandler
|
|||
FMLLoader.beforeStart(launchClassLoader);
|
||||
}
|
||||
|
||||
protected void processModClassesEnvironmentVariable(final Map<String, List<Pair<Path, List<Path>>>> arguments) {
|
||||
LOGGER.info(CORE, "Got mod coordinates {} from env", System.getenv("MOD_CLASSES"));
|
||||
|
||||
// "a/b/;c/d/;" -> "modid%%c:\fish\pepper;modid%%c:\fish2\pepper2\;modid2%%c:\fishy\bums;modid2%%c:\hmm"
|
||||
final Map<String, List<Path>> modClassPaths = Arrays.stream(System.getenv("MOD_CLASSES").split(File.pathSeparator)).
|
||||
map(inp -> inp.split("%%", 2)).map(this::buildModPair).
|
||||
collect(Collectors.groupingBy(Pair::getLeft, Collectors.mapping(Pair::getRight, Collectors.toList())));
|
||||
|
||||
LOGGER.info(CORE, "Found supplied mod coordinates [{}]", modClassPaths);
|
||||
|
||||
final List<Pair<Path, List<Path>>> explodedTargets = arguments.computeIfAbsent("explodedTargets", a -> new ArrayList<>());
|
||||
modClassPaths.forEach((modlabel,paths) -> explodedTargets.add(Pair.of(paths.get(0), paths.subList(1, paths.size()))));
|
||||
}
|
||||
|
||||
private Pair<String, Path> buildModPair(String[] splitString) {
|
||||
String modid = splitString.length == 1 ? "defaultmodid" : splitString[0];
|
||||
Path path = Paths.get(splitString[splitString.length - 1]);
|
||||
return Pair.of(modid, path);
|
||||
}
|
||||
|
||||
protected void validatePaths(final Path forgePath, final Path[] mcPaths, String forgeVersion, String mcVersion, String mcpVersion) {
|
||||
if (!Files.exists(forgePath)) {
|
||||
LOGGER.fatal(CORE, "Failed to find forge version {} for MC {} at {}", forgeVersion, mcVersion, forgePath);
|
||||
|
|
|
@ -84,6 +84,8 @@ public class FMLDevClientLaunchProvider extends FMLCommonLaunchHandler implement
|
|||
final Path forgemodstoml = LibraryFinder.findJarPathFor("META-INF/mods.toml", "forgemodstoml");
|
||||
((Map<String, List<Pair<Path,List<Path>>>>) arguments).computeIfAbsent("explodedTargets", a->new ArrayList<>()).
|
||||
add(Pair.of(forgemodstoml, Collections.singletonList(compiledClasses)));
|
||||
|
||||
processModClassesEnvironmentVariable((Map<String, List<Pair<Path, List<Path>>>>) arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -83,29 +83,13 @@ public abstract class FMLUserdevLaunchProvider extends FMLCommonLaunchHandler {
|
|||
throw new RuntimeException("wha?", e);
|
||||
}
|
||||
|
||||
LOGGER.fatal(CORE, "Got mod coordinates {} from env", System.getenv("MOD_CLASSES"));
|
||||
|
||||
// "a/b/;c/d/;" -> "modid%%c:\fish\pepper;modid%%c:\fish2\pepper2\;modid2%%c:\fishy\bums;modid2%%c:\hmm"
|
||||
final Map<String, List<Path>> modClassPaths = Arrays.stream(System.getenv("MOD_CLASSES").split(File.pathSeparator)).
|
||||
map(inp -> inp.split("%%", 2)).map(this::buildModPair).
|
||||
collect(Collectors.groupingBy(Pair::getLeft, Collectors.mapping(Pair::getRight, Collectors.toList())));
|
||||
|
||||
LOGGER.info(CORE, "Found supplied mod coordinates [{}]", modClassPaths);
|
||||
|
||||
final List<Pair<Path, List<Path>>> explodedTargets = ((Map<String, List<Pair<Path, List<Path>>>>) arguments).computeIfAbsent("explodedTargets", a -> new ArrayList<>());
|
||||
modClassPaths.forEach((modlabel,paths) -> explodedTargets.add(Pair.of(paths.get(0), paths.subList(1, paths.size()))));
|
||||
processModClassesEnvironmentVariable((Map<String, List<Pair<Path, List<Path>>>>) arguments);
|
||||
|
||||
// generics are gross yea?
|
||||
((Map)arguments).put("mavenRoots", mavenRoots);
|
||||
((Map)arguments).put("mods", mods);
|
||||
}
|
||||
|
||||
private Pair<String, Path> buildModPair(String[] splitString) {
|
||||
String modid = splitString.length == 1 ? "defaultmodid" : splitString[0];
|
||||
Path path = Paths.get(splitString[splitString.length - 1]);
|
||||
return Pair.of(modid, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validatePaths(final Path forgePath, final Path[] mcPaths, final String forgeVersion, final String mcVersion, final String mcpVersion) {
|
||||
|
||||
|
|
Loading…
Reference in a new issue