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.
Constructors¶
NBTHolderImpl¶
constructor()
Functions¶
booleanField¶
open fun booleanField(default: () -> Boolean = { false }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, Boolean>>
byteField¶
open fun byteField(default: () -> Byte = { 0 }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, Byte>>
doubleField¶
open fun doubleField(default: () -> Double = { 0.0 }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, Double>>
energyField¶
open override fun energyField(capacity: Long, onUpdate: () -> Unit?): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieEnergyStorage>>
Declares an ArchieEnergyStorage field capped at capacity, keyed by the delegated property's name. See itemField for onUpdate's semantics.
energyListField¶
open override fun energyListField(capacity: Long, onUpdate: () -> Unit?): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieStorageList<ArchieEnergyStorage>>>
Declares an ArchieStorageList of ArchieEnergyStorages, each capped at capacity, keyed by the delegated property's name. See itemMapField for onUpdate's semantics.
energyMapField¶
open override fun energyMapField(capacity: Long, onUpdate: () -> Unit?): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieStorageMap<ArchieEnergyStorage>>>
Declares an ArchieStorageMap of ArchieEnergyStorages, each capped at capacity, keyed by the delegated property's name. See itemMapField for onUpdate's semantics.
field¶
open override fun <T> field(serializer: KSerializer<T>, default: () -> T): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, T>>
Declares a read-write field backed by serializer, keyed by the delegated property's name. default supplies the value used before the field has been loaded/set.
field¶
inline fun <T> NBTHolder.field(noinline default: () -> T): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, T>>
Reified variant of NBTHolder.field that resolves the KSerializer for T automatically.
floatField¶
open fun floatField(default: () -> Float = { 0.0f }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, Float>>
fluidField¶
open override fun fluidField(
limit: Long,
size: Int,
filter: Predicate<FluidResource>,
onUpdate: () -> Unit?
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieFluidStorage>>
Declares an ArchieFluidStorage field with size tank slots each capped at limit, keyed by the delegated property's name. See itemField for onUpdate's semantics.
fluidListField¶
open override fun fluidListField(
limit: Long,
size: Int,
filter: Predicate<FluidResource>,
onUpdate: () -> Unit?
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieStorageList<ArchieFluidStorage>>>
Declares an ArchieStorageList of ArchieFluidStorages, each with size tank slots capped at limit, keyed by the delegated property's name. See itemMapField for onUpdate's semantics.
fluidMapField¶
open override fun fluidMapField(
limit: Long,
size: Int,
filter: Predicate<FluidResource>,
onUpdate: () -> Unit?
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieStorageMap<ArchieFluidStorage>>>
Declares an ArchieStorageMap of ArchieFluidStorages, each with size tank slots capped at limit, keyed by the delegated property's name. See itemMapField for onUpdate's semantics.
getSyncTag¶
open override fun getSyncTag(): CompoundTag
Builds a CompoundTag suitable for sending to the client to sync current field values.
intField¶
open fun intField(default: () -> Int = { 0 }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, Int>>
itemField¶
open override fun itemField(
size: Int,
filter: Predicate<ItemResource>,
onUpdate: () -> Unit?
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieItemStorage>>
Declares an ArchieItemStorage field with size slots, keyed by the delegated property's name. onUpdate, if given, runs in addition to (not instead of) this holder's own internal bookkeeping (persistence, @Sync propagation, BlockEntity.setChanged, ...) every time ArchieItemStorage.update fires for this specific field - a caller-supplied "something in this inventory changed" hook, without needing to poll it or re-derive the same notification some other way.
itemListField¶
open override fun itemListField(
size: Int,
filter: Predicate<ItemResource>,
onUpdate: () -> Unit?
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieStorageList<ArchieItemStorage>>>
Declares an ArchieStorageList of ArchieItemStorages, each with size slots, keyed by the delegated property's name. See itemMapField for onUpdate's semantics.
itemMapField¶
open override fun itemMapField(
size: Int,
filter: Predicate<ItemResource>,
onUpdate: () -> Unit?
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ArchieStorageMap<ArchieItemStorage>>>
Declares an ArchieStorageMap of ArchieItemStorages, each with size slots, keyed by the delegated property's name. onUpdate, if given, runs whenever the map's own structure changes (an entry added/removed/cleared) or any individual entry's own contents change - every entry the map creates is wired with the map's own persistence trigger as well, so a mutation deep inside one entry is never silently unpersisted.
listField¶
open override fun <T> listField(serializer: KSerializer<T>, default: () -> List<T>): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, ObservableList<T>>>
Declares a mutable-list field backed by serializer, keyed by the delegated property's name.
Typed as ObservableList rather than plain MutableList so a caller can reach ObservableList.setAll - every ordinary mutator persists the whole list on each call, which a caller rewriting many entries in one pass has no reason to pay for. A property declared as MutableList<T> still binds to this unchanged.
listField¶
inline fun <T> NBTHolder.listField(noinline default: () -> List<T>): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, MutableList<T>>>
Reified variant of NBTHolder.listField that resolves the KSerializer for T automatically.
loadFromTag¶
open override fun loadFromTag(compoundTag: CompoundTag)
Loads every declared field's value from compoundTag, overwriting current values.
longField¶
open fun longField(default: () -> Long = { 0 }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, Long>>
mapField¶
open override fun <T> mapField(serializer: KSerializer<T>, default: () -> Map<String, T>): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, MutableMap<String, T>>>
Declares a mutable-map (keyed by String) field backed by serializer, keyed by the delegated property's name.
mapField¶
inline fun <T> NBTHolder.mapField(noinline default: () -> Map<String, T>): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, MutableMap<String, T>>>
Reified variant of NBTHolder.mapField that resolves the KSerializer for T automatically.
nestedField¶
open override fun <T : NBTHolder> nestedField(factory: (CompoundTag) -> T?): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, NestedNBTHolder<T>>>
Declares a single nested NBTHolder field, keyed by the delegated property's name and built once via factory - the scalar counterpart to nestedMapField/nestedListField. Unlike those, there's exactly one fixed-type entry, so no per-entry type discrimination is needed: factory takes no tag to inspect.
nestedListField¶
open override fun <T : NBTHolder> nestedListField(factory: (CompoundTag) -> T?): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, NestedNBTHolderList<T>>>
Declares a NestedNBTHolderList field, keyed by the delegated property's name - the index-ordered counterpart to nestedMapField; see its KDoc for factory's role and T's.
nestedMapField¶
open override fun <T : NBTHolder> nestedMapField(factory: (CompoundTag) -> T?): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, NestedNBTHolderMap<T>>>
Declares a NestedNBTHolderMap field, keyed by the delegated property's name. Unlike mapField, entries aren't one fixed kotlinx.serialization-compatible value type - each is its own self-contained NBTHolder, built fresh via factory either when first inserted (NestedNBTHolderMap.getOrPut) or, when loading a previously-saved entry back, from that entry's own raw sub-CompoundTag (so factory can inspect it - e.g. a stored "kind" field - to decide which concrete nested holder type to reconstruct). T is factory's return type - the common upper bound every entry shares, letting a caller declare e.g. NestedNBTHolderMap<HookHolderState> instead of always getting back the base NBTHolder type and having to cast every entry manually.
saveToTag¶
open override fun saveToTag(compoundTag: CompoundTag)
Writes every declared field's current value into compoundTag.
shortField¶
open fun shortField(default: () -> Short = { 0 }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, Short>>
stringField¶
open fun stringField(default: () -> String = { "" }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, String>>
ubyteField¶
open fun ubyteField(default: () -> UByte = { 0u }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, UByte>>
uintField¶
open fun uintField(default: () -> UInt = { 0u }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, UInt>>
ulongField¶
open fun ulongField(default: () -> ULong = { 0u }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, ULong>>
updateProperty¶
open override fun <T> updateProperty(
propertyName: String,
serializer: KSerializer<T>,
value: T
)
Updates a single field, identified by propertyName, from a client sync payload.
ushortField¶
open fun ushortField(default: () -> UShort = { 0u }): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, UShort>>