Package net.ixdarklord.coolcatcore.api.attachment


package net.ixdarklord.coolcatcore.api.attachment
Attachments: typed data any entity (players included), block entity, item stack, level or the server itself can carry, and offline players' saved values.

Each mod declares its attachments through its own AttachmentRegistry, which stores them under the mod's id (<modid>:attachments). An attachment saves with its holder, syncs by its SyncPolicy, and is read and written straight from the attachment:


 public static final AttachmentRegistry ATTACHMENTS = AttachmentRegistry.create(MOD_ID);
 public static final Attachment<Integer> MADNESS = ATTACHMENTS.builder("madness", Codec.INT, 0)
         .sync(SyncPolicy.SELF).copyOnDeath().build();

 // While the mod initialises:
 ATTACHMENTS.register();

 MADNESS.update(player, madness -> madness + 1);   // server: saved, and sent to that player at the end of the tick
 int madness = MADNESS.get(minecraft.player);        // client: the synced value
 
Changes can be watched, changed or cancelled with AttachmentEvents. Related packages: net.ixdarklord.coolcatcore.api.container (inventories, including container attachments), net.ixdarklord.coolcatcore.api.handler (handlers holders hand out, cached and invalidated) and net.ixdarklord.coolcatcore.api.block (block entity base classes).