Download

Home Guides Baubles Mod API for Developers

Baubles Mod API for Developers

Learn how the Baubles API works on 1.12.2, from slot types and item hooks to safe checks and testing.

Updated October 26, 20265 min readBy the Baubles Mod team
Baubles Mod API for Developers

The Baubles Mod is, at heart, a small API for Forge mod makers. Azanor built it so other mods could add worn items without each one making its own slot screen. This guide walks through the 1.12.2 code, line by line in plain words. All names come from the baubles.api package in the last original release, 1.5.2.

Why a shared slot API helps

Picture ten mods that each add rings. If every mod built its own ring slots, players would juggle ten screens. Saves would grow messy, and items would clash. A shared API fixes that. Every mod puts its gear in the same seven slots, and players learn one screen.

It also saves you work. The Baubles Mod already runs the slot screen and saves the slots. It drops worn items on death and syncs them to each client. You just write the item. Your code stays short, and you spend your time on the fun part.

Players gain too. They press one key, B by default, and see all their worn gear in one place. Rings from your mod sit next to amulets from a second one.

The Baubles Mod slot model

Slots are set by the BaubleType enum. Each type maps to one or more slot numbers. Here is the full layout on 1.12.2:

TypeSlot numbers
AMULET0
RING1 and 2
BELT3
HEAD4
BODY5
CHARM6
TRINKET0 to 6

Two helper methods sit on the enum. getValidSlots() returns the slot numbers as an array. hasSlot(int) tells you if a type may use a given slot. Use these rather than writing your own number checks.

To turn an item into a bauble, add the IBauble type to it. Only one method is required: getBaubleType(ItemStack). Since it takes the stack, one item can return a new type per damage value or per tag.

From 1.5.1, IBauble is also a capability. Does your item class use the interface? Then the Baubles Mod adds the capability for you. If you would rather not touch the item class, attach it yourself. The ready-made BaubleItem class is a tiny IBauble that just stores a type, which you pass to its constructor.

Equipped item checks

Most mods built on the Baubles Mod need to ask, "Is the player wearing my item?" The simple way is BaublesApi.isBaubleEquipped(player, item). It came in with 1.5.2. It hands back the first slot number that holds the item, or -1 if none does.

For more control, get the handler. BaublesApi.getBaublesHandler(player) returns an IBaublesItemHandler. It builds on Forge's IItemHandlerModifiable, so you can loop with getSlots() and read each slot with getStackInSlot(int).

Always loop to getSlots(). Do not hard-code seven. The old 1.7.10 Baubles had only four slots. Baubles Expanded, a fork for 1.7.10, can reach twenty. A fixed count is the first thing to break when code moves between them.

You may still see BaublesApi.getBaubles(player) in old code. It wraps the handler as an IInventory and is marked as deprecated. New code should use the handler.

Events and integration

The Baubles Mod does not post its own events. You hook in through the default methods on IBauble. Each one does nothing or returns a safe value. So you only write the ones you need.

  • onWornTick runs once per tick while the item is worn. It fires on both the client and the server side.
  • onEquipped and onUnequipped run when the item goes in or out of a slot.
  • canEquip and canUnequip return true by default. Return false to lock a slot, such as a cursed ring.
  • willAutoSync returns false by default. Set it to true if the stack's tag or damage changes while worn.

Auto sync is not instant. Baubles checks every 10 ticks, which is half a second. It also syncs a player's slots when they join and when another player comes into range.

A few rules in the Baubles Mod itself are worth knowing. Worn items drop on death unless the keepInventory rule is on. Slot items also carry over when the game clones the player, as on a trip to a new dimension.

Keeping Baubles Mod dependencies clear

The mod ID is baubles. If your mod cannot run without it, say so in your @Mod line, for example with required-after:baubles. Forge will then warn players at launch instead of crashing later.

If Baubles is optional, keep all Baubles calls in their own class. Only touch that class after you confirm the mod is loaded. That way your mod still starts when Baubles is missing.

Build against the API, but do not pack Baubles classes in your jar. Players should get the real mod. The API is tagged with version 1.4.0.2 and provides Baubles|API. Baubles 1.5.2 itself asks for Forge 14.21.0.2348 or newer. List that in your notes so players know the floor.

Testing compatibility

Start with a clean profile. Add Forge for 1.12.2, the Baubles Mod 1.5.2 jar and your mod. Add nothing else. Once that works, add other mods one at a time.

  1. Point at your item. The gold tooltip line should name the right slot type.
  2. Equip it and watch for your onEquipped effect. Take it off and confirm the effect ends.
  3. As an operator, run /baubles view <player> to see what the server thinks is worn.
  4. Use /baubles clear <player> <slot> to reset a slot between tests.
  5. Die with the item on, once with keepInventory on and once with it off.
  6. Join a test server with a second account. Check that the other player sees your changes.

If your item changes its tag while worn and the other player sees old data, check willAutoSync first.

Showing your bauble on the player model

To draw your item on the player, add IRenderBauble to the item. It has one method, onPlayerBaubleRender. It is called with a render type of BODY or HEAD. Check that type and draw only once, or your model shows up twice.

The nested Helper class saves you math. translateToHeadLevel and translateToFace place a model on the head. translateToChest places it on the chest. rotateIfSneaking fixes the angle when the player sneaks, and defaultTransforms scales the model down.

The item must still implement IBauble, since the render hook does not cover that. Last, players can switch off all bauble art with baubleRender.enabled in the client config. Never tie game logic to the render call.

Quick Answers

Do I have to ship the Baubles API inside my mod jar?

No. Build against the API, then let players install Baubles itself. Two copies of the same classes in one pack can clash and are hard to track down.

Can an item go in more than one Baubles slot?

Yes. Return TRINKET from getBaubleType and the item can sit in any of the seven slots. Ring items can also use either of the two ring slots.

Is this API the same as Curios or Trinkets?

No. Those are separate slot systems for newer Minecraft versions. Code written for Baubles on 1.12.2 needs real changes before it can work with them.