Posted December 8, 20204 yr 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?
December 10, 20204 yr 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() .getAllScanData() .stream() .map(ModFileScanData::getClasses) .flatMap(Collection::stream) .filter(data -> "your.ParentClass".equals(data.parent.getClassName())) .map(Type::getClassName) .map(Class::forName) .map(ParentClass.class::asSubclass) .collect(Collectors.toSet()); } 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 December 10, 20204 yr by Vinyarion Have you ever want the new operator to return a type that you didn't ask for? Well, now you can!
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.