net.kernelpanicsoft.archie.serialization¶
Types¶
ArchieDataAttachment¶
interface ArchieDataAttachment<T> : ReadWriteProperty<Any?, T>
A DataManager-backed attachment. Unlike NBTHolder, which owns its own per-instance field storage, a single ArchieDataAttachment instance is stateless and reusable as the delegate for a var Holder.property by ... extension property on any number of holder instances - the holder passed to each method (or, via getValue/setValue, the property's receiver) is where the data actually lives. Obtain instances via AttachmentRegistry.attachment.
ArchieStorageList¶
class ArchieStorageList<T : UpdateManager<NbtTag>> : Iterable<T>
A dynamically-sized, index-ordered list of storage-like UpdateManagers, declared via NBTHolder.itemListField/fluidListField/energyListField. Every entry shares the same shape (size/limit/capacity), built via factory on add.
ArchieStorageMap¶
A dynamically-sized, key-ordered map of storage-like UpdateManagers (e.g. net.kernelpanicsoft.archie.transfer.ArchieItemStorage), declared via NBTHolder.itemMapField/fluidMapField/energyMapField. Unlike NestedNBTHolderMap, every entry shares the same shape (size/limit/capacity), fixed once at field declaration, so factory is supplied once here rather than per getOrPut call.
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().
CodecSerializer¶
open class CodecSerializer<T>(codec: Codec<T>) : KSerializer<T>
Used for Codec.kSerializer, you could extend this class to make any modifications you like.
FluidStackNBTHolderImpl¶
class FluidStackNBTHolderImpl(stack: FluidStack) : NBTHolder
NBTHolder implementation backing NBTHolder.fluid, persisting field values into stack's CustomData component instead of an in-memory map.
ItemStackNBTHolderImpl¶
class ItemStackNBTHolderImpl(stack: ItemStack) : NBTHolder
NBTHolder implementation backing NBTHolder.item, persisting field values into stack's CustomData component instead of an in-memory map.
KOps¶
object KOps
Mojang DynamicOps implementations for the tree formats used elsewhere in this package (kotlinx.serialization.json.JsonElement, net.peanuuutz.tomlkt.TomlElement, and knbt's net.benwoodworth.knbt.NbtTag), so com.mojang.serialization.Codecs can operate on them directly. Registered with SerializationManager and used internally by SerializerCodec and CodecSerializer; not usually needed directly.
NBTHolder¶
interface NBTHolder
An interface for managing NBT-backed fields on block entities, item stacks, or fluid stacks.
NBTHolderImpl¶
class NBTHolderImpl : NBTHolder
Default NBTHolder implementation backing NBTHolder.create. Field values are cached in-memory as knbt tags keyed by the delegated property's snake_case name; properties annotated Sync additionally push updates through net.kernelpanicsoft.archie.gui.blockentity.BlockEntityStateManager-backed state containers when the holder is attached to a BlockEntity.
NestedNBTHolder¶
class NestedNBTHolder<T : NBTHolder>
NestedNBTHolderList¶
class NestedNBTHolderList<T : NBTHolder> : Iterable<T>
A dynamically-sized, index-ordered list of nested NBTHolders, declared via NBTHolder.nestedListField. Like NestedNBTHolderMap, entries can be heterogeneous - add takes its own factory, and reconstructing a saved entry inspects that entry's own raw sub-CompoundTag first (the same factory shape NBTHolder.nestedListField itself takes) to decide which concrete holder type to rebuild. T is the common upper bound every entry shares - see NestedNBTHolderMap's KDoc for why that's still useful even for a genuinely heterogeneous list.
NestedNBTHolderMap¶
A mutable map of nested NBTHolders, keyed by String, declared via NBTHolder.nestedMapField. Each entry is itself a self-contained, independently field()-declared NBTHolder rather than one shared value shape - useful when a map's entries are heterogeneous (e.g. one holder type per registry-driven "kind" of thing an entry represents), which NBTHolder.mapField can't express since it needs one fixed, kotlinx.serialization-compatible value type for every entry. T is the common upper bound every entry shares - plain NBTHolder itself if entries have nothing more specific in common, or a narrower shared supertype (a caller can still insert any subtype of T via getOrPut's own type parameter) - so callers get correctly-typed entries back without a manual cast at every read site.
ObservableList¶
class ObservableList<T>(list: MutableList<T>, listener: (MutableList<T>) -> Unit) : MutableList<T>
A MutableList wrapper that invokes listener with the underlying list after every mutating operation. Used by listField-style NBTHolder delegates to detect changes and persist/sync them.
ObservableMap¶
class ObservableMap<K, V>(map: MutableMap<K, V>, listener: (MutableMap<K, V>) -> Unit) : MutableMap<K, V>
A MutableMap wrapper that invokes listener with the underlying map after every mutating operation. Used by mapField-style NBTHolder delegates to detect changes and persist/sync them.
SerializationManager¶
object SerializationManager
Manages serializers for KLib, allowing customization and extension.
SerializerCodec¶
open class SerializerCodec<T : Any>(serializer: KSerializer<T>) : Codec<T>
Used for KSerializer.codec, you could extend this class to make any modifications you like.
Sync¶
@Target
(allowedTargets = [AnnotationTarget.PROPERTY])annotation class Sync
Marks an NBTHolder-delegated property as one that should be synced from server to client.
Properties¶
fromMinecraft¶
val CompoundTag.fromMinecraft: NbtCompound
Converts a Minecraft CompoundTag to the equivalent knbt NbtCompound.
val ListTag.fromMinecraft: NbtList<*>?
Converts a Minecraft ListTag to the equivalent knbt NbtList, or null for an untyped (empty) list.
val Tag.fromMinecraft: NbtTag?
Converts a Minecraft Tag to the equivalent knbt tag, or null for an EndTag.
NBT¶
val NBT: Nbt
A Nbt (knbt) instance pre-configured for Minecraft's Java-edition NBT format, uncompressed.
toGson¶
val JsonElement.toGson: JsonElement
Convert any JsonElement from kotlinx.serialization.json into GsonElement from gson
toKson¶
val JsonElement.toKson: JsonElement
Convert any GsonElement from gson into JsonElement kotlinx.serialization.json
toMinecraft¶
val NbtCompound.toMinecraft: CompoundTag
Converts a knbt NbtCompound to the equivalent Minecraft CompoundTag.
val NbtList<*>.toMinecraft: ListTag
Converts a knbt NbtList to the equivalent Minecraft ListTag.
val NbtTag?.toMinecraft: Tag
Converts a knbt tag to the equivalent Minecraft Tag (a null receiver becomes EndTag).
Functions¶
buildComponentPatch¶
inline fun buildComponentPatch(builderAction: DataComponentPatch.Builder.() -> Unit): DataComponentPatch
Builds a DataComponentPatch using Minecraft's DataComponentPatch.Builder DSL via builderAction.
buildCompoundTag¶
inline fun buildCompoundTag(builderAction: NbtCompoundBuilder.() -> Unit): CompoundTag
Builds a Minecraft CompoundTag using knbt's NbtCompoundBuilder DSL via builderAction.
buildListTag¶
inline fun <T : NbtTag> buildListTag(builderAction: NbtListBuilder<T>.() -> Unit): ListTag
Builds a Minecraft ListTag using knbt's NbtListBuilder DSL via builderAction.
decodeFromNbtTagRootless¶
inline fun <T> Nbt.decodeFromNbtTagRootless(tag: NbtTag): T
Reified variant of decodeFromNbtTagRootless that resolves T's serializer automatically.
fun <T> Nbt.decodeFromNbtTagRootless(deserializer: DeserializationStrategy<T>, tag: NbtTag): T
The inverse of encodeToNbtTagRootless: decodes tag as T, re-wrapping it in a one-entry compound keyed by the serial name first if T is a class/polymorphic type.
defer¶
fun defer(deferred: () -> SerialDescriptor): SerialDescriptor
Returns serial descriptor that delegates all the calls to descriptor returned by deferred block. Used to resolve cyclic dependencies between recursive serializable structures.
DeferredArraySerializer¶
Returns serializer for reference Array of type E with descriptor of StructureKind.LIST kind. Each element of the array is serialized with the given elementSerializer.
Returns serializer for reference Array of type E with descriptor of StructureKind.LIST kind. Each element of the array is serialized with the given elementSerializer.
DeferredListSerializer¶
fun <T> DeferredListSerializer(elementSerializer: KSerializer<T>): KSerializer<List<T>>
DeferredMapSerializer¶
DeferredSetSerializer¶
fun <T> DeferredSetSerializer(elementSerializer: KSerializer<T>): KSerializer<Set<T>>
encodeToNbtTagRootless¶
inline fun <T> Nbt.encodeToNbtTagRootless(value: T): NbtTag
Reified variant of encodeToNbtTagRootless that resolves T's serializer automatically.
fun <T> Nbt.encodeToNbtTagRootless(serializer: SerializationStrategy<T>, value: T): NbtTag
Like Nbt.encodeToNbtTag, but for class/polymorphic types unwraps the single top-level compound entry keyed by the serial name, returning its value directly instead of a one-entry NbtCompound wrapper.
forEachTag¶
inline fun forEachTag(compoundTag: CompoundTag, action: (Map.Entry<String, NbtTag>) -> Unit)
Runs action for each key/value entry of compoundTag, with the value converted to a knbt NbtTag.
inline fun forEachTag(listTag: ListTag, action: (NbtTag) -> Unit)
Runs action for each element of listTag, converted to a knbt NbtTag. No-op for an empty/untyped list.
mergeToCompoundTag¶
inline fun mergeToCompoundTag(compoundTag: CompoundTag, builderAction: NbtCompoundBuilder.() -> Unit)
Builds entries via knbt's NbtCompoundBuilder DSL and puts each of them into the existing compoundTag.
read¶
Gets data from a RegistryFriendlyByteBuf using the KSerializer resolved for its type.
Gets data from a RegistryFriendlyByteBuf using the provided KSerializer
write¶
Writes data into a RegistryFriendlyByteBuf using the KSerializer resolved for its type.
Writes data into a RegistryFriendlyByteBuf using a KSerializer