Moddable game

Does jme3 in any way stop you from creating moddable game?

I want to let users replace models, though jme3 converts all of them to *.j3o and then all of them are hidden inside of *.jar.

Is it possibile to load assets directly from folders and prevent java/jme3 from putting them inside of *.jar?

Not really, at worst, the user can simply replace the assetpack from any game.

At best you add modding support to your game and let the user replace explicitly replace some models…

What about adding new models? Normally I’d scan through the folder and load everything that can be found, but here I’m clueless how to approach it.

It really depends on your game.

What should your game do with the new models? What features have the new models? There is usually more to mod, than adding a model.

As minimum i would add something like:
[java]
HashMap<String ModelId,String ModelPath> availableModels;

[/java]

somewhere in your application. A modder then addes a jar containing the models, as well as some kind of configuration file (I use reflections to get all classes implementing a specified interface) which modified the above set. When the game starts, the ModelPaths are loaded.

Similar stuff is possible with game modes and nearly all kind of things. But all in all, it’s not jme or any other engine limiting you. It comes down how modular you make your game, and how easy it is to add all kind of features without having the full source code

1 Like

In my case for example a possible modder just have to add this class:

[java]
public class AirplaneControl implements GameModule {
@Inject
EntityData entityData;

EntitySet airplanesToMove;

@Override
public void onLoad() {
    airplanesToMove = entityData.getEntities(Airplane.class, Position.class, ActiveFlag.class, SteerData.class);
}

@Override
public void onUpdate(float tpf) {
    airplanesToMove.applyChanges();
    for (Entity entity : airplanesToMove) {
        Position position = entity.get(Position.class);
        SteerData steerData = entity.get(SteerData.class);
        Quaternion newRotation = position.getRotation().clone();
        Vector3f newPosition = position.getPosition().clone();

        float currentSpeed = 100;
        float yawFactor = 0.1f;
        float rollFactor = 2;
        float pitchFactor = 1;
        newRotation.multLocal(new Quaternion().fromAngleAxis(pitchFactor * steerData.getPitch() * tpf, Vector3f.UNIT_X));
        newRotation.multLocal(new Quaternion().fromAngleAxis(yawFactor * steerData.getJaw() * tpf, Vector3f.UNIT_Y));
        newRotation.multLocal(new Quaternion().fromAngleAxis(rollFactor * steerData.getRoll() * tpf, Vector3f.UNIT_Z));

        Vector3f newDirection = newRotation.mult(new Vector3f(0, 0, 1));
        newPosition.addLocal(newDirection.mult(currentSpeed * tpf));

        entity.set(new Position(newPosition, newRotation, newDirection));
    }
}

}

[/java]

to the classpath, the class gets loaded and executed automatically. If the modder also finds a way to add the Airplane flag to a car he would be able to fly as it was a airplane

1 Like