From 25eefb5d62dac05cf20e5d404cd3aad48b82890e Mon Sep 17 00:00:00 2001 From: SettingDust Date: Sun, 13 Aug 2023 04:09:40 +0800 Subject: [PATCH] Make all jars nestable on Forge (#153) Fixes #152. --- .../net/fabricmc/loom/build/nesting/JarNester.java | 6 +++--- .../fabricmc/loom/util/fmj/FabricModJsonFactory.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/build/nesting/JarNester.java b/src/main/java/net/fabricmc/loom/build/nesting/JarNester.java index 028f9b2fb..a90d5de01 100644 --- a/src/main/java/net/fabricmc/loom/build/nesting/JarNester.java +++ b/src/main/java/net/fabricmc/loom/build/nesting/JarNester.java @@ -53,7 +53,7 @@ public static void nestJars(Collection jars, List forgeJars, F return; } - Preconditions.checkArgument(FabricModJsonFactory.isModJar(modJar, platform), "Cannot nest jars into none mod jar " + modJar.getName()); + Preconditions.checkArgument(FabricModJsonFactory.isNestableModJar(modJar, platform), "Cannot nest jars into none mod jar " + modJar.getName()); try { ZipUtils.add(modJar.toPath(), jars.stream().map(file -> { @@ -78,7 +78,7 @@ public static void nestJars(Collection jars, List forgeJars, F for (File file : jars) { String nestedJarPath = "META-INF/jars/" + file.getName(); - Preconditions.checkArgument(FabricModJsonFactory.isModJar(file, platform), "Cannot nest none mod jar: " + file.getName()); + Preconditions.checkArgument(FabricModJsonFactory.isNestableModJar(file, platform), "Cannot nest none mod jar: " + file.getName()); for (JsonElement nestedJar : nestedJars) { JsonObject jsonObject = nestedJar.getAsJsonObject(); @@ -115,7 +115,7 @@ public static void nestJars(Collection jars, List forgeJars, F for (File file : jars) { String nestedJarPath = "META-INF/jars/" + file.getName(); - Preconditions.checkArgument(FabricModJsonFactory.isModJar(file, platform), "Cannot nest none mod jar: " + file.getName()); + Preconditions.checkArgument(FabricModJsonFactory.isNestableModJar(file, platform), "Cannot nest none mod jar: " + file.getName()); for (JsonElement nestedJar : nestedJars) { String nestedJarString = nestedJar.getAsString(); diff --git a/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java b/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java index 21653eeee..d5b806def 100644 --- a/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java +++ b/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java @@ -175,6 +175,16 @@ public static boolean isModJar(Path input, ModPlatform platform) { return ZipUtils.contains(input, FABRIC_MOD_JSON); } + public static boolean isNestableModJar(File file, ModPlatform platform) { + return isNestableModJar(file.toPath(), platform); + } + + public static boolean isNestableModJar(Path input, ModPlatform platform) { + // Forge don't care if the main jar is mod jar. + if (platform == ModPlatform.FORGE) return true; + return isModJar(input, platform); + } + public static boolean containsMod(FileSystemUtil.Delegate fs, ModPlatform platform) { if (Files.exists(fs.getPath("architectury.common.marker"))) { return true;