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.
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.
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!");
});
}
}
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.
Balm.initializeMod(Waystones.MOD_ID, FabricLoadContext.INSTANCE, new Waystones());
You can also pass multiple modules to have them all registered. They will initialize in the order they were passed in.
Balm.initializeMod(Waystones.MOD_ID, FabricLoadContext.INSTANCE, new Waystones(), new Sharestones());
You can call BalmRegistrars.registerModule() to load an additional module.
public static void initialize(BalmRegistrars registrars) {
registrars.registerModule(new Sharestones());
}
Client modules behave exactly the same except they use the BalmClientModule interface and are registered through BalmClient.