Skip to content

Applicables

Applicables are the types of items to which the enchantment can be applied.

Creating an applicable

To start, create a class that implements the interface RegistrableApplicable.

class MyApplicable : RegistrableApplicable {
  override val aliases = listOf<String>()

  override fun canBeAppliedTo(type: Material) = false
}

Fill the aliases list with however you want to identify your applicable.

override val aliases = listOf("myapplicable", "coolapplicable")

Adding allowed items

The applicable checks whether an item can be legally enchanted by calling canBeAppliedTo on its type. The implementation can be as simple as verifying the type against a list of allowed types:

override fun canBeAppliedTo(type: Material) = type in allowedMaterials

Or, if necessary, you can do something more complicated/interesting, such as:

override fun canBeAppliedTo(type: Material) = type.name.startsWith("A")

Example applicable

Built-in BowsApplicable
class BowsApplicable : RegistrableApplicable {
  override val aliases = listOf("bow", "bows", "crossbow", "crossbows", "range", "ranged")

  override fun canBeAppliedTo(type: Material): Boolean = type in Constants.RANGED_WEAPONS
}