2018-03-25 15:59:43 +00:00
/ *
* Minecraft Forge
2019-02-10 22:57:03 +00:00
* Copyright ( c ) 2016 - 2019 .
2018-03-25 15:59:43 +00:00
*
* 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 ;
import cpw.mods.modlauncher.api.ITransformationService ;
import cpw.mods.modlauncher.api.ITransformer ;
import cpw.mods.modlauncher.api.IncompatibleEnvironmentException ;
import joptsimple.ArgumentAcceptingOptionSpec ;
import joptsimple.OptionSpecBuilder ;
2019-01-14 03:51:36 +00:00
import net.minecraftforge.forgespi.Environment ;
2018-08-27 17:10:07 +00:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2018-03-25 15:59:43 +00:00
import javax.annotation.Nonnull ;
2018-12-31 21:33:54 +00:00
import java.util.* ;
2018-03-25 15:59:43 +00:00
import java.util.function.BiFunction ;
2018-12-31 21:33:54 +00:00
import static net.minecraftforge.fml.loading.LogMarkers.CORE ;
2018-03-25 15:59:43 +00:00
public class FMLServiceProvider implements ITransformationService
{
2018-08-27 17:10:07 +00:00
private static final Logger LOGGER = LogManager . getLogger ( ) ;
2018-03-25 15:59:43 +00:00
private ArgumentAcceptingOptionSpec < String > modsOption ;
private ArgumentAcceptingOptionSpec < String > modListsOption ;
2018-12-31 21:33:54 +00:00
private ArgumentAcceptingOptionSpec < String > mavenRootsOption ;
private ArgumentAcceptingOptionSpec < String > forgeOption ;
private ArgumentAcceptingOptionSpec < String > mcOption ;
2019-01-01 21:50:04 +00:00
private ArgumentAcceptingOptionSpec < String > forgeGroupOption ;
private ArgumentAcceptingOptionSpec < String > mcpOption ;
2019-01-08 08:29:36 +00:00
private ArgumentAcceptingOptionSpec < String > mappingsOption ;
2018-03-25 15:59:43 +00:00
private List < String > modsArgumentList ;
private List < String > modListsArgumentList ;
2018-12-31 21:33:54 +00:00
private List < String > mavenRootsArgumentList ;
private String targetForgeVersion ;
private String targetMcVersion ;
2019-01-01 21:50:04 +00:00
private String targetMcpVersion ;
2019-01-08 08:29:36 +00:00
private String targetMcpMappings ;
2019-01-01 21:50:04 +00:00
private String targetForgeGroup ;
2018-03-25 15:59:43 +00:00
@Override
public String name ( )
{
return " fml " ;
}
@Override
public void initialize ( IEnvironment environment )
{
2018-08-27 17:10:07 +00:00
LOGGER . debug ( CORE , " Setting up basic FML game directories " ) ;
2018-03-25 15:59:43 +00:00
FMLPaths . setup ( environment ) ;
2018-08-27 17:10:07 +00:00
LOGGER . debug ( CORE , " Loading configuration " ) ;
2018-03-25 15:59:43 +00:00
FMLConfig . load ( ) ;
2018-12-31 21:33:54 +00:00
final Map < String , Object > arguments = new HashMap < > ( ) ;
arguments . put ( " modLists " , modListsArgumentList ) ;
arguments . put ( " mods " , modsArgumentList ) ;
arguments . put ( " mavenRoots " , mavenRootsArgumentList ) ;
arguments . put ( " forgeVersion " , targetForgeVersion ) ;
2019-01-01 21:50:04 +00:00
arguments . put ( " forgeGroup " , targetForgeGroup ) ;
2018-12-31 21:33:54 +00:00
arguments . put ( " mcVersion " , targetMcVersion ) ;
2019-01-01 21:50:04 +00:00
arguments . put ( " mcpVersion " , targetMcpVersion ) ;
2019-01-08 08:29:36 +00:00
arguments . put ( " mcpMappings " , targetMcpMappings ) ;
2018-08-27 17:10:07 +00:00
LOGGER . debug ( CORE , " Preparing launch handler " ) ;
2018-12-31 21:33:54 +00:00
FMLLoader . setupLaunchHandler ( environment , arguments ) ;
2019-01-14 03:51:36 +00:00
FMLEnvironment . setupInteropEnvironment ( environment ) ;
Environment . build ( environment ) ;
2018-08-27 17:10:07 +00:00
LOGGER . debug ( CORE , " Initiating mod scan " ) ;
2018-12-31 21:33:54 +00:00
FMLLoader . beginModScan ( arguments ) ;
2018-03-25 15:59:43 +00:00
}
@Override
public void onLoad ( IEnvironment environment , Set < String > otherServices ) throws IncompatibleEnvironmentException
{
2018-04-07 03:58:48 +00:00
FMLLoader . onInitialLoad ( environment , otherServices ) ;
2018-03-25 15:59:43 +00:00
}
@Override
public void arguments ( BiFunction < String , String , OptionSpecBuilder > argumentBuilder )
{
2018-12-31 21:33:54 +00:00
forgeOption = argumentBuilder . apply ( " forgeVersion " , " Forge Version number " ) . withRequiredArg ( ) . ofType ( String . class ) . required ( ) ;
2019-01-01 21:50:04 +00:00
forgeGroupOption = argumentBuilder . apply ( " forgeGroup " , " Forge Group (for testing) " ) . withRequiredArg ( ) . ofType ( String . class ) . defaultsTo ( " net.minecraftforge " ) ;
2018-12-31 21:33:54 +00:00
mcOption = argumentBuilder . apply ( " mcVersion " , " Minecraft Version number " ) . withRequiredArg ( ) . ofType ( String . class ) . required ( ) ;
2019-01-01 21:50:04 +00:00
mcpOption = argumentBuilder . apply ( " mcpVersion " , " MCP Version number " ) . withRequiredArg ( ) . ofType ( String . class ) . required ( ) ;
2019-01-08 08:29:36 +00:00
mappingsOption = argumentBuilder . apply ( " mcpMappings " , " MCP Mappings Channel and Version " ) . withRequiredArg ( ) . ofType ( String . class ) ;
2018-03-25 15:59:43 +00:00
modsOption = argumentBuilder . apply ( " mods " , " List of mods to add " ) . withRequiredArg ( ) . ofType ( String . class ) . withValuesSeparatedBy ( " , " ) ;
modListsOption = argumentBuilder . apply ( " modLists " , " JSON modlists " ) . withRequiredArg ( ) . ofType ( String . class ) . withValuesSeparatedBy ( " , " ) ;
2018-12-31 21:33:54 +00:00
mavenRootsOption = argumentBuilder . apply ( " mavenRoots " , " Maven root directories " ) . withRequiredArg ( ) . ofType ( String . class ) . withValuesSeparatedBy ( " , " ) ;
2018-03-25 15:59:43 +00:00
}
@Override
public void argumentValues ( OptionResult option )
{
modsArgumentList = option . values ( modsOption ) ;
modListsArgumentList = option . values ( modListsOption ) ;
2018-12-31 21:33:54 +00:00
mavenRootsArgumentList = option . values ( mavenRootsOption ) ;
targetForgeVersion = option . value ( forgeOption ) ;
2019-01-01 21:50:04 +00:00
targetForgeGroup = option . value ( forgeGroupOption ) ;
2018-12-31 21:33:54 +00:00
targetMcVersion = option . value ( mcOption ) ;
2019-01-01 21:50:04 +00:00
targetMcpVersion = option . value ( mcpOption ) ;
2019-01-08 08:29:36 +00:00
targetMcpMappings = option . value ( mappingsOption ) ;
2018-03-25 15:59:43 +00:00
}
@Nonnull
@Override
public List < ITransformer > transformers ( )
{
2018-08-27 17:10:07 +00:00
LOGGER . debug ( CORE , " Loading coremod transformers " ) ;
2018-04-07 15:48:43 +00:00
return new ArrayList < > ( FMLLoader . getCoreModProvider ( ) . getCoreModTransformers ( ) ) ;
2018-03-25 15:59:43 +00:00
}
}