/* * 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. * *
Instances are handed to the configurator passed to {@link GuitaAttachmentRegistry#create} and
* are not meant to be implemented by mods.
*
* @param the type of the attached data
*/
@ApiStatus.NonExtendable
public interface GuitaAttachmentBuilder {
/**
* 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 persistent(Codec codec);
/**
* Declares that this attachment should remain when a player dies and respawns or when a mob is
* converted.
*
* Platform note: 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 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 initializer(Supplier 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 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}.
*
* Platform note: {@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 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 buildAndRegister(Identifier id);
}