Class AttachmentRegistry
java.lang.Object
net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry
Class used to create and register
AttachmentTypes. To quickly create AttachmentTypes, use one of the various
createXXX methods:
create(Identifier, Consumer): attachments can be further configured by the supplied consumer.create(Identifier): attachments will be neither persistent nor auto-initialized.createDefaulted(Identifier, Supplier): attachments will be auto-initialized, but not persistent.createPersistent(Identifier, Codec): attachments will be persistent, but not auto-initialized.
For finer control over the attachment type and its properties, use create(Identifier, Consumer) to
get and configure a AttachmentRegistry.Builder instance.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA builder for creatingAttachmentTypes with finer control over their properties. -
Method Summary
Modifier and TypeMethodDescriptionstatic <A> AttachmentRegistry.Builder<A> builder()Deprecated.static <A> AttachmentType<A> create(Identifier id) Creates and registers an attachment.static <A> AttachmentType<A> create(Identifier id, Consumer<AttachmentRegistry.Builder<A>> consumer) Creates and registers an attachment using a builder.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, usingAttachmentTarget.getAttachedOrCreate(AttachmentType).static <A> AttachmentType<A> createPersistent(Identifier id, com.mojang.serialization.Codec<A> codec) Creates and registers an attachment, that will persist across server restarts.
-
Method Details
-
create
public static <A> AttachmentType<A> create(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 attachmentconsumer- a lambda that configures aAttachmentRegistry.Builderfor this attachment type- Returns:
- the registered
AttachmentTypeinstance
-
create
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
AttachmentTypeinstance
-
createDefaulted
Creates and registers an attachment, that will be automatically initialized with a default value when an attachment does not exist on a given target, usingAttachmentTarget.getAttachedOrCreate(AttachmentType).- Type Parameters:
A- the type of attached data- Parameters:
id- the identifier of this attachmentinitializer- the initializer used to provide a default value- Returns:
- the registered
AttachmentTypeinstance
-
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 attachmentcodec- the codec used for (de)serialization- Returns:
- the registered
AttachmentTypeinstance
-
builder
Deprecated.Creates aAttachmentRegistry.Builder, that gives finer control over the attachment's properties. Calling this method directly is not recommended, as it requires explicit type parameters.create(net.minecraft.util.Identifier, java.util.function.Consumer<net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry.Builder<A>>)should be used instead.- Type Parameters:
A- the type of the attached data- Returns:
- a
AttachmentRegistry.Builderinstance
-