Class AttachmentType<T>
IAttachmentHolder.
Data attachment types must be registered to the registry.
BlockEntity-exclusive behavior:
- Modifications to attachments should be followed by a call to
BlockEntity.setChanged().
Entity-exclusive behavior:
- Serializable entity attachments are not copied on death by default (but they are copied when returning from the end).
- Serializable entity attachments can opt into copying on death via
AttachmentType.Builder.copyOnDeath().
ItemStack-exclusive behavior:
- Serializable item stack attachments are synced between the server and the client.
- Serializable item stack attachments are copied when an item stack is copied.
- Serializable item stack attachments must match for item stack comparison to succeed.
Level-exclusive behavior:
- (nothing)
ChunkAccess-exclusive behavior:
- Modifications to attachments should be followed by a call to
ChunkAccess.setUnsaved(boolean). - Serializable attachments are copied from a
ProtoChunkto aLevelChunkon promotion.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final IAttachmentCopyHandler<T> (package private) final boolean(package private) final Function<IAttachmentHolder, T> (package private) final @Nullable IAttachmentSerializer<?, T> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> AttachmentType.Builder<T> builder(Function<IAttachmentHolder, T> defaultValueConstructor) Creates a builder for an attachment type.static <T> AttachmentType.Builder<T> Creates a builder for an attachment type.private static <T,H extends Tag>
IAttachmentCopyHandler<T> defaultCopyHandler(@Nullable IAttachmentSerializer<H, T> serializer) static <S extends Tag,T extends INBTSerializable<S>>
AttachmentType.Builder<T> serializable(Function<IAttachmentHolder, T> defaultValueConstructor) Create a builder for an attachment type that usesINBTSerializablefor serialization.static <S extends Tag,T extends INBTSerializable<S>>
AttachmentType.Builder<T> serializable(Supplier<T> defaultValueSupplier) Create a builder for an attachment type that usesINBTSerializablefor serialization.
-
Field Details
-
defaultValueSupplier
-
serializer
-
copyOnDeath
final boolean copyOnDeath -
copyHandler
-
-
Constructor Details
-
AttachmentType
-
-
Method Details
-
defaultCopyHandler
private static <T,H extends Tag> IAttachmentCopyHandler<T> defaultCopyHandler(@Nullable @Nullable IAttachmentSerializer<H, T> serializer) -
builder
Creates a builder for an attachment type.See
builder(Function)for attachments that want to capture a reference to their holder.- Parameters:
defaultValueSupplier- A supplier for a new default value of this attachment type.
-
builder
public static <T> AttachmentType.Builder<T> builder(Function<IAttachmentHolder, T> defaultValueConstructor) Creates a builder for an attachment type.This overload allows capturing a reference to the
IAttachmentHolderfor the attachment. To obtain a specific subtype, the holder can be cast. If the holder is of the wrong type, the constructor should throw an exception. Seebuilder(Supplier)for an overload that does not capture the holder.- Parameters:
defaultValueConstructor- A constructor for a new default value of this attachment type.
-
serializable
public static <S extends Tag,T extends INBTSerializable<S>> AttachmentType.Builder<T> serializable(Supplier<T> defaultValueSupplier) Create a builder for an attachment type that usesINBTSerializablefor serialization. Other kinds of serialization can be implemented usingbuilder(Supplier)andAttachmentType.Builder.serialize(IAttachmentSerializer).See
serializable(Function)for attachments that want to capture a reference to their holder. -
serializable
public static <S extends Tag,T extends INBTSerializable<S>> AttachmentType.Builder<T> serializable(Function<IAttachmentHolder, T> defaultValueConstructor) Create a builder for an attachment type that usesINBTSerializablefor serialization. Other kinds of serialization can be implemented usingbuilder(Supplier)andAttachmentType.Builder.serialize(IAttachmentSerializer).This overload allows capturing a reference to the
IAttachmentHolderfor the attachment. To obtain a specific subtype, the holder can be cast. If the holder is of the wrong type, the constructor should throw an exception. Seeserializable(Supplier)for an overload that does not capture the holder.
-