Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Getting forge to recognize a class
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Sparrow

Getting forge to recognize a class

By Sparrow, September 15, 2013 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Sparrow    0

Sparrow

Sparrow    0

  • Tree Puncher
  • Sparrow
  • Members
  • 0
  • 4 posts
Posted September 15, 2013

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.

  • Quote

Share this post


Link to post
Share on other sites

GotoLink    381

GotoLink

GotoLink    381

  • World Shaper
  • GotoLink
  • Members
  • 381
  • 2012 posts
Posted September 16, 2013

But once the mod is added into a clean forge jar

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

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7613

diesieben07

diesieben07    7613

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7613
  • 55180 posts
Posted September 16, 2013

What are you even trying to do?

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

  • Quote

Share this post


Link to post
Share on other sites

Sparrow    0

Sparrow

Sparrow    0

  • Tree Puncher
  • Sparrow
  • Members
  • 0
  • 4 posts
Posted September 23, 2013

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.

  • Quote

Share this post


Link to post
Share on other sites

Mew    36

Mew

Mew    36

  • Dragon Slayer
  • Mew
  • Members
  • 36
  • 567 posts
Posted September 23, 2013

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

  • Quote

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

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Jack Richard
      [1.15.2] Minecraft Registry Problem When Loading from Jar

      By Jack Richard · Posted 2 hours ago

      Thanks so much for your help! I removed the log4j dependency, I honesty don't remember when I put that there. Once I fixed the jar.finalizedBy line, everything worked! (One small issue where I was relocating all of "com.google" when I just should've relocated "com.google.common," too)   Thanks again!
    • Teedledee
      1.16.4 Failed to synchronize registry data with server LAN

      By Teedledee · Posted 2 hours ago

      Fixed the issue, one config didnt match, downloaded randompatches to solve badly compressed packet afterwards.
    • DaemonUmbra
      [1.15.2] Minecraft Registry Problem When Loading from Jar

      By DaemonUmbra · Posted 2 hours ago

      First of all, why are you shadowing log4j? Minecraft already provides log4j2. Second if build is running shadowjar instead of jar then you might need to tweak the line where it says jar.finalizedBy('reobfJar') to finalize shadowJar instead
    • DaemonUmbra
      "The game crashed whilst rendering overlay"

      By DaemonUmbra · Posted 2 hours ago

      What do you think you should do about this?
    • DaemonUmbra
      IntelliJ doesn't include resources folder while debugging

      By DaemonUmbra · Posted 2 hours ago

      What version of Minecraft are you using?
  • Topics

    • Jack Richard
      2
      [1.15.2] Minecraft Registry Problem When Loading from Jar

      By Jack Richard
      Started 3 hours ago

    • Teedledee
      2
      1.16.4 Failed to synchronize registry data with server LAN

      By Teedledee
      Started January 18

    • GuyWithTVHead
      1
      "The game crashed whilst rendering overlay"

      By GuyWithTVHead
      Started 2 hours ago

    • GermanBucket
      2
      IntelliJ doesn't include resources folder while debugging

      By GermanBucket
      Started 4 hours ago

    • Arthurmeade12
      8
      Error Conecting to My Minecraft Server

      By Arthurmeade12
      Started Saturday at 11:05 PM

  • Who's Online (See full list)

    • DaemonUmbra
    • NullBite
    • Inforno
    • ChampionAsh5357
    • HoldenTheGamer
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Getting forge to recognize a class
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community