AttachmentRegistry¶
abstract class AttachmentRegistry(modId: String)
Base class for declaring a mod's ArchieDataAttachments, wrapping a single Common Storage Lib DataManagerRegistry. Declare one object per mod extending this class, declare attachments as delegated properties on it via attachment (or one of the primitive convenience wrappers), then call init once at mod-init time - after those property initializers have already run, same ordering as net.kernelpanicsoft.archie.networking.NetworkChannel/Config.init().
Constructors¶
AttachmentRegistry¶
constructor(modId: String)
Functions¶
attachment¶
fun <T : Any> attachment(
serializer: KSerializer<T>,
sync: Boolean = false,
copyOnDeath: Boolean = false,
itemComponent: Boolean = false,
default: () -> T
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieDataAttachment<T>>>
Declares an ArchieDataAttachment backed by serializer, keyed by the delegated property's snake_case name. See ArchieDataAttachment for the full contract, including exactly what sync and itemComponent each do and don't cover.
Parameters
-
sync: Reactively push updates to tracking players on every
ArchieDataAttachment.set/ArchieDataAttachment.remove- Entity/BlockEntity on both loaders, ServerLevel on NeoForge only. -
copyOnDeath: Preserve the value across a player's death/respawn. Entity/BlockEntity holders only; meaningless (and untested by Archie) for
itemComponent-only attachments. -
itemComponent: Additionally back this attachment with a vanilla
DataComponentType, making it usable onItemStackholders too. -
default: Supplies the value used before a holder has anything explicitly set.
attachment¶
inline fun <T : Any> AttachmentRegistry.attachment(
sync: Boolean = false,
copyOnDeath: Boolean = false,
itemComponent: Boolean = false,
noinline default: () -> T
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieDataAttachment<T>>>
Reified variant of AttachmentRegistry.attachment that resolves the KSerializer for T automatically.
booleanAttachment¶
fun booleanAttachment(
sync: Boolean = false,
copyOnDeath: Boolean = false,
itemComponent: Boolean = false,
default: () -> Boolean = { false }
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieDataAttachment<Boolean>>>
byteAttachment¶
fun byteAttachment(
sync: Boolean = false,
copyOnDeath: Boolean = false,
itemComponent: Boolean = false,
default: () -> Byte = { 0 }
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieDataAttachment<Byte>>>
doubleAttachment¶
fun doubleAttachment(
sync: Boolean = false,
copyOnDeath: Boolean = false,
itemComponent: Boolean = false,
default: () -> Double = { 0.0 }
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieDataAttachment<Double>>>
floatAttachment¶
fun floatAttachment(
sync: Boolean = false,
copyOnDeath: Boolean = false,
itemComponent: Boolean = false,
default: () -> Float = { 0.0f }
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieDataAttachment<Float>>>
init¶
fun init()
Registers every attachment declared through this registry against the mod event bus. Call once, at mod-init time, after all of this object's by attachment(...) properties have already run.
intAttachment¶
fun intAttachment(
sync: Boolean = false,
copyOnDeath: Boolean = false,
itemComponent: Boolean = false,
default: () -> Int = { 0 }
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieDataAttachment<Int>>>
longAttachment¶
fun longAttachment(
sync: Boolean = false,
copyOnDeath: Boolean = false,
itemComponent: Boolean = false,
default: () -> Long = { 0 }
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieDataAttachment<Long>>>
shortAttachment¶
fun shortAttachment(
sync: Boolean = false,
copyOnDeath: Boolean = false,
itemComponent: Boolean = false,
default: () -> Short = { 0 }
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieDataAttachment<Short>>>
stringAttachment¶
fun stringAttachment(
sync: Boolean = false,
copyOnDeath: Boolean = false,
itemComponent: Boolean = false,
default: () -> String = { "" }
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieDataAttachment<String>>>