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'm developing a coremod. One of the things this mod does is load all the classes implementing a certain type from a certain package.

 

By default the classloader doesn't recognize a package until it has to load a class from that package. So I force the classloader to be aware of it. In development/eclipse, this works just fine. But once the mod is added into a clean forge jar, the classloader is not finding the package no matter what I do.

 

Some of the things I've tried:

		Class<Module> someModule = Module.class; //should make the classloader aware
	try {
		ClassLoader.getSystemResources("net.*"); //should load the net.sparrow package
	} catch (IOException e2) {
		// TODO Auto-generated catch block
		e2.printStackTrace();
	}
	try {
		Module.class.getClassLoader().loadClass("net.sparrow.module.Module"); //should FORCE the class to load
	} catch (ClassNotFoundException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	Package[] knownPacks = Package.getPackages(); //prints all known packages from the classloader
//note that it does NOT print aynthing from the packages described above (net.sparrow)
	for(int i = 0; i < knownPacks.length; i++) {
		FMLLog.info("Package:" + knownPacks[i], 0);
	}
	ArrayList<Class<?>> moduleList = UtilFile.getClassesForPackage(Module.class.getPackage());
//getPackage() is always returning null.

But once the mod is added into a clean forge jar

Jar editing ? You are doing it wrong. Mod goes in mods folder.

  • Author

Jar editing ? You are doing it wrong. Mod goes in mods folder.

Yes I'm aware, I'm developing a coremod which modifies base mc files

 

What are you even trying to do?

As soon as you do Module.class it already loads the class anyways.

I know, that's what I thought.

 

My mod basically looks for all the .class files in a certain package in the jar. So you just open up the package and iterate through the files, instantiating a new copy of each of them as you go.

 

The problem is that the classloader has not been made aware of the package, and thus refuses to load it. Ok, fair enough, just force the classloader to load a .class file from the package itself (like Module.class) and then it'll load up the package into memory. In the development environment, this works just fine. But as soon as it's simply inserted into a clear .jar file, Forge's classloader fails to pick up the package. I wonder if that's a fault of Forge's or something else.

GotoLink is ABSOLUTELY RIGHT!

 

Even if it is a core mod that edits base files, it is still a MOD so it goes in the MODS FOLDER. It should then be able to iterate as you are wanting to do. ( Notice I said SHOULD... )

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

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.