Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.