Something went wrong. Try again.
Library for my mods and adding supporter perks
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111/* * Copyright 2026 macuguita * * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * * https://joinup.ec.europa.eu/software/page/eupl * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. */package com.macuguita.lib.api.attachment;
import java.util.function.Supplier;
import org.jetbrains.annotations.ApiStatus;
import net.minecraft.network.RegistryFriendlyByteBuf;import net.minecraft.network.codec.StreamCodec;import net.minecraft.resources.Identifier;
import com.mojang.serialization.Codec;
/** * A builder used to configure and create a {@link GuitaAttachmentType} with finer control over its * properties. * * <p>Instances are handed to the configurator passed to {@link GuitaAttachmentRegistry#create} and * are not meant to be implemented by mods. * * @param <A> the type of the attached data */@ApiStatus.NonExtendablepublic interface GuitaAttachmentBuilder<A> {
/** * Declares that this attachment should persist between server restarts using the provided * {@link Codec} for (de)serialization. * * @param codec the codec used for (de)serialization * @return this builder */ GuitaAttachmentBuilder<A> persistent(Codec<A> codec);
/** * Declares that this attachment should remain when a player dies and respawns or when a mob is * converted. * * <p><strong>Platform note:</strong> on NeoForge copying on death requires the attachment to be * persistent, while on Fabric this flag can be used on its own. If you need portable behavior, * call {@link #persistent(Codec)} as well. * * @return this builder */ GuitaAttachmentBuilder<A> copyOnDeath();
/** * Sets the default initializer for this attachment type. It is used to automatically initialize * attachments that don't yet exist when calling {@code getAttachedOrCreate}. It must not return * {@code null}. * * @param initializer the initializer * @return this builder */ GuitaAttachmentBuilder<A> initializer(Supplier<A> initializer);
/** * Declares that this attachment type may be automatically synchronized with some clients, as * determined by {@code syncPredicate}. * * @param streamCodec the codec used to serialize the attachment data over the network * @param syncPredicate a {@link GuitaAttachmentSyncPredicate} determining with which clients to * synchronize data * @return this builder */ GuitaAttachmentBuilder<A> syncWith( StreamCodec<? super RegistryFriendlyByteBuf, A> streamCodec, GuitaAttachmentSyncPredicate syncPredicate);
/** * Declares that this attachment type may be automatically synchronized with some clients, as * determined by {@code syncPredicate}. * * <p><strong>Platform note:</strong> {@code maxSyncSize} is only honored on Fabric; NeoForge has * no equivalent knob and ignores it. * * @param streamCodec the codec used to serialize the attachment data over the network * @param syncPredicate a {@link GuitaAttachmentSyncPredicate} determining with which clients to * synchronize data * @param maxSyncSize the max number of data bytes that can be synced * @return this builder */ GuitaAttachmentBuilder<A> syncWith( StreamCodec<? super RegistryFriendlyByteBuf, A> streamCodec, GuitaAttachmentSyncPredicate syncPredicate, int maxSyncSize);
/** * Builds and registers this attachment type. * * @param id the attachment's identifier * @return the built and registered {@link GuitaAttachmentType} */ GuitaAttachmentType<A> buildAndRegister(Identifier id);}