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 Details

    • persistent

      AttachmentRegistry.Builder<A> persistent(com.mojang.serialization.Codec<A> codec)
      Declares that attachments should persist between server restarts, using the provided Codec for (de)serialization.
      Parameters:
      codec - the codec used for (de)serialization
      Returns:
      the builder
    • 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

      AttachmentRegistry.Builder<A> initializer(Supplier<A> initializer)
      Sets the default initializer for this attachment type. The initializer will be called by AttachmentTarget.getAttachedOrCreate(AttachmentType) to automatically initialize attachments that don't yet exist. It must not return null.

      It is encouraged for A to 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 by syncPredicate.
      Parameters:
      streamCodec - the codec used to serialize the attachment data over the network
      syncPredicate - an AttachmentSyncPredicate determining 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 by syncPredicate.

      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 network
      syncPredicate - an AttachmentSyncPredicate determining with which clients to synchronize data
      maxSyncSize - the max number of data bytes that can be synced, defaults to 1 MiB minus some small padding
      Returns:
      the builder
    • buildAndRegister

      AttachmentType<A> buildAndRegister(net.minecraft.resources.Identifier id)
      Builds and registers the AttachmentType.
      Parameters:
      id - the attachment's identifier
      Returns:
      the built and registered AttachmentType