Interface AttachmentRegistry.Builder<A>
- Type Parameters:
A- the type of the attached data
- Enclosing class:
AttachmentRegistry
@NonExtendable
public static interface AttachmentRegistry.Builder<A>
A builder for creating
AttachmentTypes with finer control over their properties.-
Method Summary
Modifier and TypeMethodDescriptionBuilds and registers theAttachmentType.Declares that when a player dies and respawns, the attachments of this type should remain.initializer(Supplier<A> initializer) Sets the default initializer for this attachment type.persistent(com.mojang.serialization.Codec<A> codec) Declares that attachments should persist between server restarts, using the providedCodecfor (de)serialization.syncWith(PacketCodec<? super RegistryByteBuf, A> packetCodec, AttachmentSyncPredicate syncPredicate) Declares that this attachment type may be automatically synchronized with some clients, as determined bysyncPredicate.
-
Method Details
-
persistent
Declares that attachments should persist between server restarts, using the providedCodecfor (de)serialization.- Parameters:
codec- the codec used for (de)serialization- Returns:
- the builder
-
copyOnDeath
AttachmentRegistry.Builder<A> copyOnDeath()Declares that when a player dies and respawns, the attachments of this type should remain.- Returns:
- the builder
-
initializer
Sets the default initializer for this attachment type. The initializer will be called byAttachmentTarget.getAttachedOrCreate(AttachmentType)to automatically initialize attachments that don't yet exist. It must not returnnull.It is encouraged for
AttachmentRegistry.Builderto be an immutable data type, such as a primitive type or an immutable record.Otherwise, it is important to ensure that attachments do not share any mutable state. As an example, for a (mutable) list/array attachment type, the initializer should create a new independent instance each time it is called.
- Parameters:
initializer- the initializer- Returns:
- the builder
-
syncWith
AttachmentRegistry.Builder<A> syncWith(PacketCodec<? super RegistryByteBuf, A> packetCodec, AttachmentSyncPredicate syncPredicate) Declares that this attachment type may be automatically synchronized with some clients, as determined bysyncPredicate.- Parameters:
packetCodec- the codec used to serialize the attachment data over the networksyncPredicate- anAttachmentSyncPredicatedetermining with which clients to synchronize data- Returns:
- the builder
-
buildAndRegister
Builds and registers theAttachmentType.- Parameters:
id- the attachment's identifier- Returns:
- the built and registered
AttachmentType
-