Basic Functionality - Swackyy/Ohmega GitHub Wiki

Using the API

Most of what you need can be achieved through the use of the api package in the mod, however you may need to access other directories at times.

Accessory Functionality

Simple, working accessories can be created through the use of overriding various methods from the IAccessory interface.

Here is a link to the 1.21 IAccessory interface source code, containing useful JavaDocs

Method List

Here are those methods, with descriptions:

  • tick(Player, ItemStack) -> Called every tick when the accessory is equipped
  • onEquip(Player, ItemStack) -> Called upon equipping the accessory
  • onUnequip(Player, ItemStack) -> Called upon unequipping the accessory
  • canEquip(Player, ItemStack) -> Called when equipping the accessory, if false, the accessory will not be equipped
  • canUnequip(Player, ItemStack) -> Called when unequipping the accessory, if false, the accessory will not be unequipped
  • checkCompatibility(IAccessory) -> denotes if an accessory (this) is compatible with another (parameter), if false, the accessory will not be equipped
  • onUse(Player, ItemStack) -> Called when a key-bind is pressed corresponding to the slot that the accessory is in, only works with Utility and Special type items
  • autoSync(Player) -> If true, the client will be synced with the server every tick
  • addDefaultAttributeModifiers(ModifierBuilder) -> More complicated, see this section for more information
  • getEquipSound() (1.19.4+) -> Serves as a replacement to the pre 1.19.3 vanilla getEquipSound(), plays a sound when equipped via right clicking it as a held item

Each of these can be overridden produce a variety of useful accessories

AccessoryHelper utility class

Here is a link to the 1.21 AccessoryHelper source code, containing useful JavaDocs

This utility class can be used to achieve more complicated functionality in an easy way.

Additional built-in functionality such as an "active state" can also be achieved using this, however it is instead covered here, as an advanced topic