Something went wrong. Try again.
Library for my mods and adding supporter perks
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243/** * Platform-agnostic data attachment API for attaching arbitrary data to entities, block entities, * levels and chunks. * * <p>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. * * <h2>Example usage</h2> * * <pre>{@code * // Create and register an attachment type (during mod initialization). * public static final GuitaAttachmentType<Integer> MANA = * GuitaAttachmentRegistry.createDefaulted(id("mana"), () -> 0); * * public static final GuitaAttachmentType<String> 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 + "!"); * }</pre> * * <h2>Client synchronization</h2> * * <p>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 */@NullMarkedpackage com.macuguita.lib.api.attachment;
import org.jspecify.annotations.NullMarked;