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

Rewrite language loaders and allow for multiple entrypoints per mod #126

Merged
merged 9 commits into from
May 4, 2024

Conversation

Matyrobbrt
Copy link
Member

@Matyrobbrt Matyrobbrt commented May 3, 2024

This PR changes language loaders to directly load mods instead of relying on a scan data consumer, and allows a mod file to have different mods loaded with different locators. Right now there's no way to express it in the default toml format, but that can be changed.
It also allows a javafml mod to have multiple @Mod annotations, with an optional dist parameter.

@Matyrobbrt Matyrobbrt added enhancement New feature or request breaking-change labels May 3, 2024
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented May 3, 2024

  • Publish PR to GitHub Packages

Last commit published: 567632e2ab2c7dd4be91462df1d7b1f11dfc622d.

PR Publishing

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven {
        name 'Maven for PR #126' // https://github.com/neoforged/FancyModLoader/pull/126
        url 'https://prmaven.neoforged.net/FancyModLoader/pr126'
        content {
            includeModule('net.neoforged.fancymodloader', 'earlydisplay')
            includeModule('net.neoforged.fancymodloader', 'loader')
        }
    }
}

@neoforged-compatibility-checks
Copy link

neoforged-compatibility-checks bot commented May 3, 2024

@Matyrobbrt, this PR introduces breaking changes.
Fortunately, this project is currently accepting breaking changes, but if they are not intentional, please revert them.
Last checked commit: 567632e2ab2c7dd4be91462df1d7b1f11dfc622d.

Compatibility checks

