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
AttachmentType
s with finer control over their properties.-
Method Summary
Modifier and TypeMethodDescriptionBuilds and registers theAttachmentType
.Declares that when a player dies and respawns, the attachments corresponding 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 providedCodec
for (de)serialization.
-
Method Details
-
persistent
Declares that attachments should persist between server restarts, using the providedCodec
for (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 corresponding 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.Builder
to be an immutable data type, such as a primitive type or an immutable record.Otherwise, one must be very careful, as attachments must 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
-
buildAndRegister
Builds and registers theAttachmentType
.- Parameters:
id
- the attachment's identifier- Returns:
- the built and registered
AttachmentType
-