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
| Action | Input |
|---|---|
| LEFT_CLICK | Main-hand left click, not sneaking |
| RIGHT_CLICK | Main-hand right click, not sneaking |
| SHIFT_LEFT_CLICK | Main-hand left click while sneaking |
| SHIFT_RIGHT_CLICK | Main-hand right click while sneaking |
| OFFHAND_LEFT_CLICK | Offhand left click, not sneaking |
| OFFHAND_RIGHT_CLICK | Offhand right click, not sneaking |
| OFFHAND_SHIFT_LEFT_CLICK | Offhand left click while sneaking |
| OFFHAND_SHIFT_RIGHT_CLICK | Offhand 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)