diff --git a/build.gradle b/build.gradle index c2ca3fed7b..8d6f7240b7 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ ext { MAPPING_VERSION = '1.18.2' MC_VERSION = '1.18.2' MCP_VERSION = '20220404.173914' - SPI_VERSION = '4.0.10' + SPI_VERSION = '4.0.15-4.x' ACCESSTRANSFORMERS_VERSION = '8.0.4' COREMODS_VERSION = '5.0.1' EVENTBUS_VERSION = '5.0.3' @@ -58,6 +58,7 @@ ext { ASM_VERSION = '9.2' INSTALLER_VERSION = '2.1.+' MIXIN_VERSION = '0.8.5' + JARJAR_VERSION = '0.2.26' GIT_INFO = gradleutils.gitInfo VERSION = gradleutils.getFilteredMCTagOffsetBranchVersion(true, '[0-9]', MC_VERSION) @@ -274,6 +275,7 @@ def sharedDeps = { installer 'org.jline:jline-terminal:3.12.+' //Dep of TerminaalConsoleeAppender installer "org.spongepowered:mixin:${MIXIN_VERSION}" installer 'org.openjdk.nashorn:nashorn-core:15.3' + installer "net.minecraftforge:JarJar:${JARJAR_VERSION}" /* installer 'org.lwjgl:lwjgl:3.2.2' diff --git a/fmlcore/src/main/java/net/minecraftforge/fml/ModLoader.java b/fmlcore/src/main/java/net/minecraftforge/fml/ModLoader.java index 521ab8acb0..dc05a8b61f 100644 --- a/fmlcore/src/main/java/net/minecraftforge/fml/ModLoader.java +++ b/fmlcore/src/main/java/net/minecraftforge/fml/ModLoader.java @@ -11,11 +11,11 @@ import net.minecraftforge.fml.event.IModBusEvent; import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.fml.loading.LoadingModList; import net.minecraftforge.fml.loading.moddiscovery.InvalidModIdentifier; -import net.minecraftforge.fml.loading.moddiscovery.ModFile; import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo; import net.minecraftforge.fml.loading.progress.StartupMessageManager; import net.minecraftforge.forgespi.language.IModInfo; import net.minecraftforge.forgespi.language.IModLanguageProvider; +import net.minecraftforge.forgespi.locating.IModFile; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -28,6 +28,7 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.Executor; +import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; @@ -222,7 +223,7 @@ public class ModLoader } } - private List buildMods(final ModFile modFile) + private List buildMods(final IModFile modFile) { final Map modInfoMap = modFile.getModFileInfo().getMods().stream().collect(Collectors.toMap(IModInfo::getModId, Function.identity())); @@ -244,7 +245,7 @@ public class ModLoader return containers.stream().filter(mc -> mc.modLoadingStage != ModLoadingStage.ERROR).collect(Collectors.toList()); } - private ModContainer buildModContainerFromTOML(final ModFile modFile, final Map modInfoMap, final Map.Entry idToProviderEntry) { + private ModContainer buildModContainerFromTOML(final IModFile modFile, final Map modInfoMap, final Map.Entry idToProviderEntry) { try { final String modId = idToProviderEntry.getKey(); final IModLanguageProvider.IModLanguageLoader languageLoader = idToProviderEntry.getValue(); diff --git a/fmlloader/build.gradle b/fmlloader/build.gradle index d32b45e915..7249d4cc99 100644 --- a/fmlloader/build.gradle +++ b/fmlloader/build.gradle @@ -16,7 +16,7 @@ dependencies { api("org.ow2.asm:asm:${ASM_VERSION}") api("org.ow2.asm:asm-tree:${ASM_VERSION}") api("org.ow2.asm:asm-commons:${ASM_VERSION}") - api('net.minecraftforge:forgespi:4.0.+') + api("net.minecraftforge:forgespi:${SPI_VERSION}") api('org.apache.logging.log4j:log4j-api:2.17.0') api('org.slf4j:slf4j-api:1.8.0-beta4') api('com.google.guava:guava:21.0') @@ -27,6 +27,7 @@ dependencies { api('com.electronwill.night-config:toml:3.6.4') api('cpw.mods:modlauncher:9.0.+') api('net.minecraftforge:coremods:5.0.+') + api "net.minecraftforge:JarJar:${JARJAR_VERSION}" implementation("cpw.mods:securejarhandler:${SECUREJARHANDLER_VERSION}") implementation('org.apache.logging.log4j:log4j-core:2.17.0') annotationProcessor('org.apache.logging.log4j:log4j-core:2.17.0') diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/EarlyLoadingException.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/EarlyLoadingException.java index e151f2b146..371fe9e44b 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/EarlyLoadingException.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/EarlyLoadingException.java @@ -47,7 +47,7 @@ public class EarlyLoadingException extends RuntimeException { return errorMessages; } - EarlyLoadingException(final String message, final Throwable originalException, List errorMessages) { + public EarlyLoadingException(final String message, final Throwable originalException, List errorMessages) { super(message, originalException); this.errorMessages = errorMessages; } diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/ModSorter.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/ModSorter.java index b20f161182..9ba59688dc 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/ModSorter.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/ModSorter.java @@ -9,7 +9,6 @@ import com.google.common.graph.GraphBuilder; import com.google.common.graph.MutableGraph; import cpw.mods.jarhandling.SecureJar; import net.minecraftforge.fml.loading.moddiscovery.MinecraftLocator; -import net.minecraftforge.forgespi.language.IModFileInfo; import net.minecraftforge.forgespi.language.IModInfo; import net.minecraftforge.fml.loading.EarlyLoadingException.ExceptionData; import net.minecraftforge.fml.loading.moddiscovery.ModFile; @@ -17,7 +16,6 @@ import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo; import net.minecraftforge.fml.loading.moddiscovery.ModInfo; import net.minecraftforge.fml.loading.toposort.CyclePresentException; import net.minecraftforge.fml.loading.toposort.TopologicalSort; -import net.minecraftforge.forgespi.locating.IModFile; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -36,14 +34,15 @@ import static net.minecraftforge.fml.loading.LogMarkers.LOADING; public class ModSorter { private static final Logger LOGGER = LogManager.getLogger(); + private final UniqueModListBuilder uniqueModListBuilder; private List modFiles; private List sortedList; - private Map modIdNameLookup; + private Map modIdNameLookup; private List systemMods; private ModSorter(final List modFiles) { - this.modFiles = modFiles; + this.uniqueModListBuilder = new UniqueModListBuilder(modFiles); } public static LoadingModList sort(List mods, final List errors) @@ -78,11 +77,12 @@ public class ModSorter // lambdas are identity based, so sorting them is impossible unless you hold reference to them final MutableGraph graph = GraphBuilder.directed().build(); AtomicInteger counter = new AtomicInteger(); - Map infos = modFiles.stream() + Map infos = modFiles.stream() .map(ModFile::getModFileInfo) .filter(ModFileInfo.class::isInstance) + .map(ModFileInfo.class::cast) .collect(toMap(Function.identity(), e -> counter.incrementAndGet())); - infos.keySet().forEach(i -> graph.addNode((ModFileInfo) i)); + infos.keySet().forEach(graph::addNode); modFiles.stream() .map(ModFile::getModInfos) .mapMulti(Iterable::forEach) @@ -125,10 +125,9 @@ public class ModSorter private void addDependency(MutableGraph topoGraph, IModInfo.ModVersion dep) { final ModFileInfo self = (ModFileInfo)dep.getOwner().getOwningFile(); - final ModInfo targetModInfo = modIdNameLookup.get(dep.getModId()); + final IModInfo targetModInfo = modIdNameLookup.get(dep.getModId()); // soft dep that doesn't exist. Just return. No edge required. - if (targetModInfo == null) return; - final ModFileInfo target = targetModInfo.getOwningFile(); + if (targetModInfo == null || !(targetModInfo.getOwningFile() instanceof final ModFileInfo target)) return; if (self == target) return; // in case a jar has two mods that have dependencies between switch (dep.getOrdering()) { @@ -139,10 +138,22 @@ public class ModSorter private void buildUniqueList() { - // Collect mod files by module name. This will be used for deduping purposes - final Map> modFilesByFirstId = modFiles.stream() - .collect(groupingBy(mf -> mf.getModFileInfo().moduleName())); + final UniqueModListBuilder.UniqueModListData uniqueModListData = uniqueModListBuilder.buildUniqueList(); + this.modFiles = uniqueModListData.modFiles(); + + detectSystemMods(uniqueModListData.modFilesByFirstId()); + + modIdNameLookup = uniqueModListData.modFilesByFirstId().entrySet().stream() + .filter(e -> !e.getValue().get(0).getModInfos().isEmpty()) + .collect(Collectors.toMap( + Map.Entry::getKey, + e -> e.getValue().get(0).getModInfos().get(0) + )); + } + + private void detectSystemMods(final Map> modFilesByFirstId) + { // Capture system mods (ex. MC, Forge) here, so we can keep them for later final Set systemMods = new HashSet<>(); // The minecraft mod is always a system mod @@ -169,47 +180,6 @@ public class ModSorter throw new IllegalStateException("Failed to find system mod: " + systemMod); } } - - // Select the newest by artifact version sorting of non-unique files thus identified - this.modFiles = modFilesByFirstId.entrySet().stream() - .map(this::selectNewestModInfo) - .map(Map.Entry::getValue) - .map(ModFile.class::cast) - .collect(toList()); - - // Transform to the full mod id list - final Map> modIds = modFiles.stream() - .map(ModFile::getModInfos) - .flatMap(Collection::stream) - .map(ModInfo.class::cast) - .collect(groupingBy(IModInfo::getModId)); - - // Its theoretically possible that some mod has somehow moved an id to a secondary place, thus causing a dupe. - // We can't handle this - final List dupedMods = modIds.values().stream() - .filter(modInfos -> modInfos.size() > 1) - .map(modInfos -> modInfos.get(0)) - .toList(); - - if (!dupedMods.isEmpty()) { - final List duplicateModErrors = dupedMods.stream() - .map(dm -> new EarlyLoadingException.ExceptionData("fml.modloading.dupedmod", - dm, Objects.toString(dm))).toList(); - throw new EarlyLoadingException("Duplicate mods found", null, duplicateModErrors); - } - - modIdNameLookup = modIds.entrySet().stream() - .collect(toMap(Map.Entry::getKey, e -> e.getValue().get(0))); - } - - private Map.Entry selectNewestModInfo(Map.Entry> fullList) { - List modInfoList = fullList.getValue(); - if (modInfoList.size() > 1) { - LOGGER.debug("Found {} mods for first modid {}, selecting most recent based on version data", modInfoList.size(), fullList.getKey()); - modInfoList.sort(Comparator.comparing(mf -> mf.getModInfos().get(0).getVersion()).reversed()); - LOGGER.debug("Selected file {} for modid {} with version {}", modInfoList.get(0).getFileName(), fullList.getKey(), modInfoList.get(0).getModInfos().get(0).getVersion()); - } - return Map.entry(fullList.getKey(), modInfoList.get(0)); } private List verifyDependencyVersions() diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/UniqueModListBuilder.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/UniqueModListBuilder.java new file mode 100644 index 0000000000..1ce1479a4a --- /dev/null +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/UniqueModListBuilder.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) Forge Development LLC and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.minecraftforge.fml.loading; + +import net.minecraftforge.fml.loading.moddiscovery.ModFile; +import net.minecraftforge.forgespi.language.IModInfo; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.maven.artifact.versioning.ArtifactVersion; + +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +import static java.util.stream.Collectors.*; + +public class UniqueModListBuilder +{ + private final static Logger LOGGER = LogManager.getLogger(); + + private final List modFiles; + + public UniqueModListBuilder(final List modFiles) {this.modFiles = modFiles;} + + public UniqueModListData buildUniqueList() + { + List uniqueModList; + List uniqueLibListWithVersion; + + // Collect mod files by module name. This will be used for deduping purposes + final Map> modFilesByFirstId = modFiles.stream() + .filter(mf -> mf.getModFileInfo() != null) + .collect(groupingBy(UniqueModListBuilder::getModId)); + + final Map> libFilesWithVersionByModuleName = modFiles.stream() + .filter(mf -> mf.getModFileInfo() == null) + .collect(groupingBy(UniqueModListBuilder::getModId)); + + // Select the newest by artifact version sorting of non-unique files thus identified + uniqueModList = modFilesByFirstId.entrySet().stream() + .map(this::selectNewestModInfo) + .toList(); + + // Select the newest by artifact version sorting of non-unique files thus identified + uniqueLibListWithVersion = libFilesWithVersionByModuleName.entrySet().stream() + .map(this::selectNewestModInfo) + .toList(); + + // Transform to the full mod id list + final Map> modIds = uniqueModList.stream() + .filter(mf -> mf.getModFileInfo() != null) //Filter out non-mod files, we don't care about those for now..... + .map(ModFile::getModInfos) + .flatMap(Collection::stream) + .collect(groupingBy(IModInfo::getModId)); + + // Transform to the full lib id list + final Map> versionedLibIds = uniqueLibListWithVersion.stream() + .map(UniqueModListBuilder::getModId) + .collect(Collectors.toMap( + Function.identity(), + libFilesWithVersionByModuleName::get + )); + + // Its theoretically possible that some mod has somehow moved an id to a secondary place, thus causing a dupe. + // We can't handle this + final List dupedMods = modIds.values().stream() + .filter(modInfos -> modInfos.size() > 1) + .map(modInfos -> modInfos.get(0)) + .toList(); + + if (!dupedMods.isEmpty()) { + final List duplicateModErrors = dupedMods.stream() + .map(dm -> new EarlyLoadingException.ExceptionData("fml.modloading.dupedmod", dm, Objects.toString(dm))) + .toList(); + throw new EarlyLoadingException("Duplicate mods found", null, duplicateModErrors); + } + + final List dupedLibs = versionedLibIds.values().stream() + .filter(modFiles -> modFiles.size() > 1) + .map(modFiles -> modFiles.get(0)) + .toList(); + + if (!dupedLibs.isEmpty()) { + final List duplicateLibErrors = dupedLibs.stream() + .map(dm -> new EarlyLoadingException.ExceptionData("fml.modloading.dupedlib.versioned", dm, Objects.toString(dm))) + .toList(); + throw new EarlyLoadingException("Duplicate plugins or libraries found", null, duplicateLibErrors); + } + + // Collect unique mod files by module name. This will be used for deduping purposes + final Map> uniqueModFilesByFirstId = uniqueModList.stream() + .collect(groupingBy(UniqueModListBuilder::getModId)); + + final List loadedList = new ArrayList<>(); + loadedList.addAll(uniqueModList); + loadedList.addAll(uniqueLibListWithVersion); + + return new UniqueModListData(loadedList, uniqueModFilesByFirstId); + } + + private ModFile selectNewestModInfo(Map.Entry> fullList) { + List modInfoList = fullList.getValue(); + if (modInfoList.size() > 1) { + LOGGER.debug("Found {} mods for first modid {}, selecting most recent based on version data", modInfoList.size(), fullList.getKey()); + modInfoList.sort(Comparator.comparing(this::getVersion).reversed()); + LOGGER.debug("Selected file {} for modid {} with version {}", modInfoList.get(0).getFileName(), fullList.getKey(), modInfoList.get(0).getModInfos().get(0).getVersion()); + } + return modInfoList.get(0); + } + + private ArtifactVersion getVersion(final ModFile mf) + { + if (mf.getModFileInfo() == null) { + return mf.getJarVersion(); + } + return mf.getModInfos().get(0).getVersion(); + } + + private static String getModId(ModFile modFile) { + if (modFile.getModFileInfo() == null || modFile.getModFileInfo().getMods().isEmpty()) { + return modFile.getSecureJar().name(); + } + + return modFile.getModFileInfo().moduleName(); + } + + public record UniqueModListData(List modFiles, Map> modFilesByFirstId) {} + +} diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileDependencyLocator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileDependencyLocator.java new file mode 100644 index 0000000000..d9d4c4c228 --- /dev/null +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileDependencyLocator.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) Forge Development LLC and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.minecraftforge.fml.loading.moddiscovery; + +import net.minecraftforge.forgespi.locating.IModFile; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Optional; + +public abstract class AbstractJarFileDependencyLocator extends AbstractJarFileLocator +{ + private static final Logger LOGGER = LogManager.getLogger(); + + protected Optional loadResourceFromModFile(final IModFile modFile, final Path path) { + try { + return Optional.of(Files.newInputStream(modFile.findResource(path.toString()))); + } + catch (final FileNotFoundException e) { + LOGGER.debug("Failed to load resource {} from {}, it does not contain dependency information.", path, modFile.getFileName()); + return Optional.empty(); + } + catch (final Exception e) { + LOGGER.error("Failed to load resource {} from mod {}, cause {}", path, modFile.getFileName(), e); + return Optional.empty(); + } + } + + protected Optional loadModFileFrom(final IModFile file, final Path path) { + try { + final Path pathInModFile = file.findResource(path.toString()); + return createMod(pathInModFile); + } + catch (Exception e) { + LOGGER.error("Failed to load mod file {} from {}", path, file.getFileName()); + return Optional.empty(); + } + } + + protected String identifyMod(final IModFile modFile) { + return modFile.getFileName(); + } +} diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileLocator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileLocator.java index 0f70a6cb03..069ae404be 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileLocator.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileLocator.java @@ -6,30 +6,20 @@ package net.minecraftforge.fml.loading.moddiscovery; import cpw.mods.jarhandling.SecureJar; -import cpw.mods.jarhandling.JarMetadata; import net.minecraftforge.fml.loading.LogMarkers; -import net.minecraftforge.forgespi.language.IConfigurable; -import net.minecraftforge.forgespi.language.IModFileInfo; -import net.minecraftforge.forgespi.language.IModInfo; import net.minecraftforge.forgespi.locating.IModFile; -import net.minecraftforge.forgespi.locating.IModLocator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; -import java.util.jar.Manifest; -import java.util.stream.Collectors; import java.util.stream.Stream; -public abstract class AbstractJarFileLocator extends AbstractModLocator { +public abstract class AbstractJarFileLocator extends AbstractModLocator +{ private static final Logger LOGGER = LogManager.getLogger(); @Override @@ -43,15 +33,4 @@ public abstract class AbstractJarFileLocator extends AbstractModLocator { } LOGGER.debug(LogMarkers.SCAN,"Scan finished: {}", file); } - - @Override - public List scanMods() { - return scanCandidates() - .map(this::createMod) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toList()); - } - - public abstract Stream scanCandidates(); } diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileModLocator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileModLocator.java new file mode 100644 index 0000000000..a076d6ab3d --- /dev/null +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractJarFileModLocator.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) Forge Development LLC and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.minecraftforge.fml.loading.moddiscovery; + +import net.minecraftforge.forgespi.locating.IModFile; +import net.minecraftforge.forgespi.locating.IModLocator; + +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public abstract class AbstractJarFileModLocator extends AbstractJarFileLocator implements IModLocator +{ + @Override + public List scanMods() + { + return scanCandidates() + .map(this::createMod) + .filter(Optional::isPresent) + .map(Optional::get) + .collect(Collectors.toList()); + } + + public abstract Stream scanCandidates(); +} diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractModLocator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractModLocator.java index 51c8c71cab..96e8f3eb66 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractModLocator.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractModLocator.java @@ -24,8 +24,9 @@ import java.util.Optional; import java.util.function.Function; import java.util.jar.Manifest; -public abstract class AbstractModLocator implements IModLocator { - private static final Logger LOGGER = LogManager.getLogger(); +public abstract class AbstractModLocator implements IModLocator +{ + private static final Logger LOGGER = LogManager.getLogger(); protected static final String MODS_TOML = "META-INF/mods.toml"; protected static final String MANIFEST = "META-INF/MANIFEST.MF"; @@ -40,12 +41,15 @@ public abstract class AbstractModLocator implements IModLocator { IModFile mod; var type = sj.getManifest().getMainAttributes().getValue(ModFile.TYPE); + if (type == null) { + type = getDefaultJarModType(); + } if (sj.findFile(MODS_TOML).isPresent()) { LOGGER.debug(LogMarkers.SCAN, "Found {} mod of type {}: {}", MODS_TOML, type, path); mod = new ModFile(sj, this, ModFileParser::modsTomlParser); } else if (type != null) { LOGGER.debug(LogMarkers.SCAN, "Found {} mod of type {}: {}", MANIFEST, type, path); - mod = new ModFile(sj, this, this::manifestParser); + mod = new ModFile(sj, this, this::manifestParser, type); } else { return Optional.empty(); } @@ -68,29 +72,49 @@ public abstract class AbstractModLocator implements IModLocator { } }; - return new IModFileInfo() { - @Override public List getMods() { return Collections.emptyList(); } - @Override public List requiredLanguageLoaders() { return Collections.emptyList(); } - @Override public boolean showAsResourcePack() { return false; } - @Override public Map getFileProperties() { return Collections.emptyMap(); } - @Override public String getLicense() { return license; } - @Override public IModFile getFile() { return mod; } - @Override public IConfigurable getConfig() { return dummy; } - - // These Should never be called as it's only called from ModJarMetadata.version and we bypass that - @Override public String moduleName() { return mod.getSecureJar().name(); } - @Override public String versionString() { return null; } - @Override public List usesServices() { return null; } - - @Override - public String toString() { - return "IModFileInfo(" + mod.getFilePath() + ")"; - } - }; + return new DefaultModFileInfo(mod, license, dummy); } @Override public boolean isValid(final IModFile modFile) { return true; } + + protected String getDefaultJarModType() { + return null; + } + + private record DefaultModFileInfo(IModFile mod, String license, IConfigurable configurable) implements IModFileInfo, IConfigurable { + @Override + public Optional getConfigElement(final String... strings) + { + return Optional.empty(); + } + + @Override + public List getConfigList(final String... strings) + { + return null; + } + + @Override public List getMods() { return Collections.emptyList(); } + @Override public List requiredLanguageLoaders() { return Collections.emptyList(); } + @Override public boolean showAsResourcePack() { return false; } + @Override public Map getFileProperties() { return Collections.emptyMap(); } + @Override + public String getLicense() { return license; } + + @Override public IModFile getFile() { return mod; } + @Override public IConfigurable getConfig() { return configurable; } + + // These Should never be called as it's only called from ModJarMetadata.version and we bypass that + @Override public String moduleName() { return mod.getSecureJar().name(); } + @Override public String versionString() { return null; } + @Override public List usesServices() { return null; } + + @Override + public String toString() { + return "IModFileInfo(" + mod.getFilePath() + ")"; + } + } } diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ClasspathLocator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ClasspathLocator.java index cf19b28408..849ff43ac5 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ClasspathLocator.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ClasspathLocator.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Stream; -public class ClasspathLocator extends AbstractJarFileLocator { +public class ClasspathLocator extends AbstractJarFileModLocator { private static final Logger LOGGER = LogManager.getLogger(); private final List legacyClasspath = Arrays.stream(System.getProperty("legacyClassPath", "").split(File.pathSeparator)).map(Path::of).toList(); private boolean enabled = false; diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/JarInJarDependencyLocator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/JarInJarDependencyLocator.java new file mode 100644 index 0000000000..b394b43ac2 --- /dev/null +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/JarInJarDependencyLocator.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) Forge Development LLC and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.minecraftforge.fml.loading.moddiscovery; + +import com.google.common.collect.Lists; +import net.minecraftforge.fml.loading.EarlyLoadingException; +import net.minecraftforge.forgespi.language.IModInfo; +import net.minecraftforge.forgespi.locating.IModFile; +import net.minecraftforge.jarjar.selection.JarSelector; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.VersionRange; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class JarInJarDependencyLocator extends AbstractJarFileDependencyLocator +{ + private static final Logger LOGGER = LogManager.getLogger(); + + @Override + public String name() + { + return "JarInJar"; + } + + @Override + public List scanMods(final Iterable loadedMods) { + final List sources = Lists.newArrayList(); + loadedMods.forEach(sources::add); + + + final List dependenciesToLoad = JarSelector.detectAndSelect( + sources, + this::loadResourceFromModFile, + this::loadModFileFrom, + this::identifyMod, + this::exception + ); + + if (dependenciesToLoad.isEmpty()) { + LOGGER.info("No dependencies to load found. Skipping!"); + return Collections.emptyList(); + } + + LOGGER.info("Found {} dependencies adding them to mods collection", dependenciesToLoad.size()); + return dependenciesToLoad; + } + + @Override + public void initArguments(final Map arguments) + { + // NO-OP, for now + } + + @Override + protected String getDefaultJarModType() + { + return IModFile.Type.GAMELIBRARY.name(); + } + + protected EarlyLoadingException exception(Collection> failedDependencies) + { + + final List errors = failedDependencies.stream() + .filter(entry -> !entry.sources().isEmpty()) //Should never be the case, but just to be sure + .map(entry -> new EarlyLoadingException.ExceptionData( + getErrorTranslationKey(entry), + entry.identifier().group() + ":" + entry.identifier().artifact(), + entry.sources() + .stream() + .flatMap(this::getModWithVersionRangeStream) + .map(this::formatError) + .collect(Collectors.joining(", ")))).toList(); + + return new EarlyLoadingException(failedDependencies.size() + " Dependency restrictions were not met.", null, errors); + } + + @NotNull + private String getErrorTranslationKey(final JarSelector.ResolutionFailureInformation entry) + { + return entry.failureReason() == JarSelector.FailureReason.VERSION_RESOLUTION_FAILED + ? "fml.dependencyloading.conflictingdependencies" + : "fml.dependencyloading.mismatchedcontaineddependencies"; + } + + @NotNull + private Stream getModWithVersionRangeStream(final JarSelector.SourceWithRequestedVersionRange file) + { + return file.source().getModFileInfo().getMods().stream().map(modInfo -> new ModWithVersionRange(modInfo, file.requestedVersionRange(), file.includedVersion())); + } + + @NotNull + private String formatError(final ModWithVersionRange modWithVersionRange) + { + return "\u00a7e" + modWithVersionRange.modInfo().getModId() + "\u00a7r - \u00a74" + + modWithVersionRange.versionRange().toString() + "\u00a74 - \u00a72" + + modWithVersionRange.artifactVersion().toString() + "\u00a72"; + } + + private record ModWithVersionRange(IModInfo modInfo, VersionRange versionRange, ArtifactVersion artifactVersion) {} +} diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/MavenDirectoryLocator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/MavenDirectoryLocator.java index 94ebc4d07d..e4ac3604bb 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/MavenDirectoryLocator.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/MavenDirectoryLocator.java @@ -15,7 +15,7 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; -public class MavenDirectoryLocator extends AbstractJarFileLocator { +public class MavenDirectoryLocator extends AbstractJarFileModLocator { private List modCoords; @Override diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/MinecraftLocator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/MinecraftLocator.java index 939d5f8cb0..415c7f05fe 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/MinecraftLocator.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/MinecraftLocator.java @@ -23,7 +23,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; -public class MinecraftLocator extends AbstractModLocator { +public class MinecraftLocator extends AbstractModLocator implements IModLocator { private static final Logger LOGGER = LogManager.getLogger(); @Override diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java index 55fc8a974f..d3c457002c 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java @@ -5,10 +5,14 @@ package net.minecraftforge.fml.loading.moddiscovery; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Maps; import cpw.mods.modlauncher.Launcher; import cpw.mods.modlauncher.api.IModuleLayerManager; import cpw.mods.modlauncher.util.ServiceLoaderUtils; +import net.minecraftforge.fml.loading.EarlyLoadingException; import net.minecraftforge.fml.loading.LogMarkers; +import net.minecraftforge.fml.loading.UniqueModListBuilder; import net.minecraftforge.fml.loading.progress.StartupMessageManager; import net.minecraftforge.forgespi.Environment; import net.minecraftforge.forgespi.locating.IModFile; @@ -24,43 +28,119 @@ import java.util.stream.Collectors; public class ModDiscoverer { private static final Logger LOGGER = LogManager.getLogger(); - private final ServiceLoader locators; - private final List locatorList; + private final ServiceLoader modLocators; + private final List modLocatorList; public ModDiscoverer(Map arguments) { Launcher.INSTANCE.environment().computePropertyIfAbsent(Environment.Keys.MODDIRECTORYFACTORY.get(), v->ModsFolderLocator::new); Launcher.INSTANCE.environment().computePropertyIfAbsent(Environment.Keys.PROGRESSMESSAGE.get(), v-> StartupMessageManager.locatorConsumer().orElseGet(()-> s->{})); final var moduleLayerManager = Launcher.INSTANCE.environment().findModuleLayerManager().orElseThrow(); - locators = ServiceLoader.load(moduleLayerManager.getLayer(IModuleLayerManager.Layer.SERVICE).orElseThrow(), IModLocator.class); - locatorList = ServiceLoaderUtils.streamServiceLoader(()->locators, sce->LOGGER.error("Failed to load locator list", sce)).collect(Collectors.toList()); - locatorList.forEach(l->l.initArguments(arguments)); - LOGGER.debug(LogMarkers.CORE,"Found Mod Locators : {}", ()->locatorList.stream().map(iModLocator -> "("+iModLocator.name() + ":" + iModLocator.getClass().getPackage().getImplementationVersion()+")").collect(Collectors.joining(","))); - } - - ModDiscoverer(List locatorList) { - this.locatorList = locatorList; - this.locators = null; + modLocators = ServiceLoader.load(moduleLayerManager.getLayer(IModuleLayerManager.Layer.SERVICE).orElseThrow(), IModLocator.class); + modLocatorList = ServiceLoaderUtils.streamServiceLoader(()-> modLocators, sce->LOGGER.error("Failed to load mod locator list", sce)).collect(Collectors.toList()); + modLocatorList.forEach(l->l.initArguments(arguments)); + if (LOGGER.isDebugEnabled(LogMarkers.CORE)) + { + LOGGER.debug(LogMarkers.CORE, "Found Mod Locators : {}", modLocatorList.stream() + .map(modLocator -> "(%s:%s)".formatted(modLocator.name(), + modLocator.getClass().getPackage().getImplementationVersion())).collect(Collectors.joining(","))); + } } public ModValidator discoverMods() { - LOGGER.debug(LogMarkers.SCAN,"Scanning for mods and other resources to load. We know {} ways to find mods", locatorList.size()); - var loadedFiles = new ArrayList<>(); - for (IModLocator locator : locatorList) { - LOGGER.debug(LogMarkers.SCAN,"Trying locator {}", locator); - var modFiles = locator.scanMods(); - for (IModFile mf : modFiles) { - LOGGER.info(LogMarkers.SCAN, "Found mod file {} of type {} with locator {}", mf.getFileName(), mf.getType(), mf.getLocator()); - StartupMessageManager.modLoaderConsumer().ifPresent(c->c.accept("Found mod file "+mf.getFileName()+" of type "+mf.getType())); - } - loadedFiles.addAll(modFiles); - } - final var modFilesMap = loadedFiles.stream() - .map(ModFile.class::cast) - .collect(Collectors.groupingBy(IModFile::getType)); + LOGGER.debug(LogMarkers.SCAN,"Scanning for mods and other resources to load. We know {} ways to find mods", modLocatorList.size()); + List loadedFiles = new ArrayList<>(); + List discoveryErrorData = new ArrayList<>(); + boolean successfullyLoadedMods = true; - var validator = new ModValidator(modFilesMap); + //Loop all mod locators to get the prime mods to load from. + for (IModLocator locator : modLocatorList) { + try { + LOGGER.debug(LogMarkers.SCAN,"Trying locator {}", locator); + var locatedFiles = locator.scanMods(); + + if (locatedFiles.stream().anyMatch(file -> !(file instanceof ModFile))) { + LOGGER.error(LogMarkers.SCAN, "A mod locator returned a file which is not a ModFile instance!. They will be skipped!"); + } + + handleLocatedFiles(loadedFiles, locatedFiles); + } catch (EarlyLoadingException exception) { + LOGGER.error(LogMarkers.SCAN, "Failed to load mods with locator {}", locator, exception); + discoveryErrorData.addAll(exception.getAllData()); + } + } + + //First processing run of the mod list. Any duplicates will cause resolution failure and dependency loading will be skipped. + Map> modFilesMap = Maps.newHashMap(); + try { + final UniqueModListBuilder modsUniqueListBuilder = new UniqueModListBuilder(loadedFiles); + final UniqueModListBuilder.UniqueModListData uniqueModsData = modsUniqueListBuilder.buildUniqueList(); + + //Grab the temporary results. + //This allows loading to continue to a base state, in case dependency loading fails. + modFilesMap = uniqueModsData.modFiles().stream() + .collect(Collectors.groupingBy(IModFile::getType)); + loadedFiles = uniqueModsData.modFiles(); + } + catch (EarlyLoadingException exception) { + LOGGER.error(LogMarkers.SCAN, "Failed to build unique mod list after mod discovery.", exception); + discoveryErrorData.addAll(exception.getAllData()); + successfullyLoadedMods = false; + } + + //We can continue loading if prime mods loaded successfully. + if (successfullyLoadedMods) { + LOGGER.debug(LogMarkers.SCAN, "Successfully Loaded {} mods. Attempting to load dependencies...", loadedFiles.size()); + for (IModLocator locator : modLocatorList) { + try { + LOGGER.debug(LogMarkers.SCAN,"Trying locator {}", locator); + final List locatedMods = ImmutableList.copyOf(loadedFiles); + + var locatedFiles = locator.scanMods(locatedMods); + if (locatedFiles.stream().anyMatch(file -> !(file instanceof ModFile))) { + LOGGER.error(LogMarkers.SCAN, "A dependency locator returned a file which is not a ModFile instance!. They will be skipped!"); + } + + handleLocatedFiles(loadedFiles, locatedFiles); + } + catch (EarlyLoadingException exception) { + LOGGER.error(LogMarkers.SCAN, "Failed to load dependencies with locator {}", locator, exception); + discoveryErrorData.addAll(exception.getAllData()); + } + } + + //Second processing run of the mod list. Any duplicates will cause resolution failure and only the mods list will be loaded. + try { + final UniqueModListBuilder modsAndDependenciesUniqueListBuilder = new UniqueModListBuilder(loadedFiles); + final UniqueModListBuilder.UniqueModListData uniqueModsAndDependenciesData = modsAndDependenciesUniqueListBuilder.buildUniqueList(); + + //We now only need the mod files map, not the list. + modFilesMap = uniqueModsAndDependenciesData.modFiles().stream() + .collect(Collectors.groupingBy(IModFile::getType)); + } catch (EarlyLoadingException exception) { + LOGGER.error(LogMarkers.SCAN, "Failed to build unique mod list after dependency discovery.", exception); + discoveryErrorData.addAll(exception.getAllData()); + modFilesMap = loadedFiles.stream().collect(Collectors.groupingBy(IModFile::getType)); + } + } + else { + //Failure notify the listeners. + LOGGER.error(LogMarkers.SCAN, "Mod Discovery failed. Skipping dependency discovery."); + } + + //Validate the loading. With a deduplicated list, we can now successfully process the artifacts and load + //transformer plugins. + var validator = new ModValidator(modFilesMap, discoveryErrorData); validator.stage1Validation(); return validator; } + private void handleLocatedFiles(final List loadedFiles, final List locatedFiles) + { + var locatedModFiles = locatedFiles.stream().filter(ModFile.class::isInstance).map(ModFile.class::cast).toList(); + for (IModFile mf : locatedModFiles) { + LOGGER.info(LogMarkers.SCAN, "Found mod file {} of type {} with provider {}", mf.getFileName(), mf.getType(), mf.getLocator()); + StartupMessageManager.modLoaderConsumer().ifPresent(c->c.accept("Found mod file "+mf.getFileName()+" of type "+mf.getType())); + } + loadedFiles.addAll(locatedModFiles); + } } diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java index 760ec9dac9..f81f0ddb54 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java @@ -19,6 +19,8 @@ import net.minecraftforge.forgespi.locating.IModLocator; import net.minecraftforge.forgespi.locating.ModFileFactory; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import java.nio.file.Files; import java.nio.file.Path; @@ -51,9 +53,9 @@ public class ModFile implements IModFile { private Throwable scanError; private final SecureJar jar; private final Type modFileType; - private final Manifest manifest; + private final Manifest manifest; private final IModLocator locator; - private IModFileInfo modFileInfo; + private IModFileInfo modFileInfo; private ModFileScanData fileModFileScanData; private CompletableFuture futureScanResult; private List coreMods; @@ -63,14 +65,18 @@ public class ModFile implements IModFile { private SecureJar.Status securityStatus; public ModFile(final SecureJar jar, final IModLocator locator, final ModFileFactory.ModFileInfoParser parser) { + this(jar, locator, parser, parseType(jar)); + } + + public ModFile(final SecureJar jar, final IModLocator locator, final ModFileFactory.ModFileInfoParser parser, String type) { this.locator = locator; this.jar = jar; this.parser = parser; manifest = this.jar.getManifest(); - final Optional value = Optional.ofNullable(manifest.getMainAttributes().getValue(TYPE)); - modFileType = Type.valueOf(value.orElse("MOD")); + modFileType = Type.valueOf(type); jarVersion = Optional.ofNullable(manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION)).orElse("0.0NONE"); + this.modFileInfo = ModFileParser.readModList(this, this.parser); } @Override @@ -201,4 +207,15 @@ public class ModFile implements IModFile { public void setSecurityStatus(final SecureJar.Status status) { this.securityStatus = status; } + + public ArtifactVersion getJarVersion() + { + return new DefaultArtifactVersion(this.jarVersion); + } + + private static String parseType(final SecureJar jar) { + final Manifest m = jar.getManifest(); + final Optional value = Optional.ofNullable(m.getMainAttributes().getValue(TYPE)); + return value.orElse("MOD"); + } } diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModValidator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModValidator.java index b7b4d2455b..ba7988f73d 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModValidator.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModValidator.java @@ -26,13 +26,15 @@ public class ModValidator { private final List candidateMods; private LoadingModList loadingModList; private List brokenFiles; + private final List discoveryErrorData; - public ModValidator(final Map> modFiles) { + public ModValidator(final Map> modFiles, final List discoveryErrorData) { this.modFiles = modFiles; this.candidateMods = lst(modFiles.get(IModFile.Type.MOD)); this.candidateMods.addAll(lst(modFiles.get(IModFile.Type.GAMELIBRARY))); this.candidatePlugins = lst(modFiles.get(IModFile.Type.LANGPROVIDER)); this.candidatePlugins.addAll(lst(modFiles.get(IModFile.Type.LIBRARY))); + this.discoveryErrorData = discoveryErrorData; } private static List lst(List files) { @@ -50,22 +52,22 @@ public class ModValidator { final List brokenFiles = new ArrayList<>(); for (Iterator iterator = mods.iterator(); iterator.hasNext(); ) { - ModFile mod = iterator.next(); - if (!mod.getLocator().isValid(mod) || !mod.identifyMods()) { - LOGGER.warn(LogMarkers.SCAN, "File {} has been ignored - it is invalid", mod.getFilePath()); + ModFile modFile = iterator.next(); + if (!modFile.getLocator().isValid(modFile) || !modFile.identifyMods()) { + LOGGER.warn(LogMarkers.SCAN, "File {} has been ignored - it is invalid", modFile.getFilePath()); iterator.remove(); - brokenFiles.add(mod); + brokenFiles.add(modFile); } } return brokenFiles; } public ITransformationService.Resource getPluginResources() { - return new ITransformationService.Resource(IModuleLayerManager.Layer.PLUGIN, this.candidatePlugins.stream().map(ModFile::getSecureJar).toList()); + return new ITransformationService.Resource(IModuleLayerManager.Layer.PLUGIN, this.candidatePlugins.stream().map(IModFile::getSecureJar).toList()); } public ITransformationService.Resource getModResources() { - return new ITransformationService.Resource(IModuleLayerManager.Layer.GAME, this.candidateMods.stream().map(ModFile::getSecureJar).toList()); + return new ITransformationService.Resource(IModuleLayerManager.Layer.GAME, this.candidateMods.stream().map(IModFile::getSecureJar).toList()); } private List validateLanguages() { @@ -84,7 +86,11 @@ public class ModValidator { public BackgroundScanHandler stage2Validation() { var errors = validateLanguages(); - loadingModList = ModSorter.sort(candidateMods, errors); + + var allErrors = new ArrayList<>(errors); + allErrors.addAll(this.discoveryErrorData); + + loadingModList = ModSorter.sort(candidateMods, allErrors); loadingModList.addCoreMods(); loadingModList.addAccessTransformers(); loadingModList.setBrokenFiles(brokenFiles); diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModsFolderLocator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModsFolderLocator.java index f21e069835..b6d73b0b75 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModsFolderLocator.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModsFolderLocator.java @@ -23,7 +23,7 @@ import static cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck; /** * Support loading mods located in JAR files in the mods folder */ -public class ModsFolderLocator extends AbstractJarFileLocator { +public class ModsFolderLocator extends AbstractJarFileModLocator { private static final String SUFFIX = ".jar"; private static final Logger LOGGER = LogManager.getLogger(); private final Path modFolder; diff --git a/fmlloader/src/main/resources/META-INF/services/net.minecraftforge.forgespi.locating.IModLocator b/fmlloader/src/main/resources/META-INF/services/net.minecraftforge.forgespi.locating.IModLocator index 0ace126c60..c7307b84fa 100644 --- a/fmlloader/src/main/resources/META-INF/services/net.minecraftforge.forgespi.locating.IModLocator +++ b/fmlloader/src/main/resources/META-INF/services/net.minecraftforge.forgespi.locating.IModLocator @@ -3,3 +3,4 @@ net.minecraftforge.fml.loading.moddiscovery.MavenDirectoryLocator net.minecraftforge.fml.loading.moddiscovery.ExplodedDirectoryLocator net.minecraftforge.fml.loading.moddiscovery.MinecraftLocator net.minecraftforge.fml.loading.moddiscovery.ClasspathLocator +net.minecraftforge.fml.loading.moddiscovery.JarInJarDependencyLocator \ No newline at end of file diff --git a/src/main/java/net/minecraftforge/client/gui/LoadingErrorScreen.java b/src/main/java/net/minecraftforge/client/gui/LoadingErrorScreen.java index 15dfe76fe8..5931b6b75c 100644 --- a/src/main/java/net/minecraftforge/client/gui/LoadingErrorScreen.java +++ b/src/main/java/net/minecraftforge/client/gui/LoadingErrorScreen.java @@ -96,7 +96,11 @@ public class LoadingErrorScreen extends ErrorScreen { } public static class LoadingEntryList extends ObjectSelectionList { LoadingEntryList(final LoadingErrorScreen parent, final List errors, final List warnings) { - super(parent.minecraft, parent.width, parent.height, 35, parent.height - 50, 2 * parent.minecraft.font.lineHeight + 8); + super(Objects.requireNonNull(parent.minecraft), parent.width, parent.height, 35, parent.height - 50, + Math.max( + errors.stream().mapToInt(error -> parent.font.split(new TranslatableComponent(error.getMessage() != null ? error.getMessage() : ""), parent.width - 20).size()).max().orElse(0), + warnings.stream().mapToInt(warning -> parent.font.split(new TranslatableComponent(warning.formatToString() != null ? warning.formatToString() : ""), parent.width - 20).size()).max().orElse(0) + ) * parent.minecraft.font.lineHeight + 8); boolean both = !errors.isEmpty() && !warnings.isEmpty(); if (both) addEntry(new LoadingMessageEntry(parent.errorHeader, true)); @@ -142,13 +146,14 @@ public class LoadingErrorScreen extends ErrorScreen { @Override public void render(PoseStack poseStack, int entryIdx, int top, int left, final int entryWidth, final int entryHeight, final int mouseX, final int mouseY, final boolean p_194999_5_, final float partialTick) { Font font = Minecraft.getInstance().font; - final List strings = font.split(message, LoadingEntryList.this.width); + final List strings = font.split(message, LoadingEntryList.this.width - 20); int y = top + 2; - for (int i = 0; i < Math.min(strings.size(), 2); i++) { + for (FormattedCharSequence string : strings) + { if (center) - font.draw(poseStack, strings.get(i), left + (width) - font.width(strings.get(i)) / 2F, y, 0xFFFFFF); + font.draw(poseStack, string, left + (width) - font.width(string) / 2F, y, 0xFFFFFF); else - font.draw(poseStack, strings.get(i), left + 5, y, 0xFFFFFF); + font.draw(poseStack, string, left + 5, y, 0xFFFFFF); y += font.lineHeight; } } diff --git a/src/main/resources/assets/forge/lang/en_us.json b/src/main/resources/assets/forge/lang/en_us.json index 7b8f78cfb3..c943eca847 100644 --- a/src/main/resources/assets/forge/lang/en_us.json +++ b/src/main/resources/assets/forge/lang/en_us.json @@ -66,6 +66,8 @@ "fml.modloading.failedtoloadforge": "Failed to load Forge", "fml.modloading.missingdependency": "Mod \u00a7e{4}\u00a7r requires \u00a76{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a76{3}\u00a7r\u00a77 is \u00a7o{6,i18n,fml.messages.artifactversion.ornotinstalled}", "fml.modloading.missingdependency.optional": "Mod \u00a7e{4}\u00a7r only supports \u00a73{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a73{3}\u00a7r\u00a77 is \u00a7o{6}", + "fml.dependencyloading.conflictingdependencies": "Some mods have requested conflicting versions of: \u00a76{3}\u00a7r. Requested by: \u00a7e{4}\u00a7r.", + "fml.dependencyloading.mismatchedcontaineddependencies": "Some mods have agreed upon an acceptable version range for : \u00a76{3}\u00a7r, but no jar was provided which matched the range. Requested by: \u00a7e{4}\u00a7r.", "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.brokenfile": "File {2} is not a valid mod file", diff --git a/src/test/resources/META-INF/jarjar/ForgeJiJTestMod-1.2.jar b/src/test/resources/META-INF/jarjar/ForgeJiJTestMod-1.2.jar new file mode 100644 index 0000000000..df2812e60d Binary files /dev/null and b/src/test/resources/META-INF/jarjar/ForgeJiJTestMod-1.2.jar differ diff --git a/src/test/resources/META-INF/jarjar/metadata.json b/src/test/resources/META-INF/jarjar/metadata.json new file mode 100644 index 0000000000..4b0210ed9c --- /dev/null +++ b/src/test/resources/META-INF/jarjar/metadata.json @@ -0,0 +1,15 @@ +{ + "jars": [ + { + "identifier": { + "group": "net.minecraftforge.jij", + "artifact": "JijTestMod" + }, + "version": { + "range": "[1.0,)", + "artifactVersion": "1.2" + }, + "path": "META-INF/jarjar/ForgeJiJTestMod-1.2.jar" + } + ] +} \ No newline at end of file