loader (:loader)

  • net/neoforged/fml/mclanguageprovider/MinecraftModLanguageProvider
    • ❗ Class missing interface: net/neoforged/neoforgespi/language/IModLanguageProvider
    • getFileVisitor()Ljava/util/function/Consumer;: ❗ API method was removed
  • net/neoforged/fml/javafmlmod/FMLJavaModLanguageProvider
    • ❗ Class missing interface: net/neoforged/neoforgespi/language/IModLanguageProvider
    • getFileVisitor()Ljava/util/function/Consumer;: ❗ API method was removed
    • MODANNOTATION:Lorg/objectweb/asm/Type;: ❗ API field was removed
  • net/neoforged/fml/javafmlmod/AutomaticEventSubscriber
    • inject(Lnet/neoforged/fml/ModContainer;Lnet/neoforged/neoforgespi/language/ModFileScanData;Ljava/lang/ClassLoader;)V: ❗ API method was removed
  • net/neoforged/fml/ModContainer
    • matches(Ljava/lang/Object;)Z: ❗ API method was removed
    • getMod()Ljava/lang/Object;: ❗ API method was removed
  • net/neoforged/neoforgespi/language/ModFileScanData
    • addLanguageLoader(Ljava/util/Map;)V: ❗ API method was removed
    • getTargets()Ljava/util/Map;: ❗ API method was removed
    • interestingAnnotations()Ljava/util/function/Predicate;: ❗ API method was removed
  • net/neoforged/neoforgespi/language/IModLanguageProvider$IModLanguageLoader
    • ❗ API class no longer exists
  • net/neoforged/fml/common/Mod
    • dist()[Lnet/neoforged/api/distmarker/Dist;: ❗ Method was made abstract
  • net/neoforged/fml/javafmlmod/FMLModContainer
    • matches(Ljava/lang/Object;)Z: ❗ API method was removed
    • <init>(Lnet/neoforged/neoforgespi/language/IModInfo;Ljava/lang/String;Lnet/neoforged/neoforgespi/language/ModFileScanData;Ljava/lang/ModuleLayer;)V: ❗ API method was removed
    • getMod()Ljava/lang/Object;: ❗ API method was removed
  • net/neoforged/fml/mclanguageprovider/MinecraftModContainer
    • matches(Ljava/lang/Object;)Z: ❗ API method was removed
    • getMod()Ljava/lang/Object;: ❗ API method was removed
  • net/neoforged/fml/loading/LanguageProviderLoader$ModLanguageWrapper
    • modLanguageProvider()Lnet/neoforged/neoforgespi/language/IModLanguageProvider;: ❗ API method was removed
  • net/neoforged/neoforgespi/language/IModInfo
    • getLoader()Lnet/neoforged/neoforgespi/language/IModLanguageLoader;: ❗ Method was made abstract
  • net/neoforged/fml/loading/LanguageProviderLoader
    • findLanguage(Lnet/neoforged/fml/loading/moddiscovery/ModFile;Ljava/lang/String;Lorg/apache/maven/artifact/versioning/VersionRange;)Lnet/neoforged/neoforgespi/language/IModLanguageProvider;: ❗ API method was removed
  • net/neoforged/neoforgespi/language/IModLanguageProvider
    • ❗ API class no longer exists
  • net/neoforged/fml/ModList
    • getModContainerByObject(Ljava/lang/Object;)Ljava/util/Optional;: ❗ API method was removed
    • getModObjectById(Ljava/lang/String;)Ljava/util/Optional;: ❗ API method was removed
  • net/neoforged/neoforgespi/locating/IModFile
    • getLoaders()Ljava/util/List;: ❗ API method was removed
  • net/neoforged/fml/lowcodemod/LowCodeModLanguageProvider
    • ❗ Class missing interface: net/neoforged/neoforgespi/language/IModLanguageProvider
    • getFileVisitor()Ljava/util/function/Consumer;: ❗ API method was removed
  • net/neoforged/fml/lowcodemod/LowCodeModContainer
    • matches(Ljava/lang/Object;)Z: ❗ API method was removed
    • getMod()Ljava/lang/Object;: ❗ API method was removed
  • net/neoforged/fml/mclanguageprovider/MinecraftModLanguageProvider$MinecraftModTarget
    • ❗ API class no longer exists
  • net/neoforged/fml/loading/modscan/ModAnnotation$EnumHolder
    • ❗ Class was made final
    • getDesc()Ljava/lang/String;: ❗ API method was removed
    • getValue()Ljava/lang/String;: ❗ API method was removed

Comment on lines +18 to +23
private static final Supplier<Map<String, String>> globals = Suppliers.memoize(() -> {
final var globals = new HashMap<String, String>();
globals.put("mcVersion", FMLLoader.versionInfo() == null ? null : FMLLoader.versionInfo().mcVersion());
globals.put("neoForgeVersion", FMLLoader.versionInfo() == null ? null : FMLLoader.versionInfo().neoForgeVersion());
return globals;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeh this sucks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor for later: not make this static

@@ -55,7 +54,8 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si

public void buildData(final Set<ModFileScanData.ClassData> classes, final Set<ModFileScanData.AnnotationData> annotations) {
classes.add(new ModFileScanData.ClassData(this.asmType, this.asmSuperType, this.interfaces));
final List<ModFileScanData.AnnotationData> collect = this.annotations.stream().filter(ma -> ModFileScanData.interestingAnnotations().test(ma.getASMType())).map(a -> ModAnnotation.fromModAnnotation(this.asmType, a)).collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kek

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so one way (later) to speed up annotation scanning is to reintroduce the "annotation interest" but it's complex, so forget about it for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation has no speed impact regardless, at best a memory impact, as ann data has already been collected by then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just meant that in general, to make any sense at all it'd need to use constant-pool scanning based on the interest to avoid having to parse the class-file in the first place.
But assuming we can just cache the entire annotation index per-jar based on a file-checksum, the speed advantage probably diminishes.

@shartte shartte self-requested a review May 3, 2024 21:17
@Matyrobbrt Matyrobbrt merged commit 9cf72d0 into neoforged:main May 4, 2024
3 checks passed
@Matyrobbrt Matyrobbrt changed the title Rewrite locators and allow for multiple entrypoints per mod Rewrite language loaders and allow for multiple entrypoints per mod May 4, 2024
@Matyrobbrt Matyrobbrt deleted the change-locators branch May 12, 2024 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants