Getting Started

Reacting to Events

Learn how to react to events using Balm.

Balm makes a set of callbacks for common events available to your mod, allowing you to hook into things such as block interactions, input handling, rendering, etc.

Internally, these events map to existing mod loader events where possible, which means your mod will remain compatible with other mods the same way a mod-loader native mod would be.

To register an event listener, find the callback you need (e.g. on the Event Matrix) and call .register() on the event you'd like to listen to.

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

Some callbacks have return values — you can check the interface you're implementing to see what the return value means; the method names are generally descriptive.

LivingEntityCallback.Damage.Before.EVENT.register((entity, damageSource, damageAmount) -> {
    if (entity instanceof Wolf) {
        return 0f; // Wolves are invincible!  
    }
    return damageAmount;
});

Balm's goal is to provide a common callback for all events that are universally useful and supported by all the loaders. You can check the Event Matrix for the current status and how mod loader events map to Balm callbacks.