From 432d05e9a62da9fe6a5589ddf15c0108475d484d Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Sun, 7 Dec 2025 17:52:18 +0200 Subject: [PATCH] Support refmapless mixins on older Forge releases --- .../configuration/mods/ArtifactMetadata.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactMetadata.java b/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactMetadata.java index 2c89fda8..8ea78495 100644 --- a/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactMetadata.java +++ b/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactMetadata.java @@ -38,8 +38,11 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; import org.gradle.api.Project; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import net.fabricmc.loom.LoomGradlePlugin; import net.fabricmc.loom.configuration.InstallerData; @@ -53,6 +56,8 @@ import net.fabricmc.loom.util.gradle.GradleUtils; public record ArtifactMetadata(boolean isFabricMod, RemapRequirements remapRequirements, @Nullable InstallerData installerData, MixinRemapType mixinRemapType, List knownIdyBsms) { private static final String INSTALLER_PATH = "fabric-installer.json"; + private static final Logger LOGGER = LoggerFactory.getLogger(ArtifactMetadata.class); + // ARCH: Quilt support private static final String QUILT_INSTALLER_PATH = "quilt_installer.json"; @@ -83,6 +88,7 @@ public record ArtifactMetadata(boolean isFabricMod, RemapRequirements remapRequi final String loomVersion = mainAttributes.getValue(Constants.Manifest.LOOM_VERSION); final String mixinRemapType = mainAttributes.getValue(Constants.Manifest.MIXIN_REMAP_TYPE); final String knownIndyBsmsValue = mainAttributes.getValue(Constants.Manifest.KNOWN_IDY_BSMS); + final String mixinConfigs = mainAttributes.getValue(Constants.Forge.MIXIN_CONFIGS_MANIFEST_KEY); if (remapValue != null) { // Support opting into and out of remapping with "Fabric-Loom-Remap" manifest entry @@ -95,6 +101,10 @@ public record ArtifactMetadata(boolean isFabricMod, RemapRequirements remapRequi } catch (IllegalArgumentException e) { throw new IllegalStateException("Unknown mixin remap type: " + mixinRemapType); } + } else if (platform == ModPlatform.FORGE && hasRefmaplessMixinConfig(fs, mixinConfigs)) { + // On Forge, we support both mixins with and without refmaps. + // Check for mixins without them, and if any are found, mark the remap type as static. + refmapRemapType = MixinRemapType.STATIC; } else if (forcesStaticMixinRemap != null) { // The mixin remap type is not specified in the manifest, but we have a forced value // This is forced to be static on NeoForge or Forge 50+. @@ -123,6 +133,22 @@ public record ArtifactMetadata(boolean isFabricMod, RemapRequirements remapRequi return new ArtifactMetadata(isFabricMod, remapRequirements, installerData, refmapRemapType, Collections.unmodifiableList(knownIndyBsms)); } + private static boolean hasRefmaplessMixinConfig(FileSystemUtil.Delegate fs, String mixinConfigs) throws IOException { + for (String mixinConfig : mixinConfigs.split(",")) { + try { + final JsonObject json = LoomGradlePlugin.GSON.fromJson(Files.readString(fs.getPath(mixinConfig)), JsonObject.class); + + if (!json.has("refmap")) { + return true; + } + } catch (JsonSyntaxException e) { + LOGGER.error("Could not parse mixin config in file {}", mixinConfig, e); + } + } + + return false; + } + // Validates that the version matches or is less than the current loom version // This is only done for jars with tiny-remapper remapped mixins. private static void validateLoomVersion(String version, String currentLoomVersion, boolean lenient) {