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

Annotation for loading class if mod is present #201

Open
CodexAdrian opened this issue Sep 3, 2024 · 6 comments
Open

Annotation for loading class if mod is present #201

CodexAdrian opened this issue Sep 3, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@CodexAdrian
Copy link

CodexAdrian commented Sep 3, 2024

Its common practice for mods to add apis or features other devs can use to add integration. For optional integration its common place for a dev to put the compat in a different class and then call that class with an if check for if the mod is loaded. This is fine, but I think itd be super helpful to have something to conditionally load a class with an annotation. like

@Mod(value = "modid", required = "argonauts")

So that the class will only ever load if the mod "argonauts" is present.

@CodexAdrian CodexAdrian added the enhancement New feature or request label Sep 3, 2024
@TelepathicGrunt
Copy link
Contributor

required would ideally be a list of modids where all modids present would then run the class

@UpcraftLP
Copy link

ideally this could be added to EventBusSubscriber as well

@Matyrobbrt
Copy link
Member

Matyrobbrt commented Sep 4, 2024

required would ideally be a list of modids where all modids present would then run the class

I could see an use case where the list could be treated as an OR too (i.e. run this code if any recipe viewer is present or if any jade-like mod is present or if any mod with which I have optional recipes is present).
Heck, could even see it useful to run code when the mod isn't present (maybe when iris or a mod that adds connected textures isn't present)

This might be complicating it but a list of @Dependency annotations with their combination strategies would be interesting.

@Matyrobbrt Matyrobbrt transferred this issue from neoforged/NeoForge Sep 4, 2024
@shartte
Copy link
Contributor

shartte commented Sep 4, 2024

If we do it, we should go full hog with conditionals, in my opinion.

@Technici4n
Copy link
Member

Why not just load the class via reflection in the mod, instead of adding more magic just to save a few LOC?

@shartte
Copy link
Contributor

shartte commented Sep 4, 2024

Why not just load the class via reflection in the mod, instead of adding more magic just to save a few LOC?

The same argument could be applied to dist-conditions

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

No branches or pull requests

6 participants