Handle null return from ResourcePackInfo.createResourcePack

This commit is contained in:
tterrag 2019-03-16 01:52:18 -04:00
parent d99a55a7d1
commit 1e34f331da
2 changed files with 22 additions and 10 deletions

View file

@ -19,14 +19,7 @@
package net.minecraftforge.fml.packs; package net.minecraftforge.fml.packs;
import net.minecraft.resources.IPackFinder; import static net.minecraftforge.fml.Logging.CORE;
import net.minecraft.resources.ResourcePackInfo;
import net.minecraft.resources.ResourcePackList;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -34,7 +27,19 @@ 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 static net.minecraftforge.fml.Logging.CORE; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraft.resources.IPackFinder;
import net.minecraft.resources.ResourcePackInfo;
import net.minecraft.resources.ResourcePackList;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.ModLoadingStage;
import net.minecraftforge.fml.ModLoadingWarning;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo;
import net.minecraftforge.forgespi.language.IModInfo;
public class ResourcePackLoader public class ResourcePackLoader
{ {
@ -63,8 +68,14 @@ public class ResourcePackLoader
{ {
for (Entry<ModFile, ModFileResourcePack> e : modResourcePacks.entrySet()) for (Entry<ModFile, ModFileResourcePack> e : modResourcePacks.entrySet())
{ {
final String name = "mod:" + e.getKey().getModInfos().get(0).getModId(); IModInfo mod = e.getKey().getModInfos().get(0);
final String name = "mod:" + mod.getModId();
final T packInfo = ResourcePackInfo.func_195793_a(name, true, e::getValue, factory, ResourcePackInfo.Priority.BOTTOM); final T packInfo = ResourcePackInfo.func_195793_a(name, true, e::getValue, factory, ResourcePackInfo.Priority.BOTTOM);
if (packInfo == null) {
// Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong
ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
continue;
}
e.getValue().setPackInfo(packInfo); e.getValue().setPackInfo(packInfo);
LOGGER.debug(CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath()); LOGGER.debug(CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath());
packList.put(name, packInfo); packList.put(name, packInfo);

View file

@ -31,6 +31,7 @@
"fml.modloading.cycle": "Detected a mod dependency cycle: {0}", "fml.modloading.cycle": "Detected a mod dependency cycle: {0}",
"fml.modloading.failedtoprocesswork":"{0,modinfo,name} ({0,modinfo,id}) encountered an error processing deferred work\n\u00a77{2,exc,msg}", "fml.modloading.failedtoprocesswork":"{0,modinfo,name} ({0,modinfo,id}) encountered an error processing deferred work\n\u00a77{2,exc,msg}",
"fml.modloading.brokenfile": "File {2} is not a valid mod file", "fml.modloading.brokenfile": "File {2} is not a valid mod file",
"fml.modloading.brokenresources": "File {2} failed to load a valid ResourcePackInfo",
"fml.messages.artifactversion.ornotinstalled":"{0,ornull,fml.messages.artifactversion.notinstalled}", "fml.messages.artifactversion.ornotinstalled":"{0,ornull,fml.messages.artifactversion.notinstalled}",
"fml.messages.artifactversion":"{0,ornull,fml.messages.artifactversion.none}", "fml.messages.artifactversion":"{0,ornull,fml.messages.artifactversion.none}",