Skip to content

Creating a Bauble

Tom Tanticle edited this page Jun 22, 2024 · 2 revisions

Choosing An Implementation

Baubles 2 provides two ways of giving items specific behaviour of how they interact with the mod. Those being:

  • A simple IBauble interface that can be implemented into the item class itself. This is recommended if your mod has a hard dependency on Baubles 2, and it will never be missing.
  • The baubles:bauble ItemCapability, which implements the IBauble interface. An item needs to provide this capability when queried, and is the recommended option when Baubles 2 is optional, as it can simply be ommited if the mod is not found.

Regardless of which option is choosen, the implementation remains the same.

Defining Behaviour

A bauble implementation is composed out of only 5 methods. These methods can be implemented however a developer wishes, with all of them being defauled to "no behaviour" if not implement. All of them provide the same 3 arguments:

  • The BaubleType, an enum which defines the slot this method is currently evaluated on. This may be interesting to you if your bauble can be put into multiple slots.
  • The ItemStack, the bauble ItemStack currently being evaluated.
  • The Player, the current holder of the BaubleType and ItemStack, interacting with both.
Method Name Purpose
onWornTick Called every tick when the bauble stack is present within a bauble slot.
onEquipped Called when the bauble stack is put into a bauble slot.
onUnequipped Called when the bauble stack is removed from a bauble slot.
canEquip Determines whether the bauble stack can be put into a bauble slot.
canUnequip Determines whether the bauble stack can be removed from a bauble slot.

Note: With the exception of canEquip and canUnequip, which are only executed on the server, all methods are fired on both the client and the server.

Determining Slots

Finally, a bauble that cannot be put into a bauble slot is somewhat worthless. As such, the valid bauble slots for this specific bauble need to be specified. This is done via tags in a simple datapack. For more information on that, see Datapack Configuration.

Tip: For data generation, the BaublesData#Tags inner class contains all TagKeys for easy usage.

Clone this wiki locally