From 3adccc1a2bbdcaa67a0b7adf0992a5a828de3009 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 4 Feb 2024 15:50:47 -0500 Subject: [PATCH] [1.20.1] Prevent mixins from crashing the game when there are missing mods (#85) --- .../loading/moddiscovery/ModValidator.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/loader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModValidator.java b/loader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModValidator.java index 08e3275b5..6300b5061 100644 --- a/loader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModValidator.java +++ b/loader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModValidator.java @@ -15,11 +15,9 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; public class ModValidator { private static final Logger LOGGER = LogUtils.getLogger(); @@ -29,11 +27,13 @@ public class ModValidator { private LoadingModList loadingModList; private List brokenFiles; private final List discoveryErrorData; + private final List gameLibraries; public ModValidator(final Map> modFiles, final List brokenFiles, final List discoveryErrorData) { this.modFiles = modFiles; this.candidateMods = lst(modFiles.get(IModFile.Type.MOD)); - this.candidateMods.addAll(lst(modFiles.get(IModFile.Type.GAMELIBRARY))); + this.gameLibraries = lst(modFiles.get(IModFile.Type.GAMELIBRARY)); + this.candidateMods.addAll(this.gameLibraries); this.candidatePlugins = lst(modFiles.get(IModFile.Type.LANGPROVIDER)); this.candidatePlugins.addAll(lst(modFiles.get(IModFile.Type.LIBRARY))); this.discoveryErrorData = discoveryErrorData; @@ -72,7 +72,20 @@ public ITransformationService.Resource getPluginResources() { } public ITransformationService.Resource getModResources() { - return new ITransformationService.Resource(IModuleLayerManager.Layer.GAME, this.candidateMods.stream().map(IModFile::getSecureJar).toList()); + Stream modFileStream; + if (FMLEnvironment.production) { + // In production, only allow game libraries and/or mods in the loading mod list + // This prevents custom mixins from loading if there is a dependency error + // Usually, these mixins will break due to a missing class or AT, and that + // will prevent our error screen from ever becoming visible. + Set validMods = new HashSet<>(); + validMods.addAll(this.loadingModList.getModFiles().stream().map(ModFileInfo::getFile).toList()); + validMods.addAll(this.gameLibraries); + modFileStream = validMods.stream(); + } else { + modFileStream = this.candidateMods.stream(); + } + return new ITransformationService.Resource(IModuleLayerManager.Layer.GAME, modFileStream.map(IModFile::getSecureJar).toList()); } private List validateLanguages() {