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, the attachments corresponding 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 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

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