From 28d4205a9766e54b78ea4abdec6ff06e81d92b25 Mon Sep 17 00:00:00 2001 From: Jonathing Date: Sat, 29 Jun 2024 01:21:47 -0400 Subject: [PATCH] Choose default JarJar mod file type based on parent JAR Closes #9939 (#10022) Co-authored-by: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> --- .../fml/loading/moddiscovery/AbstractModProvider.java | 6 +++++- .../loading/moddiscovery/JarInJarDependencyLocator.java | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractModProvider.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractModProvider.java index 800b064fae..a1006a3040 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractModProvider.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/AbstractModProvider.java @@ -36,6 +36,10 @@ public abstract class AbstractModProvider implements IModProvider { protected static final String MODS_TOML = "META-INF/mods.toml"; protected IModLocator.ModFileOrException createMod(Path path) { + return this.createMod(path, getDefaultJarModType()); + } + + protected IModLocator.ModFileOrException createMod(Path path, String defaultType) { var mjm = new ModJarMetadata(); var sj = SecureJar.from( jar -> jar.moduleDataProvider().findFile(MODS_TOML).isPresent() ? mjm : JarMetadata.from(jar, path), @@ -45,7 +49,7 @@ public abstract class AbstractModProvider implements IModProvider { IModFile mod; var type = sj.moduleDataProvider().getManifest().getMainAttributes().getValue(ModFile.TYPE); if (type == null) - type = getDefaultJarModType(); + type = defaultType; if (sj.moduleDataProvider().findFile(MODS_TOML).isPresent()) { LOGGER.debug(LogMarkers.SCAN, "Found {} mod of type {}: {}", MODS_TOML, type, path); 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 index 38516007cd..04d10696e5 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/JarInJarDependencyLocator.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/JarInJarDependencyLocator.java @@ -83,7 +83,14 @@ public class JarInJarDependencyLocator extends AbstractModProvider implements ID final Map outerFsArgs = ImmutableMap.of("packagePath", pathInModFile); final FileSystem zipFS = FileSystems.newFileSystem(filePathUri, outerFsArgs); final Path pathInFS = zipFS.getPath("/"); - return Optional.of(createMod(pathInFS).file()); + final IModFile.Type parentType = file.getType(); + final String modType; + if (parentType == IModFile.Type.LIBRARY || parentType == IModFile.Type.LANGPROVIDER) { + modType = IModFile.Type.LIBRARY.name(); + } else { + modType = IModFile.Type.GAMELIBRARY.name(); + } + return Optional.of(createMod(pathInFS, modType).file()); } catch (Exception e) { LOGGER.error("Failed to load mod file {} from {}", path, file.getFileName()); final RuntimeException exception = new ModFileLoadingException("Failed to load mod file " + file.getFileName());