Jump to content

Using Reflections doesn't work outside deobfuscated environments


Recommended Posts

I know this isn't forge's fault but I actually have no idea why this happens, so basically I'm trying to get all classes in a package that extends a class, I've used reflections8 and and older verison of org.reflections since it seems bugged, but this issue stayed as is in obfuscated environments, and only worked inside IDE, here's the code :

public static Set<Class<? extends PluginHelper>> getAllPlugins() {
		Reflections reflections = new Reflections("ms55.moreplates.common.plugin");

		return reflections.getSubTypesOf(PluginHelper.class);

How do I make it obfuscation friendly?

Link to comment
Share on other sites

If you want to look at type heirarchy or annotation data, Forge has already searched the classpath for annotations and types for mod loading and event bus subscription. Here's what it would look like to use it for something:

public static Set<Class<? extends ParentClass>> init() {
  return ModList.get()
    .filter(data -> "your.ParentClass".equals(data.parent.getClassName()))

This is very simplistic, because the `parent` field is private, so you would have to use reflection, and `Class.forName(String)` throws some things, so it can't be used in a method reference like that, but otherwise, this kind of thing has worked for me before.

Edited by Vinyarion

Have you ever want the new operator to return a type that you didn't ask for? Well, now you can!

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.

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.

  • Create New...

Important Information

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