Interface AttachmentTarget
AttachmentTypes.
 Fabric implements this on Entity, BlockEntity, ServerWorld and Chunk via mixin.
Note about BlockEntity and Chunk targets: these objects need to be notified of changes to their
 state (using BlockEntity.markDirty() and Chunk.markNeedsSaving() respectively), otherwise the modifications will not take effect properly.
 The setAttached(AttachmentType, Object) method handles this automatically, but this needs to be done manually
 when attached data is mutable, for example:
 
 AttachmentType<MutableType> MUTABLE_ATTACHMENT_TYPE = ...;
 BlockEntity be = ...;
 MutableType data = be.getAttachedOrCreate(MUTABLE_ATTACHMENT_TYPE);
 data.mutate();
 be.markDirty(); // Required because we are not using setAttached
 
 Note about BlockEntity targets: by default, many block entities use their NBT to synchronize with the client.
 That would mean persistent attachments are automatically synced with the client for those block entities. As this is
 undesirable behavior, the API completely removes attachments from the result of BlockEntity.toInitialChunkDataNbt(net.minecraft.registry.RegistryWrapper.WrapperLookup),
 which takes care of all vanilla types. However, modded block entities may be coded differently, so be wary of this
 when attaching data to modded block entities.
 
 Note about Chunk targets with ChunkStatus.EMPTY: These chunks are not saved unless the generation
 progresses to at least ChunkStatus.STRUCTURE_STARTS. Therefore, persistent attachments to those chunks may not
 be saved. The setAttached(AttachmentType, Object) method will log a warning when this is attempted.
 
- 
Field SummaryFields
- 
Method SummaryModifier and TypeMethodDescriptiondefault <A> AgetAttached(AttachmentType<A> type) Gets the data associated with the givenAttachmentType, ornullif it doesn't yet exist.default <A> AgetAttachedOrCreate(AttachmentType<A> type) Specialization ofgetAttachedOrCreate(AttachmentType, Supplier), but only for attachment types withinitializers. It will throw an exception if one is not present.default <A> AgetAttachedOrCreate(AttachmentType<A> type, Supplier<A> initializer) Gets the data associated with the givenAttachmentType, or initializes it using the non-nullresult of the providedSupplier.default <A> AgetAttachedOrElse(AttachmentType<A> type, A defaultValue) Gets the data associated with the givenAttachmentType, or returns the provided default value if it doesn't exist.default <A> AgetAttachedOrGet(AttachmentType<A> type, Supplier<A> defaultValue) Gets the data associated with the givenAttachmentType, or gets the provided default value from the provided non-nullsupplier if it doesn't exist.default <A> AgetAttachedOrSet(AttachmentType<A> type, A defaultValue) Gets the data associated with the givenAttachmentType, or initializes it using the provided non-nulldefault value.default <A> AgetAttachedOrThrow(AttachmentType<A> type) Gets the data associated with the givenAttachmentType, throwing aNullPointerExceptionif it doesn't yet exist.default booleanhasAttached(AttachmentType<?> type) Tests whether the givenAttachmentTypehas any associated data.default <A> AmodifyAttached(AttachmentType<A> type, UnaryOperator<A> modifier) Modifies the data associated with the givenAttachmentType.default <A> AremoveAttached(AttachmentType<A> type) Removes any data associated with the givenAttachmentType.default <A> AsetAttached(AttachmentType<A> type, A value) Sets the data associated with the givenAttachmentType.
- 
Field Details- 
NBT_ATTACHMENT_KEY- See Also:
 
 
- 
- 
Method Details- 
getAttachedGets the data associated with the givenAttachmentType, ornullif it doesn't yet exist.- Type Parameters:
- A- the type of the data
- Parameters:
- type- the attachment type
- Returns:
- the attached data
 
- 
getAttachedOrThrowGets the data associated with the givenAttachmentType, throwing aNullPointerExceptionif it doesn't yet exist.- Type Parameters:
- A- the type of the data
- Parameters:
- type- the attachment type
- Returns:
- the attached data
 
- 
getAttachedOrSetGets the data associated with the givenAttachmentType, or initializes it using the provided non-nulldefault value.- Type Parameters:
- A- the type of the data
- Parameters:
- type- the attachment type
- defaultValue- the fallback default value
- Returns:
- the attached data, initialized if originally absent
 
- 
getAttachedOrCreateGets the data associated with the givenAttachmentType, or initializes it using the non-nullresult of the providedSupplier.- Type Parameters:
- A- the type of the data
- Parameters:
- type- the attachment type
- initializer- the fallback initializer
- Returns:
- the attached data, initialized if originally absent
 
- 
getAttachedOrCreateSpecialization ofgetAttachedOrCreate(AttachmentType, Supplier), but only for attachment types withinitializers. It will throw an exception if one is not present.- Type Parameters:
- A- the type of the data
- Parameters:
- type- the attachment type
- Returns:
- the attached data, initialized if originally absent
 
- 
getAttachedOrElse@Contract("_, !null -> !null") default <A> A getAttachedOrElse(AttachmentType<A> type, @Nullable A defaultValue) Gets the data associated with the givenAttachmentType, or returns the provided default value if it doesn't exist. UnlikegetAttachedOrCreate(AttachmentType, Supplier), this doesn't initialize the attachment with the default value.- Type Parameters:
- A- the type of the attached data
- Parameters:
- type- the attachment type
- defaultValue- the default value to use as fallback
- Returns:
- the attached data, or the default value
 
- 
getAttachedOrGetGets the data associated with the givenAttachmentType, or gets the provided default value from the provided non-nullsupplier if it doesn't exist. The supplier may returnnull. UnlikegetAttachedOrCreate(AttachmentType, Supplier), this doesn't initialize the attachment with the default value.- Type Parameters:
- A- the type of the attached data
- Parameters:
- type- the attachment type
- defaultValue- the default value supplier to use as fallback
- Returns:
- the attached data, or the default value
 
- 
setAttachedSets the data associated with the givenAttachmentType. Passingnullremoves the data.- Type Parameters:
- A- the type of the data
- Parameters:
- type- the attachment type
- value- the new value
- Returns:
- the previous data
 
- 
hasAttachedTests whether the givenAttachmentTypehas any associated data. This doesn't create any data, and may returnfalseeven for attachment types with an automatic initializer.- Parameters:
- type- the attachment type
- Returns:
- whether there is associated data
 
- 
removeAttachedRemoves any data associated with the givenAttachmentType. Equivalent to callingsetAttached(AttachmentType, Object)withnull.- Type Parameters:
- A- the type of the data
- Parameters:
- type- the attachment type
- Returns:
- the previous data
 
- 
modifyAttachedModifies the data associated with the givenAttachmentType. Functionally the same as callinggetAttached(AttachmentType), applying the modifier, then callingsetAttached(AttachmentType, Object)with the result. The modifier takes in the currently attached value, ornullif no attachment is present.- Type Parameters:
- A- the type of the data
- Parameters:
- type- the attachment type
- modifier- the operation to apply to the current data, or to- nullif it doesn't exist yet
- Returns:
- the previous data
 
 
-