Jump to content

Cross-mod Capability behaviour


HashtagShell

Recommended Posts

I've thought of this scenario, and I'm not sure how the capability system would behave in it:

Say mod A defines a handler interface adev.amod.AHandler, and uses it as a capability:

@CapabilityInject(AHandler.class)
public static Capability<IItemHandler> A_HANDLER_CAPABILITY = null;

However, it doesn't publish the capability as part of its API and it doesn't public its source, so I cannot compile against it.

If I, in my apis source set, in the same package define structurally the same interface, and use @CapabilityInject on it, will I get the same instance of the Capability as the one in mod A? How does change when I do/don't ship the AHandler interface with my mod? What if the mod is not present at runtime, will @CapabilityInject still try to reference the missing interface and crash? (I cannot really do any programmatic checks for the presence of the mod since annotations are compile-time constants)

This is a theoretical scenario, any mod that is worth building against will have their capabilities published.

Link to comment
Share on other sites

The entire point of the capability system is that it is a soft reference.

Unless you do some dirty reflection hacks specifically on that field to resolve the generic type. Then it wont crash.

As for you faking the cap with your own code. Yes its possible, the JVM doesn't care who wrote the class as long as its structurally the same.

However it is better to talk to the mod author to see if they WANT to allow others to access that cap/feature of their mod.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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.