From f4bab8b8c1c1d315e3773b366bc7d094c7e067e5 Mon Sep 17 00:00:00 2001 From: cpw Date: Fri, 27 Sep 2019 17:42:24 -0400 Subject: [PATCH] Integrate modlauncher changes for mixin. Signed-off-by: cpw --- build.gradle | 2 +- .../fml/loading/FMLClientLaunchProvider.java | 5 ++++ .../minecraftforge/fml/loading/FMLLoader.java | 6 +++-- .../fml/loading/FMLServerLaunchProvider.java | 5 ++++ .../fml/loading/FMLServiceProvider.java | 25 +++++++++++++++++-- .../moddiscovery/BackgroundScanHandler.java | 10 +++++++- .../loading/moddiscovery/ModDiscoverer.java | 2 +- 7 files changed, 48 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index e4dce31d2..8054a828c 100644 --- a/build.gradle +++ b/build.gradle @@ -405,7 +405,7 @@ project(':forge') { installer 'org.ow2.asm:asm:6.2' installer 'org.ow2.asm:asm-commons:6.2' installer 'org.ow2.asm:asm-tree:6.2' - installer 'cpw.mods:modlauncher:3.2.+' + installer 'cpw.mods:modlauncher:4.0.+' installer 'cpw.mods:grossjava9hacks:1.1.+' installer 'net.minecraftforge:accesstransformers:1.0.+:shadowed' installer 'net.minecraftforge:eventbus:1.0.+:service' diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLClientLaunchProvider.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLClientLaunchProvider.java index e7e08db46..1d48b6002 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLClientLaunchProvider.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLClientLaunchProvider.java @@ -83,4 +83,9 @@ public class FMLClientLaunchProvider extends FMLCommonLaunchHandler implements I protected String getNaming() { return "srg"; } + + @Override + public Path[] getPaths() { + return FMLLoader.getMCPaths(); + } } diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLLoader.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLLoader.java index 268b1e730..70d3b998a 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLLoader.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLLoader.java @@ -36,6 +36,7 @@ import net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer; import net.minecraftforge.fml.loading.moddiscovery.ModFile; import net.minecraftforge.forgespi.Environment; import net.minecraftforge.forgespi.coremod.ICoreModProvider; +import net.minecraftforge.forgespi.locating.IModFile; import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -85,7 +86,7 @@ public class FMLLoader LOGGER.debug(CORE,"FML {} loading", version); final Package modLauncherPackage = ITransformationService.class.getPackage(); LOGGER.debug(CORE,"FML found ModLauncher version : {}", modLauncherPackage.getImplementationVersion()); - if (!modLauncherPackage.isCompatibleWith("2.0")) { + if (!modLauncherPackage.isCompatibleWith("4.0")) { LOGGER.fatal(CORE,"Found incompatible ModLauncher specification : {}, version {} from {}", modLauncherPackage.getSpecificationVersion(), modLauncherPackage.getImplementationVersion(), modLauncherPackage.getImplementationVendor()); throw new IncompatibleEnvironmentException("Incompatible modlauncher found "+modLauncherPackage.getSpecificationVersion()); } @@ -195,12 +196,13 @@ public class FMLLoader runtimeDistCleaner.getExtension().accept(dist); } - public static void beginModScan(final Map arguments) + public static Map> beginModScan(final Map arguments) { LOGGER.debug(SCAN,"Scanning for Mod Locators"); modDiscoverer = new ModDiscoverer(arguments); final BackgroundScanHandler backgroundScanHandler = modDiscoverer.discoverMods(); loadingModList = backgroundScanHandler.getLoadingModList(); + return backgroundScanHandler.getModFiles(); } public static ICoreModProvider getCoreModProvider() { diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLServerLaunchProvider.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLServerLaunchProvider.java index 608dfc407..6645e0721 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLServerLaunchProvider.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLServerLaunchProvider.java @@ -26,6 +26,7 @@ import net.minecraftforge.api.distmarker.Dist; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -78,4 +79,8 @@ public class FMLServerLaunchProvider extends FMLCommonLaunchHandler implements I return "srg"; } + @Override + public Path[] getPaths() { + return FMLLoader.getMCPaths(); + } } diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLServiceProvider.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLServiceProvider.java index 5513b75d8..e9ca608f4 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLServiceProvider.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLServiceProvider.java @@ -25,13 +25,23 @@ import cpw.mods.modlauncher.api.ITransformer; import cpw.mods.modlauncher.api.IncompatibleEnvironmentException; import joptsimple.ArgumentAcceptingOptionSpec; import joptsimple.OptionSpecBuilder; +import net.minecraftforge.fml.loading.moddiscovery.ModFile; import net.minecraftforge.forgespi.Environment; +import net.minecraftforge.forgespi.locating.IModFile; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nonnull; -import java.util.*; +import java.nio.file.Path; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.function.BiFunction; +import java.util.stream.Collectors; import static net.minecraftforge.fml.loading.LogMarkers.CORE; @@ -86,8 +96,19 @@ public class FMLServiceProvider implements ITransformationService @Override public void beginScanning(final IEnvironment environment) { + throw new IllegalStateException("WHY ARE YOU HERE??????"); + } + + @Override + public List> runScan(final IEnvironment environment) { LOGGER.debug(CORE,"Initiating mod scan"); - FMLLoader.beginModScan(arguments); + final Map> foundFiles = FMLLoader.beginModScan(arguments); + return foundFiles + .values() + .stream() + .flatMap(Collection::stream) + .map(modFile -> new AbstractMap.SimpleImmutableEntry<>(modFile.getFileName(), modFile.getFilePath())) + .collect(Collectors.toList()); } @Override diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/BackgroundScanHandler.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/BackgroundScanHandler.java index 3073e6eb7..037fec934 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/BackgroundScanHandler.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/BackgroundScanHandler.java @@ -21,11 +21,13 @@ package net.minecraftforge.fml.loading.moddiscovery; import net.minecraftforge.forgespi.language.ModFileScanData; import net.minecraftforge.fml.loading.LoadingModList; +import net.minecraftforge.forgespi.locating.IModFile; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -40,9 +42,11 @@ public class BackgroundScanHandler private final List pendingFiles; private final List scannedFiles; private final List allFiles; + private final Map> modFiles; private LoadingModList loadingModList; - public BackgroundScanHandler() { + public BackgroundScanHandler(final Map> modFiles) { + this.modFiles = modFiles; modContentScanner = Executors.newSingleThreadExecutor(r -> { final Thread thread = Executors.defaultThreadFactory().newThread(r); thread.setDaemon(true); @@ -53,6 +57,10 @@ public class BackgroundScanHandler allFiles = new ArrayList<>(); } + public Map> getModFiles() { + return modFiles; + } + public void submitForScanning(final ModFile file) { if (modContentScanner.isShutdown()) { throw new IllegalStateException("Scanner has shutdown"); diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java index f9338208a..bd5452a04 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java @@ -89,7 +89,7 @@ public class ModDiscoverer { .collect(Collectors.groupingBy(IModFile::getType)); FMLLoader.getLanguageLoadingProvider().addAdditionalLanguages(modFiles.get(IModFile.Type.LANGPROVIDER)); - BackgroundScanHandler backgroundScanHandler = new BackgroundScanHandler(); + BackgroundScanHandler backgroundScanHandler = new BackgroundScanHandler(modFiles); final List mods = modFiles.getOrDefault(IModFile.Type.MOD, Collections.emptyList()); final List brokenFiles = new ArrayList<>(); for (Iterator iterator = mods.iterator(); iterator.hasNext(); )