Class AttachmentEvents
java.lang.Object
net.ixdarklord.coolcatcore.api.event.v2.common.AttachmentEvents
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA value was stored where there was none.static interfacestatic interfaceA value is about to be added, changed or removed by code on this side (not by a sync from the server).static interfaceSynced values from the server were applied on this client (after their add, change and remove events).static interfaceA value was removed (reset); the holder reads the default again.static interfaceA player starts receiving a holder's synced data (server side): they started seeing the entity or received the block entity's chunk (for holders carrying attachments at that moment), or, for their own attachments, joined, respawned or changed dimension (always).static interfaceA player stops receiving a holder's data (server side): they stopped seeing the entity, the block entity's chunk was dropped for them, or, for their own data, they left.static interfacestatic interfacestatic interfacestatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final EventInvoker<AttachmentEvents.Added> static final EventInvoker<AttachmentEvents.Changed> static final EventInvoker<AttachmentEvents.Changing> static final EventInvoker<AttachmentEvents.Received> static final EventInvoker<AttachmentEvents.Removed> static final EventInvoker<AttachmentEvents.StartTracking> static final EventInvoker<AttachmentEvents.StopTracking> -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> AttachmentEvents.AddedonAdded(Attachment<T> attachment, AttachmentEvents.TypedAdded<T> listener) static <T> voidonAnyChange(Attachment<T> attachment, Attachment.Listener<T> listener) Listens to every change of one attachment (added, changed or removed) with the values holders read before and after, defaults standing in for missing values.static <T> AttachmentEvents.ChangedonChanged(Attachment<T> attachment, AttachmentEvents.TypedChanged<T> listener) static <T> AttachmentEvents.ChangingonChanging(Attachment<T> attachment, AttachmentEvents.TypedChanging<T> listener) Listens to one attachment's pending changes; seeAttachmentEvents.Changing.static <T> AttachmentEvents.RemovedonRemoved(Attachment<T> attachment, AttachmentEvents.TypedRemoved<T> listener)
-
Field Details
-
CHANGING
-
ADDED
-
CHANGED
-
REMOVED
-
START_TRACKING
-
STOP_TRACKING
-
RECEIVED
-
-
Method Details
-
onChanging
public static <T> AttachmentEvents.Changing onChanging(Attachment<T> attachment, AttachmentEvents.TypedChanging<T> listener) Listens to one attachment's pending changes; seeAttachmentEvents.Changing. -
onAdded
public static <T> AttachmentEvents.Added onAdded(Attachment<T> attachment, AttachmentEvents.TypedAdded<T> listener) -
onChanged
public static <T> AttachmentEvents.Changed onChanged(Attachment<T> attachment, AttachmentEvents.TypedChanged<T> listener) -
onRemoved
public static <T> AttachmentEvents.Removed onRemoved(Attachment<T> attachment, AttachmentEvents.TypedRemoved<T> listener) -
onAnyChange
Listens to every change of one attachment (added, changed or removed) with the values holders read before and after, defaults standing in for missing values. Same asAttachment.onChange(net.ixdarklord.coolcatcore.api.attachment.Attachment.Listener<T>).
-