Skip to content

Commit

Permalink
[1.20.1] Prevent mixins from crashing the game when there are missing…
Browse files Browse the repository at this point in the history
… mods (#85)
  • Loading branch information
embeddedt authored Feb 4, 2024
1 parent 94ac62c commit 3adccc1
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -29,11 +27,13 @@ public class ModValidator {
private LoadingModList loadingModList;
private List<IModFile> brokenFiles;
private final List<EarlyLoadingException.ExceptionData> discoveryErrorData;
private final List<ModFile> gameLibraries;

public ModValidator(final Map<IModFile.Type, List<ModFile>> modFiles, final List<IModFileInfo> brokenFiles, final List<EarlyLoadingException.ExceptionData> 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;
Expand Down Expand Up @@ -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<ModFile> 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<ModFile> 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<EarlyLoadingException.ExceptionData> validateLanguages() {
Expand Down

0 comments on commit 3adccc1

Please sign in to comment.