How do I make a moddable game in Java?

How would I make a moddable game in Java with the Java ClassLoader, I can’t seem to find anything related to what I’m trying to do with my game. In my game I want it to do the same thing that Forge Mod Loader for Minecraft does(It finds the mods in a specific folder and loads them). I want people or a community of people to be able to easily modify my game. I already know that I would need to create some kind of API but the only problem is how to find and load the JAR file then run it from a ‘main’ method. If anyone could help me with this topic and or has any questions about my question just say.

I’d create a game first. Because if you haven’t even put content in, why would a community do it? If they are making mods and content for your entire game, they might as well just create a game themselves, aye?

Perhaps take a look at OSGi; in particular Apache Felix http://felix.apache.org/. OSGi handles loading modules including handling all of the classloader aspects, but doesn’t provide an in app API beyond the services registry of the OSGi framework itself which stops short more or less with what is needed in a game. This is where matching OSGi with an in app component architecture really shines and is the direction I’ve been moving down for quite some time as far as engine / framework architecture is concerned.

Another tidbit interesting to peruse is the MMM (Modularity Maturity Model) as a general guideline on the stages of modularity. http://www.infoq.com/news/2011/09/mmm-osgi

My work with TyphonRT is very modular and I have a loading mechanism that doesn’t depend on OSGi presently. At some point I’ll be looking into combining the two, but mostly to achieve hot swapping of modules which isn’t a pressing concern for me at the moment.

Hah, be warned though you are entering “architecture astronaut” territory as far as what others on JGO think about these topics… ::slight_smile: One can spend a good deal of time on this subject and not create a game, etc.

So the idea is a core application which remains under your control and cannot be modded, plus an API to allow Java to be written and loaded at run time?

May be dodging the question but is this design really appropriate? Expecting modders to write Java raises the bar significantly in terms of expertise, plus it may be fiddly to write and debug mods even if the API is very clean and simple. Hard to say without knowing more about what you’re really trying to do, but IMO the simplest way to cover off any customisability requirement is just to make the whole source code public :smiley:

why not use LuaJ and have complete control of what can be modded and what can’t. Plus, Lua is a common modding language

I’d rather just get the loading of it finished first and I’d rather not use an already built library for it but if I have to I will. I would rather start the loading first because the main part of my game ( Levels, Textures, Abilities ) would be put into a mod itself and can be easily replaced. Since I want the whole game itself to basically be in a mod this would allow me to figure out what I would need in order to make modding a bit more descriptive and easy.

I ended up supporting modding in my game due to user request - that is, people started modding the game even with no formal system in place.

So the laziest way you can support mods is to add an external mods directory to your classpath. This way, modders can drop in modified versions of your code and mod the game like that. That’s basically the Minecraft approach. But it comes with severe limitations: you have to let people fiddle around with the code of your game, the mods will break whenever you bring out a new version, and the learning curve is really steep.

To support modding you need to make sure you do the following:

  • leverage interfaces ! have a good component design and assume that your implementations may be extended or even replaced

  • make your loading dynamic on startup. If you community is going to change your program make it easy to do.

\

Lots of frameworks can be leveraged to do this: spring, osgi… heck you can even make your own using reflection if your so inclined.
(spring is the simplest … osgi is an very well established plugin framework but has a larger learning curve)

j.