Tidy up modcontainer building and discovery..

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2019-02-10 11:44:47 -05:00
parent b28a418bd9
commit dae5994e9d
No known key found for this signature in database
GPG key ID: 8EB3DF749553B1B7

View file

@ -32,6 +32,7 @@ import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.LoadingModList; import net.minecraftforge.fml.loading.LoadingModList;
import net.minecraftforge.fml.loading.moddiscovery.ModFile; import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo; import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo;
import net.minecraftforge.forgespi.language.IModLanguageProvider;
import net.minecraftforge.registries.GameData; import net.minecraftforge.registries.GameData;
import net.minecraftforge.registries.ObjectHolderRegistry; import net.minecraftforge.registries.ObjectHolderRegistry;
@ -41,6 +42,7 @@ import org.apache.logging.log4j.Logger;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -157,19 +159,22 @@ public class ModLoader
LOGGER.debug(LOADING, "ModContainer is {}", ModContainer.class.getClassLoader()); LOGGER.debug(LOADING, "ModContainer is {}", ModContainer.class.getClassLoader());
return modFile.getScanResult().getTargets().entrySet().stream(). return modFile.getScanResult().getTargets().entrySet().stream().
map(e-> { map(e-> buildModContainerFromTOML(modFile, modClassLoader, modInfoMap, e)).collect(Collectors.toList());
try { }
IModInfo info = modInfoMap.get(e.getKey());
if (info == null) { private ModContainer buildModContainerFromTOML(final ModFile modFile, final TransformingClassLoader modClassLoader, final Map<String, IModInfo> modInfoMap, final Map.Entry<String, ? extends IModLanguageProvider.IModLanguageLoader> idToProviderEntry) {
loadingExceptions.add(new ModLoadingException(null, ModLoadingStage.CONSTRUCT, "fml.modloading.missingmetadata", null, e.getKey())); try {
return null; final String modId = idToProviderEntry.getKey();
} final IModLanguageProvider.IModLanguageLoader languageLoader = idToProviderEntry.getValue();
return e.getValue().<ModContainer>loadMod(modInfoMap.get(e.getKey()), modClassLoader, modFile.getScanResult()); IModInfo info = Optional.ofNullable(modInfoMap.get(modId)).
} catch (ModLoadingException mle) { // throw a missing metadata error if there is no matching modid in the modInfoMap from the mods.toml file
loadingExceptions.add(mle); orElseThrow(()->new ModLoadingException(null, ModLoadingStage.CONSTRUCT, "fml.modloading.missingmetadata", null, modId));
return null; return languageLoader.loadMod(info, modClassLoader, modFile.getScanResult());
} } catch (ModLoadingException mle) {
}).collect(Collectors.toList()); // exceptions are caught and added to the error list for later handling. Null is returned here.
loadingExceptions.add(mle);
return null;
}
} }