Advanced

Modules

Learn how to initialize Balm with the alternative module method.

Balm offers an additional way of structuring your mod by implementing the BalmModule interface. This interface comes equipped with overridable methods for any of the registrars you may need. There is no functional difference to the standard way of initializing your mod, BalmModule is essentially just semantic sugar to bring more structure into the initialization process.

The BalmModule approach may be useful for small mods or for mods with distinct thematic areas where it would make sense to split things into multiple modules.

Defining a Module

Modules need to implement at least getId() so they can be identified and attributed to a specific mod. The path is up to you to use. All other methods are defaulted to be empty.

common/src/main/java/Waystones.java
public class Waystones implements BalmModule {
    public static final String MOD_ID = "waystones";

    public static DeferredBlock waystoneBlock;

    @Override
    public Identifier getId() {
        return Identifier.fromNamespaceAndPath(MOD_ID, "common");
    }

    @Override
    public void registerBlocks(BalmBlockRegistrar blocks) {
        waystoneBlock = blocks.register("waystone", WaystoneBlock::new, 
            it -> it.sound(SoundType.STONE)
                    .strength(5f, 2000f)
        ).withItem(WaystoneBlockItem::new).asDeferredBlock();
    }

    @Override
    public void registerConfig(BalmConfig config) {
        config.registerConfig(WaystonesConfig.class);
    }

    @Override
    public void initialize() {
        ServerPlayerCallback.Join.EVENT.register(player -> {
            System.out.println("Player " + player + " has just joined the game!");
        });
    }
}

Initializing your Mod

You can pass an instance of the BalmModule interface to the Balm.initializeMod() method of your loader entrypoint to initialize your mod with a module.

fabric/src/main/java/FabricWaystones.java
Balm.initializeMod(Waystones.MOD_ID, FabricLoadContext.INSTANCE, new Waystones());

Initializing your mod with multiple modules

You can also pass multiple modules to have them all registered. They will initialize in the order they were passed in.

fabric/src/main/java/FabricWaystones.java
Balm.initializeMod(Waystones.MOD_ID, FabricLoadContext.INSTANCE, new Waystones(), new Sharestones());

Registering a module manually

You can call BalmRegistrars.registerModule() to load an additional module.

common/src/main/java/Waystones.java
public static void initialize(BalmRegistrars registrars) {
    registrars.registerModule(new Sharestones());
}

Client Modules

Client modules behave exactly the same except they use the BalmClientModule interface and are registered through BalmClient.