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, 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
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()
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.Builder
for this attachment type- Returns:
- the registered
AttachmentType
instance
-
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
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
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.Builder
instance
-