Interface AttachmentHolder
- All Known Implementing Classes:
AttachmentStore,ItemStackAttachments
public interface AttachmentHolder
The
Attachment values of one entity, block entity, item stack, level or the server. Attachment's own methods
(MADNESS.get(player)) are shortcuts for these.
Entities and block entities keep their values in memory, save them with their other data and sync them by each
attachment's SyncPolicy. Values set on a client stay on that client until the server's next sync. Item stacks keep
theirs in their mod's <modid>:attachments component, which travels with the stack like any other component.
Levels and the server keep theirs in saved data, in the level's and the server's data folder.
-
Method Summary
Modifier and TypeMethodDescriptionSet<Attachment<?>> The attachments with a stored value.<T> Tget(Attachment<T> attachment) The value, or the attachment's default if none was set.static AttachmentHolderglobal(net.minecraft.world.level.Level level) The server's values as a side knows them: the server's own, or on a client the copy it was sent.booleanhas(Attachment<?> attachment) Whether a value is stored, rather than read from the default.booleanWhether the holder is on a client.booleanisValid()Whether the holder still exists: the entity or block entity isn't removed, the stack isn't empty.voidmarkDirty(Attachment<?> attachment) Saves and syncs a value that was changed in place, withoutmodify(net.ixdarklord.coolcatcore.api.attachment.Attachment<T>, java.util.function.Consumer<T>).<T> voidmodify(Attachment<T> attachment, Consumer<T> mutator) Changes a mutable value in place, then saves and syncs it.static AttachmentHolderof(net.minecraft.server.MinecraftServer server) The server's own values, saved in its data folder.static AttachmentHolderof(net.minecraft.world.entity.Entity entity) static AttachmentHolderof(net.minecraft.world.item.ItemStack stack) A view of the stack's data; it reads and writes the stack directly, so it's cheap and never out of date.static AttachmentHolderof(net.minecraft.world.level.block.entity.BlockEntity blockEntity) static AttachmentHolderof(net.minecraft.world.level.Level level) A level's values: a server level's saved in its data folder, a client level's as the server sent them.owner()The entity, block entity, item stack, level or server holding the values.voidreset(Attachment<?> attachment) Removes the value, so the default is read again.<T> voidset(Attachment<T> attachment, T value) Sets the value.default <T> Tupdate(Attachment<T> attachment, UnaryOperator<T> function) Sets the value tofunction's result and returns it.
-
Method Details
-
of
-
of
-
of
A level's values: a server level's saved in its data folder, a client level's as the server sent them. -
of
The server's own values, saved in its data folder. -
global
The server's values as a side knows them: the server's own, or on a client the copy it was sent. -
of
A view of the stack's data; it reads and writes the stack directly, so it's cheap and never out of date. -
owner
Object owner()The entity, block entity, item stack, level or server holding the values. -
isClientSide
boolean isClientSide()Whether the holder is on a client. Alwaysfalsefor item stacks, which have no side. -
isValid
boolean isValid()Whether the holder still exists: the entity or block entity isn't removed, the stack isn't empty. -
get
The value, or the attachment's default if none was set. -
set
Sets the value. Setting an equal value does nothing. -
update
Sets the value tofunction's result and returns it. -
modify
Changes a mutable value in place, then saves and syncs it. Not for item stacks, whose values are immutable: useupdate(net.ixdarklord.coolcatcore.api.attachment.Attachment<T>, java.util.function.UnaryOperator<T>)there. -
markDirty
Saves and syncs a value that was changed in place, withoutmodify(net.ixdarklord.coolcatcore.api.attachment.Attachment<T>, java.util.function.Consumer<T>). -
has
Whether a value is stored, rather than read from the default. -
reset
Removes the value, so the default is read again. -
attachments
Set<Attachment<?>> attachments()The attachments with a stored value.
-