Class AttachmentHolder
java.lang.Object
net.neoforged.neoforge.attachment.AttachmentHolder
- All Implemented Interfaces:
 IAttachmentHolder
- Direct Known Subclasses:
 AttachmentHolder.AsField,BlockEntity,Entity,ItemStack,Level
Implementation class for objects that can hold data attachments.
 For the user-facing methods, see 
IAttachmentHolder.- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classVersion of theAttachmentHolderthat is suitable for storing in a field. - 
Field Summary
FieldsModifier and TypeFieldDescription(package private) @Nullable Map<AttachmentType<?>,Object> static final Stringprivate static final booleanprivate static final org.slf4j.Logger - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionstatic <H extends AttachmentHolder>
booleanareAttachmentsCompatible(H first, H second) Checks if two attachment holders have compatible attachments, i.e.protected final voidReads serializable attachments from a tag previously created viaserializeAttachments().(package private) final Map<AttachmentType<?>,Object> Create the attachment map if it does not yet exist, or return the current map.final <T> TgetData(AttachmentType<T> type) Returns the data attachment of the given type.(package private) IAttachmentHolderReturns the attachment holder that is exposed to the user.final booleanReturnstrueif there is any data attachments,falseotherwise.final booleanhasData(AttachmentType<?> type) Returnstrueif there is a data attachment of the give type,falseotherwise.<T> TremoveData(AttachmentType<T> type) Removes the data attachment of the given type.final @Nullable CompoundTagWrites the serializable attachments to a tag.<T> TsetData(AttachmentType<T> type, T data) Sets the data attachment of the given type.private voidvalidateAttachmentType(AttachmentType<?> type) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.neoforged.neoforge.attachment.IAttachmentHolder
getData, hasData, removeData, setData 
- 
Field Details
- 
ATTACHMENTS_NBT_KEY
- See Also:
 
 - 
IN_DEV
private static final boolean IN_DEV - 
LOGGER
private static final org.slf4j.Logger LOGGER - 
attachments
 
 - 
 - 
Constructor Details
- 
AttachmentHolder
public AttachmentHolder() 
 - 
 - 
Method Details
- 
validateAttachmentType
 - 
getAttachmentMap
Create the attachment map if it does not yet exist, or return the current map. - 
getExposedHolder
IAttachmentHolder getExposedHolder()Returns the attachment holder that is exposed to the user. This is the same asthisfor most cases, but when usingAttachmentHolder.AsFieldit is the field holder. - 
hasAttachments
public final boolean hasAttachments()Description copied from interface:IAttachmentHolderReturnstrueif there is any data attachments,falseotherwise.- Specified by:
 hasAttachmentsin interfaceIAttachmentHolder
 - 
hasData
Description copied from interface:IAttachmentHolderReturnstrueif there is a data attachment of the give type,falseotherwise.- Specified by:
 hasDatain interfaceIAttachmentHolder
 - 
getData
Description copied from interface:IAttachmentHolderReturns the data attachment of the given type.If there is no data attachment of the given type, the default value is stored in this holder and returned.
- Specified by:
 getDatain interfaceIAttachmentHolder- Returns:
 - the data attachment of the given type
 
 - 
setData
Description copied from interface:IAttachmentHolderSets the data attachment of the given type.- Specified by:
 setDatain interfaceIAttachmentHolder- Returns:
 - the previous value for that attachment type, if any, or 
nullif there was none 
 - 
removeData
Description copied from interface:IAttachmentHolderRemoves the data attachment of the given type.- Specified by:
 removeDatain interfaceIAttachmentHolder- Returns:
 - the previous value for that attachment type, if any, or 
nullif there was none 
 - 
serializeAttachments
Writes the serializable attachments to a tag. Returnsnullif there are no serializable attachments. - 
deserializeAttachments
Reads serializable attachments from a tag previously created viaserializeAttachments(). - 
areAttachmentsCompatible
Checks if two attachment holders have compatible attachments, i.e. if they have the same serialized form.Same as calling
Objects.equals(first.serializeAttachments(), second.serializeAttachments()), but implemented more efficiently.- Returns:
 trueif the attachments are compatible,falseotherwise
 
 -