Skip to content

Java API

Traverse-Joe edited this page Dec 3, 2026 · 1 revision

Everything lives in com.traverse.orbischarms.api. Call registration methods from your plugin's setup(). See Getting started for the dependency setup.

Checking whether a charm is equipped

boolean wearing = OrbisCharms.isEquipped(store, playerRef, "MyMod_Ruby_Ring");

Or work with the player's charm inventory directly:

CharmInventory charms = OrbisCharms.getInventory(store, playerRef);

charms.isEquipped("MyMod_Ruby_Ring");
charms.isEquipped("MyMod_Ruby_Ring", "Ring");
short slot = charms.findEquipped("MyMod_Ruby_Ring");
List<ItemStack> rings = charms.getEquipped("Ring");
List<ItemStack> everything = charms.getAllEquipped();
  • findEquipped returns -1 when the charm isn't worn.
  • Broken charms don't count as equipped.

Item checks that don't need a player:

OrbisCharms.isCharm(itemStack);
OrbisCharms.fitsSlot(itemStack, "Necklace");
OrbisCharms.fitsAnySlot(itemStack);
OrbisCharms.isUnique("MyMod_Ruby_Ring");
OrbisCharms.getCharmAsset("MyMod_Ruby_Ring");

Running code while a charm is worn

A tick handler runs every game tick for each player wearing the charm:

OrbisCharms.registerTickHandler("MyMod_Swift_Ring", context -> {
    if (context.every(1.0f)) {
        EffectControllerComponent effects = context.getStore()
                .getComponent(context.getRef(), EffectControllerComponent.getComponentType());
        effects.addEffect(context.getRef(), swiftness, 1.5f, OverlapBehavior.OVERWRITE,
                context.getCommandBuffer());
    }
});

CharmContext gives you:

Method Returns
getRef(), getStore(), getCommandBuffer() the player and this tick's ECS access
getInventory() the player's CharmInventory
getSlot(), getSlotType() which slot the charm is in
getItemStack() the charm itself
getDeltaTime() seconds since the last tick
getEquippedTime() seconds the charm has been worn
every(seconds) true once per interval, for timed effects
damage(amount) wears the charm down, see Durability
isBroken() whether the charm is at 0 durability
  • Handlers run on the world thread.
  • An exception in one handler is logged and doesn't stop the others.
  • Broken charms don't tick.

For simple "while worn" effects, prefer Effects in the charm definition; it needs no code.

Durability

Durability is opt-in: the item needs a MaxDurability in its JSON. Wear it down yourself:

context.damage(1);
charms.damage(slot, 1);
  • damage does nothing for items without durability and returns false.
  • At 0 the charm is broken. It stays in its slot, but stops ticking, gives no bonuses or effects, and doesn't count as equipped until repaired.
  • Every durability change fires CharmsChangedEvent, so damage on an interval with every(...), not every tick.

Reacting to charm changes

CharmsChangedEvent fires on a player whenever their charm slots change, and once when they join. Changes in the same tick are batched into one event, so recompute from the inventory rather than tracking individual changes:

public class RubyRingSystem extends EntityEventSystem<EntityStore, CharmsChangedEvent> {

    public RubyRingSystem() {
        super(CharmsChangedEvent.class);
    }

    @Override
    public Query<EntityStore> getQuery() {
        return Player.getComponentType();
    }

    @Override
    public void handle(int index, ArchetypeChunk<EntityStore> chunk, Store<EntityStore> store,
                       CommandBuffer<EntityStore> commandBuffer, CharmsChangedEvent event) {
        boolean wearing = event.getInventory().isEquipped("MyMod_Ruby_Ring");
    }
}
getEntityStoreRegistry().registerSystem(new RubyRingSystem());

The event runs on the world thread, so you can change components directly.

Stat bonuses, resistances and damage bonuses from charm definitions are already applied for you. Use this event for behaviour JSON can't express.

Rendering

Register a render to show a charm on the player. It replaces any Render block in that charm's definition:

OrbisCharms.registerRender("MyMod_Wolf_Ring", CharmRender.builder()
        .item("MyMod_Wolf_Ears")
        .effect("MyMod_Wolf_Form")
        .attachment("Items/MyMod/Collar.blockymodel", "Items/MyMod/Collar.png")
        .build());
Builder method What it does
item(itemId) Draws that armor item on the player like worn armor, over their skin and clothes. The item needs an Armor block. Hidden while the player is transformed.
effect(effectId) Applies an entity effect while worn: glow, particles, tint, or a model change.
attachment(model, texture) Attaches a model to the player's model. Only shows while transformed into a non-player model.
attachment(CharmAttachment) The same, with a gradient set and ID for tinted textures.

OrbisCharms.getRender(itemId) returns the active render, whether it came from Java or JSON.

Slot types

OrbisCharms.enableSlotType("Ring", 2);
OrbisCharms.registerSlotType("Pocket", 1, "MyMod/Slots/Pocket.png", true);
List<CharmSlotType> types = OrbisCharms.getSlotTypes();
CharmSlotType ring = OrbisCharms.getSlotType("Ring");

See Charm slots for details.

Saved data

Each player's charms are saved with the player as the OrbisCharms_Inventory component (OrbisCharms.getComponentType()). Use OrbisCharms.getInventory rather than reading the component yourself.

Clone this wiki locally