Skip to content
piitex edited this page Jan 29, 2025 · 6 revisions

Addons

Addons are used to add additional content without modifying the source release. They can be used to create DLC and tools. Below will explain how to create an addon and most of the API. Addons are located in the addons directory. basedir/addons

Creating an Addon

I'm going to assume you have some familiarity with Maven. You can always use your games project as an example.

First create an empty maven project. Ensure you have a 'src', and 'resources' folder. If a Main.class is provided you can delete it or rename it. Please create a main class and do not call it Main. For this example, I will call mine TestAddon.

public class TestAddon {
}

Now locate the pom.xml file. This step is a little tricky so pay close attention. You will need to add your games project as a dependency. This information is completely different from person to person. Open your project with an IDEA and copy the <groupID>, <artifactID>, <version> into your addons pom.xml. Below is a rough example, paste below the <properties> configuration.

    <!-- Instead of using the RenJava framework, you use your game instead. -->
    <dependencies>
        <dependency>
            <groupId>me.piitex.game</groupId>
            <artifactId>TestGame</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>

Reload your maven changes and ensure the dependency can be located. Next part is optional but it's very useful. You will not be able to access the RenJava JavaDoc without adding RenJava as a dependency. Before we can add it as a dependency you must exclude it from your game's dependency. The key part is the <exclusions> part.

    <!-- Instead of using the RenJava framework, you use your game instead. -->
    <dependencies>
        <dependency>
            <groupId>me.piitex.game</groupId>
            <artifactId>TestGame</artifactId>
            <version>1.0.0</version>
            <exclusions>
                <exclusion>
                    <groupId>me.piitex</groupId>
                    <artifactId>RenJava</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Now add RenJava as a dependency. Replace LATEST VERSION with the version your game is running.

    <dependencies>
        <dependency>
            <groupId>me.piitex.game</groupId>
            <artifactId>TestGame</artifactId>
            <version>1.0.0</version>
            <exclusions>
                <exclusion>
                    <groupId>me.piitex</groupId>
                    <artifactId>RenJava</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>me.piitex</groupId>
            <artifactId>RenJava</artifactId>
            <version>LATEST VERSION</version>
        </dependency>
    </dependencies>

Next part is not optional. We need to add the resources file to the compiler. Above <dependencies> and below <properties> add the following lines.

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

All done with pom.xml. Let's go back to your addon class. The class will have to extend Addon and implement the methods.

public class TestAddon extends Addon {
    public TestAddon(String name, String version) {
        super(name, version);
    }

    @Override
    public void onLoad() {

    }

    @Override
    public void onDisable() {

    }
}

The addon will produce an error if you do not set the addon name and version. Once set the addon is created. The next wiki sections explain what you can do with an addon and the API,

    public TestAddon() {
        super("Test Addon", "1.0.0");
    }

API

An Addon has access to the entire RenJava API. For example, you can create characters, stories, and events within the addon. You can even modify the base game and develop tools.

Addons are loaded after the game initialization face and before the GUI is handled. The onLoad function acts as the addons entry point. Every addon handles its own events, data, and logger. When register Events and PersistentData use the addons functions. MyAddon.instance.registerData(new AddonData);

Below is an overview of the Addon API.

    /**
     * This method is called when the addon is loaded.
     * Subclasses should implement this method to perform any necessary initialization.
     */
    public abstract void onLoad();

    /**
     * This method is called when the addon is disabled.
     * Subclasses should implement this method to clean up any resources or perform any necessary cleanup actions.
     */
    public abstract void onDisable();

    /**
     * Returns the name of the addon.
     *
     * @return The name of the addon.
     */
    public String getName() {
        return name;
    }

    /**
     * Returns the version of the addon.
     *
     * @return The version of the addon.
     */
    public String getVersion() {
        return version;
    }

    /**
     * Returns the logger associated with the addon.
     *
     * @return The logger associated with the addon.
     */
    public Logger getLogger() {
        return logger;
    }

    /**
     * Registers an event listener for the addon.
     *
     * @param listener The event listener to register.
     */
    public void registerListener(EventListener listener) {
        registeredListeners.add(listener);
    }

    /**
     * Returns the collection of registered event listeners for the addon.
     *
     * @return The collection of registered event listeners.
     */
    public Collection<EventListener> getRegisteredListeners() {
        return registeredListeners;
    }


    /**
     * Registers data to be saved to the save file.
     *
     * @param data The data class to register.
     */
    public void registerData(PersistentData data) {
        registeredData.add(data);
    }

    /**
     * @return The collection of registered data for this addon.
     */
    public Collection<PersistentData> getRegisteredData() {
        return registeredData;
    }

    /**
     * Returns the collection of dependencies for the addon.
     * Dependencies are other addons that this addon relies on.
     *
     * @return The collection of dependencies for the addon.
     */
    public Collection<Addon> getDependencies() {
        return dependencies;
    }
}

Build File

The build file is extremely important because addons cannot load without one. The build file must include the RenJava build version and all dependencies. Do not use the Renjava version below, use the one your game requires. The dependencies can be blank if you do not have any. dependencies=

ren.version=0.1.235-beta
dependencies=dependency1,dependency2

The build file must be located in the root of your resources directory. resources/build.info.

Managing Assets

There are multiple ways you can distribute assets with your addon. The first way is to distribute the addon in a zip file with the necessary assets packed into the correct folder. Below is an example of how the zip would work.

Addon.zip
    └addons
        └test-addon.jar
    └─game
        └─audio
            └─packed audio.mp3
        └─images
            └─ packed image.png
        └─media
            └─packed media.mp4

The user would then have to extract the zip contents to root directory of the game. The other way is to include the assets within the resources/game/. You must create the game subdirectory as RenJava will only detect files in this directory. Once the addon is loaded, the files are moved from class-path (jar file) into the game folder. This will replace files with the addon version if they're duplicates.

resources
    └─game
        └─audio
            └─ packed audio.mp3
        └─images
            └─ packed images.png
        └─media
            └─ packed media.mp4
    └─build.info

Contruction

The page has plans to be updated with newer and updated information. Come back at a later time!

Clone this wiki locally