Basic Functionality - Swackyy/Ohmega GitHub Wiki

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
  • update(Player, ItemStack) never internally called, yet intended to be a universal way to "update" other accessories
  • 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

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.

One such example use of this class could be the simplification of the "right click to equip" functionality, similar to armour items in vanilla Minecraft:

(From the example Angel Ring accessory item (1.21 source))

// This is different to the method above (omitted), this is the vanilla method that causes the right-clicking behaviour
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand hand) {
    return AccessoryHelper.tryEquip(player, hand);

As shown, the utility class handles most of the work for you.

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

⚠️ ** Fallback** ⚠️