类 AttachmentHolder

java.lang.Object
net.neoforged.neoforge.attachment.AttachmentHolder
所有已实现的接口:
IAttachmentHolder
直接已知子类:
AttachmentHolder.AsField, BlockEntity, Entity, Level

public abstract class AttachmentHolder extends Object implements IAttachmentHolder
Implementation class for objects that can hold data attachments. For the user-facing methods, see IAttachmentHolder.
  • 字段详细资料

    • ATTACHMENTS_NBT_KEY

      public static final String ATTACHMENTS_NBT_KEY
      另请参阅:
    • IN_DEV

      private static final boolean IN_DEV
    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • attachments

      @Nullable @Nullable Map<AttachmentType<?>,Object> attachments
  • 构造器详细资料

    • AttachmentHolder

      public AttachmentHolder()
  • 方法详细资料

    • validateAttachmentType

      private void validateAttachmentType(AttachmentType<?> type)
    • getAttachmentMap

      final Map<AttachmentType<?>,Object> 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 as this for most cases, but when using AttachmentHolder.AsField it is the field holder.
    • hasAttachments

      public final boolean hasAttachments()
      从接口复制的说明: IAttachmentHolder
      Returns true if there is any data attachments, false otherwise.
      指定者:
      hasAttachments 在接口中 IAttachmentHolder
    • hasData

      public final boolean hasData(AttachmentType<?> type)
      从接口复制的说明: IAttachmentHolder
      Returns true if there is a data attachment of the give type, false otherwise.
      指定者:
      hasData 在接口中 IAttachmentHolder
    • getData

      public final <T> T getData(AttachmentType<T> type)
      从接口复制的说明: IAttachmentHolder
      返回 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.

      指定者:
      getData 在接口中 IAttachmentHolder
      返回:
      the data attachment of the given type
    • getExistingDataOrNull

      @Nullable public <T> T getExistingDataOrNull(AttachmentType<T> type)
      指定者:
      getExistingDataOrNull 在接口中 IAttachmentHolder
      返回:
      an existing data attachment value of the given type, or null if there is no data attachment of the given type
    • setData

      @MustBeInvokedByOverriders @Nullable public <T> T setData(AttachmentType<T> type, T data)
      从接口复制的说明: IAttachmentHolder
      Sets the data attachment of the given type.
      指定者:
      setData 在接口中 IAttachmentHolder
      返回:
      the previous value for that attachment type, if any, or null if there was none
    • removeData

      @MustBeInvokedByOverriders @Nullable public <T> T removeData(AttachmentType<T> type)
      从接口复制的说明: IAttachmentHolder
      Removes the data attachment of the given type.
      指定者:
      removeData 在接口中 IAttachmentHolder
      返回:
      the previous value for that attachment type, if any, or null if there was none
    • serializeAttachments

      public final void serializeAttachments(ValueOutput tag)
      Writes the serializable attachments to a tag.
    • deserializeAttachments

      protected final void deserializeAttachments(ValueInput input)
      Reads serializable attachments from a tag previously created via serializeAttachments(ValueOutput).