Skip to content

Add depends property to Mod annotation for conditional entrypoints#393

Merged
Technici4n merged 8 commits into
neoforged:mainfrom
hedgehog1029:feat/mod-entrypoint-depends
Dec 15, 2025
Merged

Add depends property to Mod annotation for conditional entrypoints#393
Technici4n merged 8 commits into
neoforged:mainfrom
hedgehog1029:feat/mod-entrypoint-depends

Conversation

@hedgehog1029

@hedgehog1029 hedgehog1029 commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

Fixes #201, alternative to #212

This PR adds the ability to specify entrypoints that will only be loaded if the specified mod ID(s) are present:

@Mod(value = "mymod", depends = {"othermod"})
public class MyEntrypoint {
    public MyEntrypoint(ModContainer mod) {
        // for example, now you can depend on OtherModExtension.class safely
        mod.registerExtensionPoint(OtherModExtension.class, () -> new MyOtherModCompatibility());
    }
}

This is implemented by checking against the LoadingModList - entrypoints with depends missing from the loading list are filtered out early.
We enforce in validate that any dependencies specified in the annotation are also specified in the mods.toml - this ensures the mods are loaded in the correct order. No longer enforced, leave it up to developers to choose.

Please let me know if this is a sane approach! Otherwise I suppose I'll have to rethink and move the filtering to a later step.

Unit tests have been added to validate the new behaviour.

@neoforged-automation neoforged-automation Bot added the enhancement New feature or request label Dec 3, 2025
@neoforged-pr-publishing

Copy link
Copy Markdown
  • Publish PR to GitHub Packages

@neoforged-compatibility-checks

neoforged-compatibility-checks Bot commented Dec 3, 2025

Copy link
Copy Markdown

@hedgehog1029, 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: 3a8905b97c3421ccfdc0e195a6c3d6276c20b335.

loader (:loader)

  • net/neoforged/fml/common/Mod
    • depends()[Ljava/lang/String;: ❗ Method was made abstract

Comment thread loader/src/main/java/net/neoforged/fml/javafmlmod/FMLJavaModLanguageProvider.java Outdated
@vfyjxf

vfyjxf commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

why not add a new mod depency type to mods.toml to impl this feature?
Adding new members to Mod annotation look weird, fml currently puts all the metadata in toml

@marchermans

Copy link
Copy Markdown
Member

why not add a new mod depency type to mods.toml to impl this feature? Adding new members to Mod annotation look weird, fml currently puts all the metadata in toml

Personally as a maintainer, I would not like to have a class name in the toml. I already have seen so many times where a class gets renamed and shit breaks. Yeah it takes like 5 minutes to fix, but given that everybody has made that mistake at least once, the time wasted on shit like that is huge, so I would prefer something that follows: one) precedent (which this does because of the dist flag), and two) is potentially something the ide follows (which at least for me string constants are).

If it where up to me it would be some Java language spec default, like a ServiceLoader (because the IDE automatically recognizes it and renames it as well), but that is difficult for us to do. So realistically I think the @mod is the best we can do at the moment.

@vfyjxf

vfyjxf commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

Personally as a maintainer, I would not like to have a class name in the toml. I already have seen so many times where a class gets renamed and shit breaks.

I mean, we hava mod's'.toml, so we can put different mod in same jar. and don't load this optional EntryPoint when its dependencies not satisfied

something like

[[mods]]
modId = "optional_entrypoint"

[[dependencies.optional_entrypoint]]
modId = "jei"
type = "conditional"
versionRange = "[${jei_version},)"
ordering = "NONE"
side = "BOTH"

and we will ignore optional_entrypoint if jei doesn't exist

@Technici4n Technici4n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is good, thank you for writing the tests as well!

@Technici4n Technici4n merged commit 690a3ce into neoforged:main Dec 15, 2025
3 checks passed
@neoforged-releases

Copy link
Copy Markdown

🚀 This PR has been released as FancyModLoader version 10.0.35.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Annotation for loading class if mod is present

4 participants