Class AttachmentHolder
java.lang.Object
net.neoforged.neoforge.attachment.AttachmentHolder
- All Implemented Interfaces:
IAttachmentHolder
- Direct Known Subclasses:
AttachmentHolder.AsField,BlockEntity,Entity,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 TypeMethodDescriptionprotected final voiddeserializeAttachments(HolderLookup.Provider provider, CompoundTag tag) Reads serializable attachments from a tag previously created viaserializeAttachments(HolderLookup.Provider).(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.<T> Optional<T> getExistingData(AttachmentType<T> type) Returns an optional possibly containing a data attachment value 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 CompoundTagserializeAttachments(HolderLookup.Provider provider) Writes 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, getExistingData, 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
-
getExistingData
Description copied from interface:IAttachmentHolderReturns an optional possibly containing a data attachment value of the given type.If there is no data attachment of the given type, an empty optional is returned.
- Specified by:
getExistingDatain interfaceIAttachmentHolder- Returns:
- an optional possibly containing a data attachment value 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(HolderLookup.Provider).
-