/** * Platform-agnostic data attachment API for attaching arbitrary data to entities, block entities, * levels and chunks. * *
This package follows Fabric's data attachment API shape, but works on both Fabric and NeoForge. * Because injecting methods onto the game objects themselves would require mixins, reading and * writing is done through a lightweight {@link com.macuguita.lib.api.attachment.GuitaAttachmentTarget} * wrapper obtained with the {@code of} factory methods. * *
{@code
* // Create and register an attachment type (during mod initialization).
* public static final GuitaAttachmentType MANA =
* GuitaAttachmentRegistry.createDefaulted(id("mana"), () -> 0);
*
* public static final GuitaAttachmentType NICKNAME =
* GuitaAttachmentRegistry.create(id("nickname"), builder -> builder
* .initializer(() -> "unknown")
* .persistent(Codec.STRING)
* .syncWith(ByteBufCodecs.STRING_UTF8, GuitaAttachmentSyncPredicate.all()));
*
* // Read and write.
* GuitaAttachmentTarget target = GuitaAttachmentTarget.of(player);
* int mana = target.getAttachedOrCreate(MANA);
* target.setAttached(MANA, mana + 10);
* target.modifyAttached(NICKNAME, name -> name + "!");
* }
*
* Syncing is configured per attachment type via * {@link com.macuguita.lib.api.attachment.GuitaAttachmentBuilder#syncWith} and a * {@link com.macuguita.lib.api.attachment.GuitaAttachmentSyncPredicate}. * * @see com.macuguita.lib.api.attachment.GuitaAttachmentRegistry * @see com.macuguita.lib.api.attachment.GuitaAttachmentTarget */ @NullMarked package com.macuguita.lib.api.attachment; import org.jspecify.annotations.NullMarked;