diff --git a/src/main/java/net/minecraftforge/fml/loading/FMLCommonLaunchHandler.java b/src/main/java/net/minecraftforge/fml/loading/FMLCommonLaunchHandler.java new file mode 100644 index 0000000000..0ae4095b1e --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/loading/FMLCommonLaunchHandler.java @@ -0,0 +1,30 @@ +/* + * Minecraft Forge + * Copyright (c) 2018. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.fml.loading; + +import cpw.mods.modlauncher.api.IEnvironment; + +public abstract class FMLCommonLaunchHandler +{ + public void setup(final IEnvironment environment) + { + // We need to check for deobf and patched jar here and if not, build one. + } +} diff --git a/src/main/java/net/minecraftforge/fml/loading/FMLDevLaunchProvider.java b/src/main/java/net/minecraftforge/fml/loading/FMLDevLaunchProvider.java index 050a126234..8c69217cd8 100644 --- a/src/main/java/net/minecraftforge/fml/loading/FMLDevLaunchProvider.java +++ b/src/main/java/net/minecraftforge/fml/loading/FMLDevLaunchProvider.java @@ -19,6 +19,7 @@ package net.minecraftforge.fml.loading; +import cpw.mods.modlauncher.api.IEnvironment; import cpw.mods.modlauncher.api.ILaunchHandlerService; import net.minecraft.client.main.Main; @@ -27,7 +28,10 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.concurrent.Callable; -public class FMLDevLaunchProvider implements ILaunchHandlerService +import static net.minecraftforge.fml.Logging.CORE; +import static net.minecraftforge.fml.Logging.fmlLog; + +public class FMLDevLaunchProvider extends FMLCommonLaunchHandler implements ILaunchHandlerService { @Override public String name() @@ -58,4 +62,10 @@ public class FMLDevLaunchProvider implements ILaunchHandlerService return null; }; } + + @Override + public void setup(IEnvironment environment) + { + fmlLog.debug(CORE, "No jar creation necessary. Launch is dev environment"); + } } diff --git a/src/main/java/net/minecraftforge/fml/loading/FMLLaunchProvider.java b/src/main/java/net/minecraftforge/fml/loading/FMLLaunchProvider.java index 484ac2a592..5dc0d45c4a 100644 --- a/src/main/java/net/minecraftforge/fml/loading/FMLLaunchProvider.java +++ b/src/main/java/net/minecraftforge/fml/loading/FMLLaunchProvider.java @@ -25,7 +25,7 @@ import net.minecraft.client.main.Main; import java.nio.file.Path; import java.util.concurrent.Callable; -public class FMLLaunchProvider implements ILaunchHandlerService +public class FMLLaunchProvider extends FMLCommonLaunchHandler implements ILaunchHandlerService { @Override public String name() diff --git a/src/main/java/net/minecraftforge/fml/loading/FMLLoader.java b/src/main/java/net/minecraftforge/fml/loading/FMLLoader.java index c46a222e0b..8790878884 100644 --- a/src/main/java/net/minecraftforge/fml/loading/FMLLoader.java +++ b/src/main/java/net/minecraftforge/fml/loading/FMLLoader.java @@ -20,6 +20,7 @@ package net.minecraftforge.fml.loading; import cpw.mods.modlauncher.api.IEnvironment; +import cpw.mods.modlauncher.api.ILaunchHandlerService; import cpw.mods.modlauncher.api.ITransformationService; import cpw.mods.modlauncher.api.IncompatibleEnvironmentException; import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; @@ -89,6 +90,24 @@ public class FMLLoader languageLoadingProvider = new LanguageLoadingProvider(); } + static void setupLaunchHandler(final IEnvironment environment) throws IncompatibleEnvironmentException + { + final String launchTarget = environment.getProperty(IEnvironment.Keys.LAUNCHTARGET.get()).orElse("MISSING"); + final Optional launchHandler = environment.findLaunchHandler(launchTarget); + fmlLog.debug(CORE, "Using {} as launch service", launchTarget); + if (!launchHandler.isPresent()) { + fmlLog.error(CORE,"Missing LaunchHandler {}, cannot continue", launchTarget); + throw new IncompatibleEnvironmentException("Missing launch handler"); + } + + if (!(launchHandler.get() instanceof FMLCommonLaunchHandler)) { + fmlLog.error(CORE, "Incompatible Launch handler found - type {}, cannot continue", launchHandler.get().getClass().getName()); + throw new IncompatibleEnvironmentException("Incompatible launch handler found"); + } + + FMLCommonLaunchHandler commonLaunchHandler = (FMLCommonLaunchHandler)launchHandler.get(); + commonLaunchHandler.setup(environment); + } public static void beginModScan() { fmlLog.debug(SCAN,"Scanning for Mod Locators"); diff --git a/src/main/java/net/minecraftforge/fml/loading/FMLServiceProvider.java b/src/main/java/net/minecraftforge/fml/loading/FMLServiceProvider.java index 8c613edfa8..c40cd94287 100644 --- a/src/main/java/net/minecraftforge/fml/loading/FMLServiceProvider.java +++ b/src/main/java/net/minecraftforge/fml/loading/FMLServiceProvider.java @@ -20,6 +20,7 @@ package net.minecraftforge.fml.loading; import cpw.mods.modlauncher.api.IEnvironment; +import cpw.mods.modlauncher.api.ILaunchHandlerService; import cpw.mods.modlauncher.api.ITransformationService; import cpw.mods.modlauncher.api.ITransformer; import cpw.mods.modlauncher.api.IncompatibleEnvironmentException; @@ -31,6 +32,7 @@ import net.minecraftforge.fml.common.FMLPaths; import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.function.BiFunction;