Class AttachmentRegistry

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

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 create(Identifier, Consumer) to get and configure a AttachmentRegistry.Builder instance.

  • Method Details

    • create

      public static <A> AttachmentType<A> create(net.minecraft.resources.Identifier id, Consumer<AttachmentRegistry.Builder<A>> consumer)
      Creates and registers an attachment using a builder.
      Type Parameters:
      A - the type of attached data
      Parameters:
      id - the identifier of this attachment
      consumer - a lambda that configures a AttachmentRegistry.Builder for this attachment type
      Returns:
      the registered AttachmentType instance
    • create

      public static <A> AttachmentType<A> create(net.minecraft.resources.Identifier id)
      Creates and registers an attachment. The data will not be persisted or synchronized.
      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(net.minecraft.resources.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(net.minecraft.resources.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

      @Deprecated public static <A> AttachmentRegistry.Builder<A> builder()
      Deprecated.
      Creates a AttachmentRegistry.Builder, that gives finer control over the attachment's properties. Calling this method directly is not recommended, as it requires explicit type parameters. create(Identifier, Consumer) should be used instead.
      Type Parameters:
      A - the type of the attached data
      Returns:
      a AttachmentRegistry.Builder instance