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 TypeMethodDescriptionbuildAndRegister(net.minecraft.resources.Identifier id) Builds and registers theAttachmentType.Declares that when a player dies and respawns or when a mob is converted (e.g.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(net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, A> streamCodec, AttachmentSyncPredicate syncPredicate) Declares that this attachment type may be automatically synchronized with some clients, as determined bysyncPredicate.syncWith(net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, A> streamCodec, AttachmentSyncPredicate syncPredicate, int maxSyncSize) 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 or when a mob is converted (e.g. zombie → drowned), 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
Ato 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(net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, A> streamCodec, AttachmentSyncPredicate syncPredicate) Declares that this attachment type may be automatically synchronized with some clients, as determined bysyncPredicate.- Parameters:
streamCodec- the codec used to serialize the attachment data over the networksyncPredicate- anAttachmentSyncPredicatedetermining with which clients to synchronize data- Returns:
- the builder
-
syncWith
AttachmentRegistry.Builder<A> syncWith(net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, A> streamCodec, AttachmentSyncPredicate syncPredicate, int maxSyncSize) Declares that this attachment type may be automatically synchronized with some clients, as determined bysyncPredicate.The max size limit should be increased with care, as syncing large amounts of data may result in network lag and excessive bandwidth usage.
- Parameters:
streamCodec- the codec used to serialize the attachment data over the networksyncPredicate- anAttachmentSyncPredicatedetermining with which clients to synchronize datamaxSyncSize- the max number of data bytes that can be synced, defaults to 1 MiB minus some small padding- Returns:
- the builder
-
buildAndRegister
Builds and registers theAttachmentType.- Parameters:
id- the attachment's identifier- Returns:
- the built and registered
AttachmentType
-