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 a <modid>:attachments tag in
a stack's NBT, and 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:
ATTACHMENTS.register();
-
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<AttachmentRegistry>all()Every mod's registry.<T> Attachment.Builder<T>An attachment saved with its holder.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).net.minecraft.world.level.storage.loot.functions.CopyNbtFunction.BuilderA loot function for a block's loot table that copies this mod'skeepOnDropvalues from the broken block entity into the dropped item, for placing it to restore them: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.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()Call once, while the mod initialises.tagName()The name of the tag (<modid>:attachments) holding this mod's values: in entity and block entity data, and in item stacks' NBT.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.ixdarklord.coolcatcore.api.network.codec.StreamCodec<? super net.minecraft.network.FriendlyByteBuf, 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()Call once, while the mod initialises. On 1.20.1, item stacks keep their values in their NBT, so there's no item component to register; this only marks the registry ready, and is kept so code stays the same across versions. -
modId
-
id
modid:name. -
get
-
getAttachments
-
tagName
The name of the tag (<modid>:attachments) holding this mod's values: in entity and block entity data, and in item stacks' NBT. -
isRegistered
public boolean isRegistered()Whetherregister()was called. -
copyKeptOnDrop
public net.minecraft.world.level.storage.loot.functions.CopyNbtFunction.Builder copyKeptOnDrop()A loot function for a block's loot table that copies this mod'skeepOnDropvalues from the broken block entity into the dropped item, for placing it to restore them:
In a JSON loot table, it's aLootItem.lootTableItem(block).apply(MyMod.ATTACHMENTS.copyKeptOnDrop())minecraft:copy_nbtfunction fromblock_entity, with one"op": "replace"operation per value: from"<modid>:attachments"."<name>"toBlockEntityTag."<modid>:attachments"."<name>". -
toString
-