diff --git a/build.gradle b/build.gradle index 6b50fc0d6..7c0b03a21 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,14 @@ allprojects { url = 'https://libraries.minecraft.net' } + maven { + url "https://repo.spongepowered.org/repository/maven-public/" + name "SpongePowered maven" + content { + includeGroup "org.spongepowered" + } + } + // TODO remove mavenLocal() } diff --git a/gradle.properties b/gradle.properties index f2e784977..4873e3690 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ modlauncher_version=10.0.9 securejarhandler_version=2.1.23 bootstraplauncher_version=1.1.2 asm_version=9.5 -mixin_version=0.8.5 +mixin_version=0.8.6-SNAPSHOT terminalconsoleappender_version=1.2.0 nightconfig_version=3.6.4 jetbrains_annotations_version=24.0.1 diff --git a/loader/src/main/java/net/neoforged/fml/loading/FMLLoader.java b/loader/src/main/java/net/neoforged/fml/loading/FMLLoader.java index a1efb7d2e..3e9cbc7a1 100644 --- a/loader/src/main/java/net/neoforged/fml/loading/FMLLoader.java +++ b/loader/src/main/java/net/neoforged/fml/loading/FMLLoader.java @@ -164,7 +164,7 @@ public static List completeScan(IModuleLayerMan loadingModList = backgroundScanHandler.getLoadingModList(); if (loadingModList.getErrors().isEmpty()) { // Add extra mixin configs - extraMixinConfigs.forEach(DeferredMixinConfigRegistration::addMixinConfig); + extraMixinConfigs.forEach(DeferredMixinConfigRegistration::addCommandLineMixinConfig); } return List.of(modValidator.getModResources()); } diff --git a/loader/src/main/java/net/neoforged/fml/loading/LoadingModList.java b/loader/src/main/java/net/neoforged/fml/loading/LoadingModList.java index b790639c5..2021b3101 100644 --- a/loader/src/main/java/net/neoforged/fml/loading/LoadingModList.java +++ b/loader/src/main/java/net/neoforged/fml/loading/LoadingModList.java @@ -80,11 +80,11 @@ public void addCoreMods() } public void addMixinConfigs() { - modFiles.stream() - .map(ModFileInfo::getFile) - .map(ModFile::getMixinConfigs) - .flatMap(List::stream) - .forEach(DeferredMixinConfigRegistration::addMixinConfig); + for (var fileInfo : modFiles) { + for (var config : fileInfo.getFile().getMixinConfigs()) { + DeferredMixinConfigRegistration.addModMixinConfig(config, fileInfo.getFile()); + } + } } public void addAccessTransformers() diff --git a/loader/src/main/java/net/neoforged/fml/loading/mixin/DeferredMixinConfigRegistration.java b/loader/src/main/java/net/neoforged/fml/loading/mixin/DeferredMixinConfigRegistration.java index ef821f703..55cc76dd1 100644 --- a/loader/src/main/java/net/neoforged/fml/loading/mixin/DeferredMixinConfigRegistration.java +++ b/loader/src/main/java/net/neoforged/fml/loading/mixin/DeferredMixinConfigRegistration.java @@ -5,16 +5,18 @@ package net.neoforged.fml.loading.mixin; +import net.neoforged.neoforgespi.locating.IModFile; import org.spongepowered.asm.launch.GlobalProperties; import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.mixin.Mixins; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigSource; import java.util.ArrayList; import java.util.List; public class DeferredMixinConfigRegistration { private static boolean added = false; - private static final List mixinConfigs = new ArrayList<>(); + private static final List mixinConfigs = new ArrayList<>(); static { // Register our platform agent first @@ -24,17 +26,38 @@ public class DeferredMixinConfigRegistration { MixinBootstrap.getPlatform().addContainer(new FMLMixinContainerHandle()); } - public static void addMixinConfig(String config) { + private record MixinToAdd(String config, IMixinConfigSource source) {} + + public static void addCommandLineMixinConfig(String config) { + addMixinConfig(config, new MixinConfigSource(config, "Mixin config passed via --fml.mixinConfig " + config)); + } + + public static void addModMixinConfig(String config, IModFile file) { + String sourceId; + if (file.getModInfos().size() == 1) { + // Single mod, use the modid + sourceId = file.getModInfos().get(0).getModId(); + } else { + // Else use file name... + sourceId = file.getFileName(); + } + + addMixinConfig(config, new MixinConfigSource(sourceId, "Mixin config loaded from mod file " + file.getFilePath())); + } + + private static void addMixinConfig(String config, IMixinConfigSource source) { if (added) { throw new IllegalStateException("Too late to add mixin configs!"); } - mixinConfigs.add(config); + mixinConfigs.add(new MixinToAdd(config, source)); } static void registerConfigs() { added = true; - mixinConfigs.forEach(Mixins::addConfiguration); + mixinConfigs.forEach(c -> { + Mixins.addConfiguration(c.config(), c.source()); + }); mixinConfigs.clear(); } } diff --git a/loader/src/main/java/net/neoforged/fml/loading/mixin/FMLMixinContainerHandle.java b/loader/src/main/java/net/neoforged/fml/loading/mixin/FMLMixinContainerHandle.java index b0f0a5ab5..e87074671 100644 --- a/loader/src/main/java/net/neoforged/fml/loading/mixin/FMLMixinContainerHandle.java +++ b/loader/src/main/java/net/neoforged/fml/loading/mixin/FMLMixinContainerHandle.java @@ -15,6 +15,16 @@ * No attribute because we directly load the mixin configs in {@link FMLMixinPlatformAgent}. */ public class FMLMixinContainerHandle implements IContainerHandle { + @Override + public String getId() { + return "fml"; + } + + @Override + public String getDescription() { + return "FMLMixinContainerHandle, a dummy source used by FML to inject mixin configs from mods at the right time."; + } + @Override public String getAttribute(String name) { return null; diff --git a/loader/src/main/java/net/neoforged/fml/loading/mixin/MixinConfigSource.java b/loader/src/main/java/net/neoforged/fml/loading/mixin/MixinConfigSource.java new file mode 100644 index 000000000..09b48556a --- /dev/null +++ b/loader/src/main/java/net/neoforged/fml/loading/mixin/MixinConfigSource.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) NeoForged and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.neoforged.fml.loading.mixin; + +import org.spongepowered.asm.mixin.extensibility.IMixinConfigSource; + +record MixinConfigSource(String id, String description) implements IMixinConfigSource { + @Override + public String getId() { + return id; + } + + @Override + public String getDescription() { + return description; + } +}