Class AttachmentRegistry
java.lang.Object
net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry
Class used to create and register
AttachmentType
s. To quickly create AttachmentType
s, use one of the various
createXXX
methods:
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 builder()
to
get a AttachmentRegistry.Builder
instance.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A builder for creatingAttachmentType
s with finer control over their properties. -
Method Summary
Modifier and TypeMethodDescriptionstatic <A> AttachmentRegistry.Builder
<A> builder()
Creates aAttachmentRegistry.Builder
, that gives finer control over the attachment's properties.static <A> AttachmentType
<A> create
(Identifier id) Creates and registers an attachment.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
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
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
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 attachmentcodec
- the codec used for (de)serialization- Returns:
- the registered
AttachmentType
instance
-
builder
Creates aAttachmentRegistry.Builder
, that gives finer control over the attachment's properties.- Type Parameters:
A
- the type of the attached data- Returns:
- a
AttachmentRegistry.Builder
instance
-