Skip to content

Using code in modules

Benjamin Amos edited this page Mar 6, 2022 · 2 revisions

Experimental


Code modules are relatively new and the API is still subject to change. Any details specified here may change at any time, so use this as a broad reference only.

Placeholder page to fill out now that https://github.com/MovingBlocks/DestinationSol/pull/381 has been merged! The PR itself is sufficiently well documented to point out a lot of the involved details, partly we need to take some of that and place it here :-)

See also https://github.com/DestinationSol/Warp as the first code-bearing DS module.

Sandboxing

Modules in Destination Sol are sandboxed. Their code is limited to using a small list of approved classes. Additional classes can be marked as accessible using the @API annotation. The full list used is here but essentially this means:

  • No network communication
  • No direct filesystem access
  • No object serialisation
  • Very limited reflection
  • No runtime class loading
  • No java.date classes

If a class you need is missing from the list, feel free to request its addition.

Update Systems

The main entry point to code modules right now is UpdateAwareSystem. Classes that implement UpdateAwareSystem and are annotated with @RegisterUpdateSystem will have their update(SolGame, float) method invoked once per game loop. The classes must have a parameterless constructor.

By using the SolGame object provided, you can access most of the functionality of the game.

Update System Example

package org.destinationsol.codeModuleTest;

import org.destinationsol.game.SolGame;
import org.destinationsol.game.UpdateAwareSystem;
import org.destinationsol.game.attributes.RegisterUpdateSystem;

@RegisterUpdateSystem
public class PlayTimeUpdateSystem implements UpdateAwareSystem {
    private float totalPlayTime;

    public PlayTimeUpdateSystem() {
    }

    @Override
    public void update(SolGame game, float timeStep) {
        // Implement game logic here...
        totalPlayTime += timeStep;
    }
}

Existing Code Modules

Console Commands

See Creating Commands for more information.

Abilities

See [Creating Abilities)(Creating-Abilities) for more information.

NUI

See Creating NUI Screens for more information.

ECS

See the following sections: