Build addons

Abilities

Write an ability, register it, and assign it to a player action.

On this page

Write an ability

Create a class that implements Ability. Give it a non-empty ID and an activate(context) function. The default cooldown is 0 (no cooldown). A positive cooldown stops that player from using the ability again for that many seconds.

kotlin
class GreetingAbility : Ability {
    override val id = "example:hello"
    override val cooldownSeconds = 3L

    override fun activate(context: AbilityContext) {
        context.player.sendMessage("Hello from Foundry!")
    }
}

Register and assign it

Register the ability when the addon starts. Then assign its ID to a player and an Action, such as RIGHT_CLICK. Foundry saves these assignments with the player's data.

kotlin
api.abilities.register(GreetingAbility())
api.playerAbilities.assign(player, Action.RIGHT_CLICK, "example:hello")

Supported actions

ActionInput
LEFT_CLICKMain-hand left click, not sneaking
RIGHT_CLICKMain-hand right click, not sneaking
SHIFT_LEFT_CLICKMain-hand left click while sneaking
SHIFT_RIGHT_CLICKMain-hand right click while sneaking
OFFHAND_LEFT_CLICKOffhand left click, not sneaking
OFFHAND_RIGHT_CLICKOffhand right click, not sneaking
OFFHAND_SHIFT_LEFT_CLICKOffhand left click while sneaking
OFFHAND_SHIFT_RIGHT_CLICKOffhand right click while sneaking

Saving an ability ID on an item

ItemAbilityService can save, read, or remove an ability ID on an item. This does not make the item run the ability yet. Right now, Foundry only checks abilities assigned to player actions.

kotlin
api.itemAbilities.assign(item, "example:hello")
val abilityId: String? = api.itemAbilities.get(item)
api.itemAbilities.remove(item)