Tidy up modcontainer building and discovery..
Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
b28a418bd9
commit
dae5994e9d
1 changed files with 18 additions and 13 deletions
|
@ -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) {
|
|
||||||
loadingExceptions.add(new ModLoadingException(null, ModLoadingStage.CONSTRUCT, "fml.modloading.missingmetadata", null, e.getKey()));
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return e.getValue().<ModContainer>loadMod(modInfoMap.get(e.getKey()), modClassLoader, modFile.getScanResult());
|
|
||||||
|
private ModContainer buildModContainerFromTOML(final ModFile modFile, final TransformingClassLoader modClassLoader, final Map<String, IModInfo> modInfoMap, final Map.Entry<String, ? extends IModLanguageProvider.IModLanguageLoader> idToProviderEntry) {
|
||||||
|
try {
|
||||||
|
final String modId = idToProviderEntry.getKey();
|
||||||
|
final IModLanguageProvider.IModLanguageLoader languageLoader = idToProviderEntry.getValue();
|
||||||
|
IModInfo info = Optional.ofNullable(modInfoMap.get(modId)).
|
||||||
|
// throw a missing metadata error if there is no matching modid in the modInfoMap from the mods.toml file
|
||||||
|
orElseThrow(()->new ModLoadingException(null, ModLoadingStage.CONSTRUCT, "fml.modloading.missingmetadata", null, modId));
|
||||||
|
return languageLoader.loadMod(info, modClassLoader, modFile.getScanResult());
|
||||||
} catch (ModLoadingException mle) {
|
} catch (ModLoadingException mle) {
|
||||||
|
// exceptions are caught and added to the error list for later handling. Null is returned here.
|
||||||
loadingExceptions.add(mle);
|
loadingExceptions.add(mle);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue