Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.20.1] Prevent mixins from crashing the game when there are missing mods #85

Merged
merged 3 commits into from
Feb 4, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
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.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ModValidator {
private static final Logger LOGGER = LogUtils.getLogger();
Expand All @@ -29,11 +28,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 +73,18 @@ 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 = this.candidateMods.stream();
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<IModFile> validMods = new HashSet<>();
validMods.addAll(this.loadingModList.getModFiles().stream().map(ModFileInfo::getFile).toList());
validMods.addAll(this.gameLibraries);
modFileStream = modFileStream.filter(validMods::contains);
Technici4n marked this conversation as resolved.
Show resolved Hide resolved
}
return new ITransformationService.Resource(IModuleLayerManager.Layer.GAME, modFileStream.map(IModFile::getSecureJar).toList());
}

private List<EarlyLoadingException.ExceptionData> validateLanguages() {
Expand Down
Loading