Jump to content

[1.16] Soft dependency for a mod (running code if a mod is loaded)


A Soulspark

Recommended Posts

I'm once again asking about mod compatibility :v

This time, it's more of a curiosity than a necessity, as I've already come up with a solution to my problem, but I was wondering:

    How do you run some code in 1.16 only if a mod is present?

 

I know there is ModList.get().isLoaded(<modid>but if I import a class that isn't loaded it will still break.

Link to comment
Share on other sites

12 minutes ago, diesieben07 said:

Imports are a compiler fiction, once your code is compiled there are no imports (only fully qualified class names).

Huh, I didn't know that! So an import is just a thing to help code readability?

12 minutes ago, diesieben07 said:

However yes, you are right, you can't just reference a class which might potentially be absent. A good choice for this is to have an interface (this can't reference any of the other mod's classes) and two implementations - one for when the mod is loaded and one for when it isn't.

Oh, I saw a post of yours from a few years ago describing this process, but I wasn't sure if it still applied today. I'll do that then, thanks!

Edited by A Soulspark
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.