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

The Modular FML #22

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ subprojects { subProject ->
manifest.attributes(
'Git-Commit' : gradleutils.gitInfo.abbreviatedId,
'Build-Number': "${subProject.version}",
'Automatic-Module-Name' : "fml_${subProject.name.replace("-", "_")}",
'FMLModType' : subProject.name.startsWith("language") ? 'LANGPROVIDER' : subProject.name == "events" ? 'GAMELIBRARY' : 'LIBRARY',
'Specification-Title' : "FML${subProject.name}",
'Specification-Vendor' : 'NeoForged',
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dependencies {
api("net.neoforged:bus:${eventbus_version}")

implementation("commons-io:commons-io:${commons_io_version}")
implementation("org.slf4j:slf4j-api:${slf4j_api_version}")
}
27 changes: 27 additions & 0 deletions core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
open module net.neoforged.fancymodloader.core {
requires com.electronwill.nightconfig.core;
requires com.electronwill.nightconfig.toml;
requires com.google.common;
requires com.google.gson;
requires cpw.mods.modlauncher;
requires java.net.http;
requires logging;
requires maven.artifact;
requires net.neoforged.bus;
requires net.neoforged.neoforgespi;
requires net.neoforged.mergetool.api;
requires net.neoforged.fancymodloader.loader;
requires org.apache.commons.io;
requires org.apache.logging.log4j;
requires org.slf4j;
requires static org.jetbrains.annotations;

exports net.neoforged.fml;
exports net.neoforged.fml.config;
exports net.neoforged.fml.event;
exports net.neoforged.fml.util;
exports net.neoforged.fml.util.thread;

uses net.neoforged.fml.IModStateProvider;
uses net.neoforged.fml.IBindingsProvider;
}
18 changes: 18 additions & 0 deletions earlydisplay/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
open module net.neoforged.fancymodloader.earlydisplay {
requires java.desktop;
requires java.management;
requires jdk.management;
requires jopt.simple;
requires net.neoforged.fancymodloader.loader;
requires org.lwjgl.glfw;
requires org.lwjgl.opengl;
requires org.lwjgl.stb;
requires org.lwjgl.tinyfd;
requires org.slf4j;
requires static org.jetbrains.annotations;

exports net.neoforged.fml.earlydisplay;

provides net.neoforged.fml.loading.ImmediateWindowProvider with
net.neoforged.fml.earlydisplay.DisplayWindow;
}

This file was deleted.

14 changes: 14 additions & 0 deletions events/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open module net.neoforged.fancymodloader.events {
requires net.neoforged.fancymodloader.core;
requires net.neoforged.mergetool.api;
requires net.neoforged.fancymodloader.loader;
requires cpw.mods.modlauncher;
requires net.neoforged.bus;

exports net.neoforged.fml.core;
exports net.neoforged.fml.event.config;
exports net.neoforged.fml.event.lifecycle;

provides net.neoforged.fml.IModStateProvider with
net.neoforged.fml.core.ModStateProvider;
}
17 changes: 17 additions & 0 deletions languages/java/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
open module net.neoforged.fancymodloader.language.java {
requires cpw.mods.modlauncher;
requires cpw.mods.securejarhandler;
requires net.neoforged.bus;
requires net.neoforged.neoforgespi;
requires net.neoforged.mergetool.api;
requires net.neoforged.fancymodloader.core;
requires net.neoforged.fancymodloader.loader;
requires org.apache.logging.log4j;
requires org.objectweb.asm;

exports net.neoforged.fml.common;
exports net.neoforged.fml.javafmlmod;

provides net.neoforged.neoforgespi.language.IModLanguageProvider with
net.neoforged.fml.javafmlmod.FMLJavaModLanguageProvider;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public FMLModContainer(IModInfo info, String className, ModFileScanData modFileS
this.contextExtension = () -> contextExtension;
try
{
var layer = gameLayer.findModule(info.getOwningFile().moduleName()).orElseThrow();
modClass = Class.forName(layer, className);
var moduleName = info.getOwningFile().getFile().getSecureJar().moduleDataProvider().descriptor().name();
var module = gameLayer.findModule(moduleName).orElseThrow();
modClass = Class.forName(module, className);
LOGGER.trace(LOADING,"Loaded modclass {} with {}", modClass.getName(), modClass.getClassLoader());
}
catch (Throwable e)
Expand Down

This file was deleted.

16 changes: 16 additions & 0 deletions languages/lowcode/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
open module net.neoforged.fancymodloader.language.lowcode {
requires cpw.mods.modlauncher;
requires logging;
requires net.neoforged.bus;
requires net.neoforged.neoforgespi;
requires net.neoforged.fancymodloader.core;
requires net.neoforged.fancymodloader.loader;
requires org.apache.logging.log4j;
requires org.slf4j;
requires static org.jetbrains.annotations;

exports net.neoforged.fml.lowcodemod;

provides net.neoforged.neoforgespi.language.IModLanguageProvider with
net.neoforged.fml.lowcodemod.LowCodeModLanguageProvider;
}

This file was deleted.

12 changes: 12 additions & 0 deletions languages/minecraft/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
open module net.neoforged.fancymodloader.language.minecraft {
requires net.neoforged.bus;
requires net.neoforged.neoforgespi;
requires net.neoforged.fancymodloader.core;
requires org.apache.logging.log4j;
requires static org.jetbrains.annotations;

exports net.neoforged.fml.mclanguageprovider;

provides net.neoforged.neoforgespi.language.IModLanguageProvider with
net.neoforged.fml.mclanguageprovider.MinecraftModLanguageProvider;
}

This file was deleted.

3 changes: 3 additions & 0 deletions loader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ dependencies {
api("org.ow2.asm:asm:${asm_version}")
api("org.ow2.asm:asm-tree:${asm_version}")
api("org.ow2.asm:asm-commons:${asm_version}")
api("org.ow2.asm:asm-analysis:${asm_version}")
api("org.ow2.asm:asm-util:${asm_version}")
api(project(':spi'))
api("net.neoforged:mergetool:${mergetool_version}:api")
api("org.apache.logging.log4j:log4j-api:${log4j_version}")
Expand All @@ -19,6 +21,7 @@ dependencies {
api("com.mojang:logging:${mojang_logging_version}")
api "net.neoforged:JarJarSelector:${jarjar_version}"
api "net.neoforged:JarJarMetadata:${jarjar_version}"
api("cpw.mods:securejarhandler:${securejarhandler_version}")

implementation("net.sf.jopt-simple:jopt-simple:${jopt_simple_version}")
implementation("cpw.mods:securejarhandler:${securejarhandler_version}")
Expand Down
71 changes: 71 additions & 0 deletions loader/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
open module net.neoforged.fancymodloader.loader {
requires net.neoforged.accesstransformer;
requires net.neoforged.accesstransformer.modlauncher;
requires com.electronwill.nightconfig.core;
requires com.google.common;
requires com.google.gson;
requires cpw.mods.modlauncher;
requires cpw.mods.securejarhandler;
requires JarJarSelector;
requires logging;
requires maven.artifact;
requires net.neoforged.neoforgespi;
requires net.neoforged.mergetool.api;
requires org.apache.commons.lang3;
requires org.apache.logging.log4j.core;
requires org.apache.logging.log4j;
requires org.objectweb.asm.commons;
requires org.objectweb.asm.tree;
requires org.objectweb.asm.tree.analysis;
requires org.objectweb.asm.util;
requires org.objectweb.asm;
requires org.slf4j;
requires org.spongepowered.mixin;
requires terminalconsoleappender;
requires static org.jetbrains.annotations;

exports net.neoforged.fml.common.asm;
exports net.neoforged.fml.loading;
exports net.neoforged.fml.loading.log4j;
exports net.neoforged.fml.loading.moddiscovery;
exports net.neoforged.fml.loading.progress;
exports net.neoforged.fml.loading.targets;
exports net.neoforged.fml.loading.toposort;
exports net.neoforged.fml.server;

uses net.neoforged.neoforgespi.coremod.ICoreModProvider;
uses net.neoforged.neoforgespi.language.IModLanguageProvider;
uses net.neoforged.neoforgespi.locating.IModLocator;
uses net.neoforged.neoforgespi.locating.IDependencyLocator;
uses net.neoforged.fml.loading.ImmediateWindowProvider;

provides cpw.mods.modlauncher.api.ILaunchHandlerService with
net.neoforged.fml.loading.targets.ForgeClientLaunchHandler,
net.neoforged.fml.loading.targets.ForgeClientDevLaunchHandler,
net.neoforged.fml.loading.targets.ForgeClientUserdevLaunchHandler,
net.neoforged.fml.loading.targets.ForgeServerLaunchHandler,
net.neoforged.fml.loading.targets.ForgeServerDevLaunchHandler,
net.neoforged.fml.loading.targets.ForgeServerUserdevLaunchHandler,
net.neoforged.fml.loading.targets.ForgeDataDevLaunchHandler,
net.neoforged.fml.loading.targets.ForgeDataUserdevLaunchHandler;
provides cpw.mods.modlauncher.api.INameMappingService with
net.neoforged.fml.loading.MCPNamingService;
provides cpw.mods.modlauncher.api.ITransformationService with
net.neoforged.fml.loading.FMLServiceProvider;
provides cpw.mods.modlauncher.serviceapi.ILaunchPluginService with
net.neoforged.fml.loading.log4j.SLF4JFixerLaunchPluginService,
net.neoforged.fml.common.asm.RuntimeDistCleaner,
net.neoforged.fml.common.asm.RuntimeEnumExtender;
provides cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService with
net.neoforged.fml.loading.ModDirTransformerDiscoverer,
net.neoforged.fml.loading.ClasspathTransformerDiscoverer;
provides net.neoforged.neoforgespi.locating.IDependencyLocator with
net.neoforged.fml.loading.moddiscovery.JarInJarDependencyLocator;
provides net.neoforged.neoforgespi.locating.IModLocator with
net.neoforged.fml.loading.moddiscovery.ModsFolderLocator,
net.neoforged.fml.loading.moddiscovery.MavenDirectoryLocator,
net.neoforged.fml.loading.moddiscovery.ExplodedDirectoryLocator,
net.neoforged.fml.loading.moddiscovery.MinecraftLocator,
net.neoforged.fml.loading.moddiscovery.ClasspathLocator,
net.neoforged.fml.loading.moddiscovery.BuiltinGameLibraryLocator;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
import cpw.mods.jarhandling.JarContents;
import cpw.mods.jarhandling.JarMetadata;
import cpw.mods.jarhandling.LazyJarMetadata;
import cpw.mods.jarhandling.SecureJar;
import cpw.mods.jarhandling.impl.ModuleJarMetadata;
import net.neoforged.neoforgespi.locating.IModFile;

import java.lang.module.ModuleDescriptor;
import java.util.Objects;
import java.util.Optional;

public final class ModJarMetadata extends LazyJarMetadata implements JarMetadata {
private static final String MODULE_INFO = "module-info.class";
private static final String AUTOMATIC_MODULE_NAME = "Automatic-Module-Name";

private final JarContents jarContents;
private IModFile modFile;

Expand All @@ -27,7 +33,7 @@ public void setModFile(IModFile file) {

@Override
public String name() {
return modFile.getModFileInfo().moduleName();
return descriptor().name();
}

@Override
Expand All @@ -37,14 +43,39 @@ public String version() {

@Override
public ModuleDescriptor computeDescriptor() {
var bld = ModuleDescriptor.newAutomaticModule(name())
.version(version())
.packages(jarContents.getPackagesExcluding("assets", "data"));
jarContents.getMetaInfServices().stream()
.filter(p -> !p.providers().isEmpty())
.forEach(p -> bld.provides(p.serviceName(), p.providers()));
modFile.getModFileInfo().usesServices().forEach(bld::uses);
return bld.build();
SecureJar secureJar = modFile.getSecureJar();
// Try reading descriptor from module-info.class first
SecureJar.ModuleDataProvider provider = secureJar.moduleDataProvider();
return provider.findFile(MODULE_INFO)
.map(uri -> {
// Use ModuleJarMetadata to read the descriptor
JarMetadata metadata = new ModuleJarMetadata(uri, () -> jarContents.getPackagesExcluding("assets", "data"));
ModuleDescriptor jarDescriptor = metadata.descriptor();
// Convert descriptor to builder
var builder = wrapDescriptor(jarDescriptor)
// Use version from mod metadata
.version(version());
return builder.build();
})
// If the jar does not contain a module descriptor, we build one ourselves
.orElseGet(() -> {
// Use Automatic-Module-Name first, fallback to modid
var name = Optional.ofNullable(provider.getManifest().getMainAttributes().getValue(AUTOMATIC_MODULE_NAME))
.orElseGet(() -> modFile.getModFileInfo().moduleName());
// Build module descriptor as automatic module. This ensures the module is open, exports all packages and mutually reads all other modules.
var bld = ModuleDescriptor.newAutomaticModule(name)
// Use version from mod metadata
.version(version())
// Add all packages
.packages(jarContents.getPackagesExcluding("assets", "data"));
// Add service providers
jarContents.getMetaInfServices().stream()
.filter(p -> !p.providers().isEmpty())
.forEach(p -> bld.provides(p.serviceName(), p.providers()));
// Add used services from mod metadata
modFile.getModFileInfo().usesServices().forEach(bld::uses);
return bld.build();
});
}

public IModFile modFile() {
Expand All @@ -68,4 +99,17 @@ public int hashCode() {
public String toString() {
return "ModJarMetadata[" +"modFile=" + modFile + ']';
}

// Create a module descriptor builder from an existing descriptor, allowing us to modify and re-build it
private ModuleDescriptor.Builder wrapDescriptor(ModuleDescriptor descriptor) {
var builder = ModuleDescriptor.newModule(descriptor.name(), descriptor.modifiers());
builder.packages(descriptor.packages());
descriptor.version().ifPresent(builder::version);
descriptor.requires().forEach(builder::requires);
descriptor.exports().forEach(builder::exports);
descriptor.opens().forEach(builder::opens);
descriptor.uses().forEach(builder::uses);
descriptor.provides().forEach(builder::provides);
return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void configureTransformationClassLoader(final ITransformingClassLoaderBui

protected String[] preLaunch(String[] arguments, ModuleLayer layer) {
URI uri;
try (var reader = layer.configuration().findModule("fml_loader").orElseThrow().reference().open()) {
try (var reader = layer.configuration().findModule("net.neoforged.fancymodloader.loader").orElseThrow().reference().open()) {
uri = reader.find("log4j2.xml").orElseThrow();
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FMLClientLaunchHandler extends CommonClientLaunchHandler {

@Override
protected void processMCStream(VersionInfo versionInfo, Stream.Builder<Path> mc, Stream.Builder<List<Path>> mods) {
var fmlonly = LibraryFinder.findPathForMaven("net.neoforged.fml", "fmlonly", "", "universal", versionInfo.mcAndFmlVersion());
var fmlonly = LibraryFinder.findPathForMaven("net.neoforged.fancymodloader", "fmlonly", "", "universal", versionInfo.mcAndFmlVersion());
mods.add(List.of(fmlonly));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FMLServerLaunchHandler extends CommonServerLaunchHandler {

@Override
protected void processMCStream(VersionInfo versionInfo, Stream.Builder<Path> mc, Stream.Builder<List<Path>> mods) {
var fmlonly = LibraryFinder.findPathForMaven("net.neoforged.fml", "fmlonly", "", "universal", versionInfo.mcAndFmlVersion());
var fmlonly = LibraryFinder.findPathForMaven("net.neoforged.fancymodloader", "fmlonly", "", "universal", versionInfo.mcAndFmlVersion());
mods.add(List.of(fmlonly));
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading