Skip to content

Commit 6fab9f7

Browse files
committed
Register plugins as mixin containers on Neo
1 parent a3cb316 commit 6fab9f7

5 files changed

Lines changed: 45 additions & 30 deletions

File tree

‎neoforge/src/applaunch/java/org/spongepowered/neoforge/applaunch/mod/discovery/SpongeLanguageLoader.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import net.neoforged.neoforgespi.language.ModFileScanData;
3434
import org.apache.logging.log4j.LogManager;
3535
import org.apache.logging.log4j.Logger;
36+
import org.spongepowered.common.applaunch.AppLaunch;
37+
import org.spongepowered.neoforge.applaunch.plugin.NeoPluginPlatform;
3638

3739
import java.lang.reflect.Constructor;
3840
import java.lang.reflect.InvocationTargetException;
@@ -41,6 +43,10 @@
4143
public final class SpongeLanguageLoader extends BuiltInLanguageLoader {
4244
private static final Logger LOGGER = LogManager.getLogger();
4345

46+
public SpongeLanguageLoader() {
47+
AppLaunch.<NeoPluginPlatform>pluginPlatform().discovery().registerMixinContainers();
48+
}
49+
4450
@Override
4551
public String name() {
4652
return "sponge";

‎neoforge/src/applaunch/java/org/spongepowered/neoforge/applaunch/mod/metadata/PluginFileConfigurable.java‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,6 @@ public List<? extends IConfigurable> getConfigList(final String... key) {
111111
return this.plugins.values().stream().map(PluginMetadataConfigurable::new).toList();
112112
}
113113

114-
if ("mixins".equals(query)) {
115-
final Optional<String> mixinConfigs = this.resource.property("MixinConfigs");
116-
if (mixinConfigs.isEmpty()) {
117-
return Collections.emptyList();
118-
}
119-
120-
final List<IConfigurable> mixinConfigurables = new ArrayList<>();
121-
for (final String config : mixinConfigs.get().split(",")) {
122-
mixinConfigurables.add(new PluginMixinConfigurable(config.trim()));
123-
}
124-
return mixinConfigurables;
125-
}
126-
127114
if (key.length != 2) {
128115
return Collections.emptyList();
129116
}

‎neoforge/src/applaunch/java/org/spongepowered/neoforge/applaunch/plugin/discovery/JarContentsPluginResource.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import net.neoforged.fml.jarcontents.JarContents;
2828
import net.neoforged.fml.jarmoduleinfo.JarModuleInfo;
29+
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
2930
import org.spongepowered.common.applaunch.plugin.discovery.SpongeJVMPluginResource;
3031

3132
import java.io.IOException;
@@ -41,6 +42,7 @@
4142
public final class JarContentsPluginResource implements SpongeJVMPluginResource {
4243
private final List<Path> paths;
4344
private final JarContents jar;
45+
private @MonotonicNonNull ModuleDescriptor descriptor;
4446

4547
public JarContentsPluginResource(final Path[] paths) {
4648
Objects.requireNonNull(paths, "paths");
@@ -82,7 +84,10 @@ public Manifest manifest() {
8284

8385
@Override
8486
public ModuleDescriptor module() {
85-
return JarModuleInfo.from(this.jar).createDescriptor(this.jar);
87+
if (this.descriptor == null) {
88+
this.descriptor = JarModuleInfo.from(this.jar).createDescriptor(this.jar);
89+
}
90+
return this.descriptor;
8691
}
8792

8893
@Override

‎neoforge/src/applaunch/java/org/spongepowered/neoforge/applaunch/plugin/discovery/NeoPluginDiscovery.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import net.neoforged.fml.jarcontents.CompositeJarContents;
2828
import net.neoforged.fml.jarcontents.JarContents;
29+
import net.neoforged.fml.loading.mixin.FMLMixinService;
30+
import org.spongepowered.asm.service.MixinService;
2931
import org.spongepowered.common.applaunch.plugin.discovery.PluginDiscovery;
3032
import org.spongepowered.common.applaunch.plugin.discovery.SpongeJVMPluginResource;
3133
import org.spongepowered.plugin.Environment;
@@ -71,4 +73,14 @@ protected void appendDiscoveryServices(final List<SpongeJVMPluginResource> resou
7173
this.currentLoader = loader;
7274
this.environment.logger().debug("Built new service layer {} on top of {}.", loader.getName(), parentLoader.getName());
7375
}
76+
77+
@SuppressWarnings("UnstableApiUsage")
78+
public void registerMixinContainers() {
79+
final FMLMixinService mixinService = (FMLMixinService) MixinService.getService();
80+
for (final PluginDiscovery.Candidate candidate : this.candidates()) {
81+
if (candidate.pluginFound() && candidate.resource() instanceof JarContentsPluginResource jarResource) {
82+
mixinService.addMixinContainer(new PluginResourceContainerHandle(jarResource));
83+
}
84+
}
85+
}
7486
}

neoforge/src/applaunch/java/org/spongepowered/neoforge/applaunch/mod/metadata/PluginMixinConfigurable.java renamed to neoforge/src/applaunch/java/org/spongepowered/neoforge/applaunch/plugin/discovery/PluginResourceContainerHandle.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,37 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
package org.spongepowered.neoforge.applaunch.mod.metadata;
25+
package org.spongepowered.neoforge.applaunch.plugin.discovery;
2626

27-
import net.neoforged.neoforgespi.language.IConfigurable;
27+
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
2828

29-
import java.util.Collections;
29+
import java.util.Collection;
3030
import java.util.List;
31-
import java.util.Optional;
3231

33-
public final class PluginMixinConfigurable implements IConfigurable {
34-
private final String config;
32+
public class PluginResourceContainerHandle implements IContainerHandle {
33+
private final JarContentsPluginResource resource;
3534

36-
public PluginMixinConfigurable(final String config) {
37-
this.config = config;
35+
public PluginResourceContainerHandle(final JarContentsPluginResource resource) {
36+
this.resource = resource;
3837
}
3938

40-
@SuppressWarnings("unchecked")
4139
@Override
42-
public <T> Optional<T> getConfigElement(final String... key) {
43-
if (key.length == 1 && "config".equals(key[0])) {
44-
return Optional.of((T) this.config);
45-
}
46-
return Optional.empty();
40+
public String getAttribute(final String name) {
41+
return this.resource.property(name).orElse(null);
4742
}
4843

4944
@Override
50-
public List<? extends IConfigurable> getConfigList(final String... key) {
51-
return Collections.emptyList();
45+
public Collection<IContainerHandle> getNestedContainers() {
46+
return List.of();
47+
}
48+
49+
@Override
50+
public String getId() {
51+
return this.resource.module().name();
52+
}
53+
54+
@Override
55+
public String getDescription() {
56+
return this.resource.toString();
5257
}
5358
}

0 commit comments

Comments
 (0)