FancyModLoader icon indicating copy to clipboard operation
FancyModLoader copied to clipboard

Annotation for loading class if mod is present

Open CodexAdrian opened this issue 1 year ago • 6 comments

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 avatar Sep 03 '24 23:09 CodexAdrian

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

TelepathicGrunt avatar Sep 03 '24 23:09 TelepathicGrunt

ideally this could be added to EventBusSubscriber as well

UpcraftLP avatar Sep 04 '24 00:09 UpcraftLP

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 avatar Sep 04 '24 06:09 Matyrobbrt

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

shartte avatar Sep 04 '24 07:09 shartte

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

Technici4n avatar Sep 04 '24 07:09 Technici4n

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

shartte avatar Sep 04 '24 07:09 shartte