diff --git a/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java b/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java index 38250e25b..2a57d2af2 100644 --- a/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java +++ b/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; @@ -91,6 +92,12 @@ public static void remapDependencies(Project project, String mappingsSuffix, Loo String name = artifact.getModuleVersion().getId().getName(); String version = replaceIfNullOrEmpty(artifact.getModuleVersion().getId().getVersion(), () -> Checksum.truncatedSha256(artifact.getFile())); + try { + ModUtils.validateJarManifest(artifact.getFile().toPath()); + } catch (IOException e) { + throw new UncheckedIOException("Failed to read manifest from" + artifact.getFile(), e); + } + if (!ModUtils.shouldRemapMod(project.getLogger(), artifact.getFile(), artifact.getId(), extension.getPlatform().get(), sourceConfig.getName())) { addToRegularCompile(project, regularConfig, artifact); continue; diff --git a/src/main/java/net/fabricmc/loom/util/ModUtils.java b/src/main/java/net/fabricmc/loom/util/ModUtils.java index f1076080f..e05469379 100644 --- a/src/main/java/net/fabricmc/loom/util/ModUtils.java +++ b/src/main/java/net/fabricmc/loom/util/ModUtils.java @@ -24,11 +24,15 @@ package net.fabricmc.loom.util; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; +import java.util.jar.Attributes; +import java.util.jar.Manifest; import com.google.gson.JsonObject; import org.gradle.api.logging.Logger; @@ -82,4 +86,21 @@ public static boolean shouldRemapMod(Logger logger, File input, Object id, ModPl return false; } + + public static void validateJarManifest(Path path) throws IOException { + try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(path)) { + final Path manifestPath = fs.get().getPath("META-INF/MANIFEST.MF"); + + if (Files.exists(manifestPath)) { + final var manifest = new Manifest(new ByteArrayInputStream(Files.readAllBytes(manifestPath))); + final Attributes mainAttributes = manifest.getMainAttributes(); + + // Check to see if the jar was built with a newer version of loom. + // This version of loom does not support the remap type value so throw an exception. + if (mainAttributes.getValue("Fabric-Loom-Mixin-Remap-Type") != null) { + throw new IllegalStateException("This version of loom does not support the mixin remap type value. Please update to the latest version of loom."); + } + } + } + } }