Jump to content

Recommended Posts

Posted

I am kinda lost here.

 

Class<?> clazz = urlClassLoader.loadClass(name.substring(0, name.length() - 6).replaceAll("/", "."));

And it is SkillFireball for sure (I can print fields/method names)

System.out.println(clazz.isInstance(SkillCast.class));
System.out.println(SkillCast.class.isInstance(clazz));
System.out.println(SkillCast.class.isAssignableFrom(clazz));
System.out.println(clazz.isAssignableFrom(SkillCast.class));

public class SkillFireball extends SkillCast implements ISkillThrown
public abstract class SkillCast extends Skill

My prints are ALL false. Note: I am loading classes with ClassLoader (might be important).

 

Anyone has idea?

 

Goal: obviously, get 'true' if class is child of SkillCast.

 

1.7.10 is no longer supported by forge, you are on your own.

Posted

Well, I know it makes no sense, I've been reading docs for past 30min, but it still is NOT working (made it to make sure).

 

I am using new ClassLoader for my Skill API. You can make skills compile them into jars and throw into gameDir/RoA/Skills/...

SkillLoader will read this dir for .jar-s and scan them for classes that are childs of Skill / SkillCast and register them into my SkillRegistry.

 

System is designed to dynamically load stuff and also send skills to client and load them in runtime (on both client/server).

 

EDIT:

Can this be caused that API is loded by Forge (as a mod) and Skill.jar-s are loaded by different loader?

 

Looking at this:

Why do you use a new ClassLoader? :o

I think that's the problem. How can I get forge's/Minecraft ClassLoader?

1.7.10 is no longer supported by forge, you are on your own.

Posted

Okay, I am apparently totally green here. I know now that I need to load new classes (skills) into same classLoader as my mod.

 

How can I do that?

 

ClassLoader cl = Loader.instance().getModClassLoader();

 

I seriously have no idea how to ADD new classees to existing CL.

 

I know this will crash, obviously, I want to know how to put (load .jar-s) my urls list into mod's CL.

//urls are URI to my .jar-s
ClassLoader cl = Loader.instance().getModClassLoader();
urlClassLoader = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]), cl);

 

@Anon10W1z

Structure goes:

Mod - handles skills

API - allows to make new skills

Config - allows to script skills using coded skills via API. That means you can make new skills using ones coded in code (obviously, that is smarter than coding skill using forge methods inside json/txt).

1.7.10 is no longer supported by forge, you are on your own.

Posted

Actually I've done it, it was more lack of knowledge about ClassLoaders and how Java loads classes.

 

skillClassLoader = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]), Loader.instance().getModClassLoader());

Loads skill.jar-s to child loader.

//where name is url to this class file
Class<?> clazz = Loader.instance().getModClassLoader().loadClass(name.substring(0, name.length() - 6).replaceAll("/", "."));
if (SkillCast.class.isAssignableFrom(clazz))
//do stuff

 

I was badly accessing created classes.

 

Problem solved.

 

And how it works:

Mod processes data and has API that allows you to make Skills.

There are build-in set of skills (like fireballs, some other stuff, will be more with every update), but also if there is lack of something, some dev might wanna create new skill - and he can.

Config allows you to without java interaction get ANY pre-made skill to be get and used to script custom one. Most of skills can still be made without any java interaction, API is only for advanced stuff and special rendering (which is also the reason I want to send skill.jar to client).

 

Thread closed.

 

 

1.7.10 is no longer supported by forge, you are on your own.

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

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

Announcements



×
×
  • Create New...

Important Information

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