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.moddiscovery ;
import cpw.mods.modlauncher.ServiceLoaderStreamUtils ;
2018-04-07 15:48:43 +00:00
import net.minecraftforge.fml.loading.FMLLoader ;
2018-06-15 19:03:35 +00:00
import net.minecraftforge.fml.loading.LoadingModList ;
2018-06-06 15:37:56 +00:00
import net.minecraftforge.fml.loading.ModSorter ;
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
2018-12-31 21:33:54 +00:00
import java.nio.file.Path ;
2018-03-25 15:59:43 +00:00
import java.util.Collection ;
2018-09-24 04:07:33 +00:00
import java.util.Collections ;
2018-06-06 15:37:56 +00:00
import java.util.Iterator ;
2018-03-25 15:59:43 +00:00
import java.util.List ;
import java.util.Map ;
import java.util.ServiceLoader ;
import java.util.stream.Collectors ;
2018-12-31 21:33:54 +00:00
import static net.minecraftforge.fml.loading.LogMarkers.SCAN ;
2018-03-25 15:59:43 +00:00
public class ModDiscoverer {
2018-08-27 17:10:07 +00:00
private static final Logger LOGGER = LogManager . getLogger ( ) ;
2018-03-25 15:59:43 +00:00
private final ServiceLoader < IModLocator > locators ;
private final List < IModLocator > locatorList ;
2018-12-31 21:33:54 +00:00
public ModDiscoverer ( Map < String , ? > arguments ) {
2018-03-25 15:59:43 +00:00
locators = ServiceLoader . load ( IModLocator . class ) ;
locatorList = ServiceLoaderStreamUtils . toList ( this . locators ) ;
2018-12-31 21:33:54 +00:00
locatorList . forEach ( l - > l . initArguments ( arguments ) ) ;
2018-08-27 17:10:07 +00:00
LOGGER . debug ( SCAN , " Found Mod Locators : {} " , ( ) - > locatorList . stream ( ) . map ( iModLocator - > " ( " + iModLocator . name ( ) + " : " + iModLocator . getClass ( ) . getPackage ( ) . getImplementationVersion ( ) + " ) " ) . collect ( Collectors . joining ( " , " ) ) ) ;
2018-03-25 15:59:43 +00:00
}
ModDiscoverer ( List < IModLocator > locatorList ) {
this . locatorList = locatorList ;
this . locators = null ;
}
public BackgroundScanHandler discoverMods ( ) {
2018-08-27 17:10:07 +00:00
LOGGER . debug ( SCAN , " Scanning for mods and other resources to load. We know {} ways to find mods " , locatorList . size ( ) ) ;
2018-03-25 15:59:43 +00:00
final Map < ModFile . Type , List < ModFile > > modFiles = locatorList . stream ( )
2018-08-27 17:10:07 +00:00
. peek ( loc - > LOGGER . debug ( SCAN , " Trying locator {} " , loc ) )
2018-03-25 15:59:43 +00:00
. map ( IModLocator : : scanMods )
. flatMap ( Collection : : stream )
2018-08-27 17:10:07 +00:00
. peek ( mf - > LOGGER . debug ( SCAN , " Found mod file {} of type {} with locator {} " , mf . getFileName ( ) , mf . getType ( ) , mf . getLocator ( ) ) )
2018-03-25 15:59:43 +00:00
. collect ( Collectors . groupingBy ( ModFile : : getType ) ) ;
2018-04-07 15:48:43 +00:00
FMLLoader . getLanguageLoadingProvider ( ) . addAdditionalLanguages ( modFiles . get ( ModFile . Type . LANGPROVIDER ) ) ;
2018-03-25 15:59:43 +00:00
BackgroundScanHandler backgroundScanHandler = new BackgroundScanHandler ( ) ;
2018-09-24 04:07:33 +00:00
final List < ModFile > mods = modFiles . getOrDefault ( ModFile . Type . MOD , Collections . emptyList ( ) ) ;
2018-06-06 15:37:56 +00:00
for ( Iterator < ModFile > iterator = mods . iterator ( ) ; iterator . hasNext ( ) ; )
{
ModFile mod = iterator . next ( ) ;
if ( ! mod . identifyMods ( ) ) {
2018-08-27 17:10:07 +00:00
LOGGER . debug ( SCAN , " Removing file {} from further analysis - it is invalid " , mod ) ;
2018-06-06 15:37:56 +00:00
iterator . remove ( ) ;
}
}
2018-08-27 17:10:07 +00:00
LOGGER . debug ( SCAN , " Found {} mod files with {} mods " , mods : : size , ( ) - > mods . stream ( ) . mapToInt ( mf - > mf . getModInfos ( ) . size ( ) ) . sum ( ) ) ;
2018-06-15 19:03:35 +00:00
final LoadingModList loadingModList = ModSorter . sort ( mods ) ;
loadingModList . addCoreMods ( ) ;
loadingModList . addAccessTransformers ( ) ;
loadingModList . addForScanning ( backgroundScanHandler ) ;
2018-03-25 15:59:43 +00:00
return backgroundScanHandler ;
}
2018-12-31 21:33:54 +00:00
public void addExplodedTarget ( final Path compiledClasses , final Path forgemodstoml ) {
}
2018-03-25 15:59:43 +00:00
}