Skip to content

Creating an extension

Qboi edited this page May 23, 2023 · 10 revisions

On this page you can learn how to make an extension.

Add dependency

Note: you need to add the Architectury API to the dependencies too.

In your build.gradle add the following code in the dependencies {...} section:

  • Forge
    implementation fg.deobf("com.github.Ultreon.advanced-debug:advanced-debug-forge:2.1.1")
  • Fabric
    modImplementation "com.github.Ultreon.advanced-debug:advanced-debug-fabric:2.1.1"
  • Architectury
    // Forge
    modImplementation "com.github.Ultreon.advanced-debug:advanced-debug-forge:2.1.1")
    
    // Fabric
    modImplementation "com.github.Ultreon.advanced-debug:advanced-debug-fabric:2.1.1")
    
    // Common
    modImplementation "com.github.Ultreon.advanced-debug:advanced-debug:2.1.1")

It also needs a repository, so add the following code in the repositories {...} section:

  • Groovy DSL
    maven {
        name "Jitpack"
        url "https://jitpack.io/"
    }

The line with the compileOnly part is for the API, so you don't have any other classes that isn't needed for the extension.
Then the line with the runtimeOnly part makes it so you can test your code from the runClient run config or launch.

Create the extension class.

We start with a simple class;

@ExtensionInfo(Main.MOD_ID) // We expect that 'Main.MOD_ID' refers to the id of the compatibilty mod.
public class AdvancedDebugExtension implements Extension {

}

Here you have the basic class. The part with @AdvDebugExt(...) is an annotation, and is used for the Advanced Debug mod to find out it's an extension class.
And it also implements IAdvDebugExt, this is for the methods it needs to have. These methods are initPages and initFormatters.
So now, we implement these methods:

@AdvDebugExt(modId = Main.MOD_ID) // We expect that 'Main.MOD_ID' refers to the id of the compatibilty mod.
public class AdvancedDebugExtension implements IAdvDebugExt {
    @Override
    public void initPages(IInitPagesEvent evt) {
        // Register pages here.
    }

    @Override
    public void initFormatters(IFormatterRegistry registry) {
        // Initialize a init class for the formatters.
    }
}

Registering the extension

Create a new file named com.ultreon.mods.advanceddebug.api.extension.Extension in resources/META-INF.
Put in there the class name reference to the extension class e.g.:

com.example.compat.advdbg.AdvancedDebugExtension

Further information

For creating a debug page click here.
For creating a formatter click here.

Download @ CurseForge and Modrinth.

Clone this wiki locally