Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mixin #83

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static List<ITransformationService.Resource> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> mixinConfigs = new ArrayList<>();
private static final List<MixinToAdd> mixinConfigs = new ArrayList<>();

static {
// Register our platform agent first
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading