Class AttachmentRegistry
java.lang.Object
net.ixdarklord.coolcatcore.api.attachment.AttachmentRegistry
One mod's
Attachments. A mod's values are stored under its own id: in the <modid>:attachments item
component on stacks, and in a <modid>:attachments tag in entity and block entity data, so each mod's data
stays separate from every other's.
public static final AttachmentRegistry ATTACHMENTS = AttachmentRegistry.create(MOD_ID);
public static final Attachment<Integer> MADNESS = ATTACHMENTS.builder("madness", Codec.INT, 0).build();
// While the mod initialises (it registers the item component, like a DeferredRegister):
ATTACHMENTS.register();
-
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<AttachmentRegistry> all()Every mod's registry.<T> Attachment.Builder<T> An attachment saved with its holder.net.minecraft.core.component.DataComponentType<AttachmentBundle> net.minecraft.core.component.DataComponentType<?> The<modid>:attachmentsitem component holding this mod's values on stacks.container(String name, ContainerLayout layout) An inventory as an attachment, so any entity or block entity can carry one (a player's backpack slots, a mob's loot).static AttachmentRegistryThe registry of a mod; each mod creates one.static @Nullable AttachmentRegistry@Nullable Attachment<?> Collection<Attachment<?>> net.minecraft.resources.ResourceLocationmodid:name.booleanWhetherregister()was called, so the item component exists.modId()<T> Attachment.Builder<T> mutableBuilder(String name, com.mojang.serialization.Codec<T> codec, Supplier<T> defaultValue) An attachment saved with its holder, whose default is made fresh for each holder: for mutable values, changed withAttachment.modify(net.minecraft.world.entity.Entity, java.util.function.Consumer<T>)(orTrackableones).voidregister()Registers the mod's item component.tagName()The name of the tag holding this mod's values in entity and block entity data.toString()<T> Attachment.Builder<T> transientBuilder(String name, Supplier<T> defaultValue) An attachment that's never saved: its value is gone when the holder unloads (timers, caches, per-session state).
-
Method Details
-
create
The registry of a mod; each mod creates one. -
all
Every mod's registry. -
forMod
-
builder
public <T> Attachment.Builder<T> builder(String name, com.mojang.serialization.Codec<T> codec, T defaultValue) An attachment saved with its holder.defaultValueis what holders without a value read; it must be immutable. For a mutable default, usemutableBuilder(java.lang.String, com.mojang.serialization.Codec<T>, java.util.function.Supplier<T>). -
mutableBuilder
public <T> Attachment.Builder<T> mutableBuilder(String name, com.mojang.serialization.Codec<T> codec, Supplier<T> defaultValue) An attachment saved with its holder, whose default is made fresh for each holder: for mutable values, changed withAttachment.modify(net.minecraft.world.entity.Entity, java.util.function.Consumer<T>)(orTrackableones). Not usable on item stacks. -
transientBuilder
An attachment that's never saved: its value is gone when the holder unloads (timers, caches, per-session state). It can still be synced withAttachment.Builder.networkCodec(net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.RegistryFriendlyByteBuf, T>)andAttachment.Builder.sync(net.ixdarklord.coolcatcore.api.attachment.SyncPolicy). Not usable on item stacks. -
container
An inventory as an attachment, so any entity or block entity can carry one (a player's backpack slots, a mob's loot). Its slot changes save and sync on their own. -
register
public void register()Registers the mod's item component. Call once, while the mod initialises. -
modId
-
id
modid:name. -
get
-
getAttachments
-
tagName
The name of the tag holding this mod's values in entity and block entity data. -
componentType
public net.minecraft.core.component.DataComponentType<?> componentType()The<modid>:attachmentsitem component holding this mod's values on stacks. -
isRegistered
public boolean isRegistered()Whetherregister()was called, so the item component exists. -
bundleComponent
-
toString
-