Class AttachmentStore

java.lang.Object
net.ixdarklord.coolcatcore.internal.attachment.AttachmentStore
All Implemented Interfaces:
AttachmentHolder

public final class AttachmentStore extends Object implements AttachmentHolder
  • Constructor Details

    • AttachmentStore

      public AttachmentStore(Object owner)
  • Method Details

    • owner

      public Object owner()
      Description copied from interface: AttachmentHolder
      The entity, block entity or item stack holding the values.
      Specified by:
      owner in interface AttachmentHolder
    • level

      @Nullable public @Nullable net.minecraft.world.level.Level level()
    • isClientSide

      public boolean isClientSide()
      Description copied from interface: AttachmentHolder
      Whether the holder is on a client. Always false for item stacks, which have no side.
      Specified by:
      isClientSide in interface AttachmentHolder
    • isValid

      public boolean isValid()
      Description copied from interface: AttachmentHolder
      Whether the holder still exists: the entity or block entity isn't removed, the stack isn't empty.
      Specified by:
      isValid in interface AttachmentHolder
    • get

      public <T> T get(Attachment<T> key)
      Description copied from interface: AttachmentHolder
      The value, or the attachment's default if none was set.
      Specified by:
      get in interface AttachmentHolder
    • set

      public <T> void set(Attachment<T> key, T value)
      Description copied from interface: AttachmentHolder
      Sets the value. Setting an equal value does nothing.
      Specified by:
      set in interface AttachmentHolder
    • modify

      public <T> void modify(Attachment<T> key, Consumer<T> mutator)
      Description copied from interface: AttachmentHolder
      Changes a mutable value in place, then saves and syncs it. Not for item stacks, whose values are immutable: use AttachmentHolder.update(Attachment, UnaryOperator) there.
      Specified by:
      modify in interface AttachmentHolder
    • markDirty

      public void markDirty(Attachment<?> key)
      Description copied from interface: AttachmentHolder
      Saves and syncs a value that was changed in place, without AttachmentHolder.modify(Attachment, Consumer).
      Specified by:
      markDirty in interface AttachmentHolder
    • has

      public boolean has(Attachment<?> key)
      Description copied from interface: AttachmentHolder
      Whether a value is stored, rather than read from the default.
      Specified by:
      has in interface AttachmentHolder
    • reset

      public void reset(Attachment<?> key)
      Description copied from interface: AttachmentHolder
      Removes the value, so the default is read again.
      Specified by:
      reset in interface AttachmentHolder
    • attachments

      public Set<Attachment<?>> attachments()
      Description copied from interface: AttachmentHolder
      The attachments with a stored value.
      Specified by:
      attachments in interface AttachmentHolder
    • save

      public void save(net.minecraft.world.level.storage.ValueOutput output)
    • hasSaved

      public static boolean hasSaved(net.minecraft.world.level.storage.ValueInput input)
      Whether saved data holds any mod's attachments.
    • load

      public void load(net.minecraft.world.level.storage.ValueInput input)
    • copyFrom

      public void copyFrom(AttachmentStore other, Predicate<Attachment<?>> filter, net.minecraft.core.HolderLookup.Provider registries)
      Copies another store's values, deep-copying persistent ones through their codec. Transient values are shared, except trackable ones, which can't have two owners.