Class AttachmentRegistry

java.lang.Object
net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry

@Experimental public final class AttachmentRegistry extends Object
Class used to create and register AttachmentTypes. To quickly create AttachmentTypes, use one of the various createXXX methods:

For finer control over the attachment type and its properties, use builder() to get a AttachmentRegistry.Builder instance.

  • Method Details

    • create

      public static <A> AttachmentType<A> create(Identifier id)
      Creates and registers an attachment. The data will not be persisted.
      Type Parameters:
      A - the type of attached data
      Parameters:
      id - the identifier of this attachment
      Returns:
      the registered AttachmentType instance
    • createDefaulted

      public static <A> AttachmentType<A> createDefaulted(Identifier id, Supplier<A> initializer)
      Creates and registers an attachment, that will be automatically initialized with a default value when an attachment does not exist on a given target, using AttachmentTarget.getAttachedOrCreate(AttachmentType).
      Type Parameters:
      A - the type of attached data
      Parameters:
      id - the identifier of this attachment
      initializer - the initializer used to provide a default value
      Returns:
      the registered AttachmentType instance
    • createPersistent

      public static <A> AttachmentType<A> createPersistent(Identifier id, com.mojang.serialization.Codec<A> codec)
      Creates and registers an attachment, that will persist across server restarts.
      Type Parameters:
      A - the type of attached data
      Parameters:
      id - the identifier of this attachment
      codec - the codec used for (de)serialization
      Returns:
      the registered AttachmentType instance
    • builder

      public static <A> AttachmentRegistry.Builder<A> builder()
      Creates a AttachmentRegistry.Builder, that gives finer control over the attachment's properties.
      Type Parameters:
      A - the type of the attached data
      Returns:
      a AttachmentRegistry.Builder instance