Class AttachmentRegistry

java.lang.Object
net.ixdarklord.coolcatcore.api.attachment.AttachmentRegistry

public final class AttachmentRegistry extends Object
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 Details

    • create

      public static AttachmentRegistry create(String modId)
      The registry of a mod; each mod creates one.
    • all

      public static Collection<AttachmentRegistry> all()
      Every mod's registry.
    • forMod

      @Nullable public static @Nullable AttachmentRegistry forMod(String modId)
    • builder

      public <T> Attachment.Builder<T> builder(String name, com.mojang.serialization.Codec<T> codec, T defaultValue)
      An attachment saved with its holder. defaultValue is what holders without a value read; it must be immutable. For a mutable default, use mutableBuilder(String, Codec, Supplier).
    • 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 with Attachment.modify(Entity, Consumer) (or Trackable ones). Not usable on item stacks.
    • transientBuilder

      public <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). It can still be synced with Attachment.Builder.networkCodec(StreamCodec) and Attachment.Builder.sync(SyncPolicy). Not usable on item stacks.
    • container

      public Attachment.Builder<SlotContainer> 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). 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

      public String modId()
    • id

      public net.minecraft.resources.Identifier id(String name)
      modid:name.
    • get

      @Nullable public @Nullable Attachment<?> get(String name)
    • getAttachments

      public Collection<Attachment<?>> getAttachments()
    • tagName

      public String 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>:attachments item component holding this mod's values on stacks.
    • isRegistered

      public boolean isRegistered()
      Whether register() was called, so the item component exists.
    • bundleComponent

      @Internal public net.minecraft.core.component.DataComponentType<AttachmentBundle> bundleComponent()
    • toString

      public String toString()
      Overrides:
      toString in class Object