Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Using reflections on another loaded mod.


Recommended Posts

Hi.

Sorry in advance if this question was asked, but I couldn't find any instance of it on here.
My question is, can (and if yes, then how) I use org.reflections on other loaded mods?
I tried looking it up online, but I couldn't get it to work.

More specifically, I wanted to look for classes extending a certain class in another mod.
I know it should look something like this, but I'm not sure what to put into parameters in new Reflection().
(It's worth noting that I already have the ModContainer as well as ModObject of the mod I want to modify in a variable if that helps)

Reflections reflections = new Reflections("package.goes.here");            
Set<Class<? extends CertainClass>> CertainClassSet = reflections.getSubTypesOf(CertainClass.class);

Any help from you all is appreciated, and again, sorry if this question was asked / is basic.

Link to comment
Share on other sites

Just now, diesieben07 said:

This is a bad idea. Why do you need subtypes of a class?

I wanted to get all classes extending Screen for a thing I was doing.  Speaking more generally, I am looking for a way to "modify" the other's mod behaviour without getting into bytecode manipulation (Getting all Screen classes was not a part of that, I wanted to test something out). I was looking for something similiar to the Harmony.Lib in C#.

Link to comment
Share on other sites

I don't know C#.

Getting all subclasses for a class involves classpath scanning, which is not a trivial task at all. I would recommend the ClassGraph library, which is well maintained and supports the Java module system (which Forge now uses) as well.

However I would ask you to please describe what you want to do more clearly. Most likely there are better ways to achieve what yoou want.

Link to comment
Share on other sites

1 minute ago, diesieben07 said:

I don't know C#.

Getting all subclasses for a class involves classpath scanning, which is not a trivial task at all. I would recommend the ClassGraph library, which is well maintained and supports the Java module system (which Forge now uses) as well.

However I would ask you to please describe what you want to do more clearly. Most likely there are better ways to achieve what yoou want.

I'll try to describe what I want to achieve:

The mod that I'm trying to modify has some custom GUI's, which I want to open by my mod.
My thinking was, if I can get all Screen classes, I can search for the one I need and open it if you know what I mean.

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.