Class AttachmentEvents

java.lang.Object
net.ixdarklord.coolcatcore.api.event.v2.common.AttachmentEvents

public final class AttachmentEvents extends Object
Attachment values being added, changed and removed on any holder (entity, block entity or item stack), and players starting and stopping to track a holder's data.

The events see every attachment; the on...(attachment, ...) helpers register a listener for one attachment, with typed values:


 AttachmentEvents.onChanged(MADNESS, (holder, oldValue, newValue) -> {
     if (newValue >= 100 && holder.owner() instanceof ServerPlayer player) player.kill(player.level());
 });
 AttachmentEvents.onChanging(MADNESS, (holder, oldValue, newValue) ->
         newValue != null && newValue > 100 ? EventResultHolder.allow(100) : EventResultHolder.pass());   // clamp
 AttachmentEvents.START_TRACKING.register((holder, player) -> ...);
 
Add, change and remove events run on the side the value changed on: where it was set, or on a client when a synced value arrives (check AttachmentHolder.isClientSide()). Values read from a save aren't changes, and fire nothing.