Annotation Interface PersistentNbt
Annotation marking fields for automatic NBT serialization/deserialization processing.
Fields annotated with @PersistentNbt participate in reflection-based NBT conversion
through NbtUtils. Supports both default reflection-based handling and custom
serialization logic via INbtAdapter implementations.
Key Characteristics:
- Runtime retention for reflection access
- Field-only targeting (other element types ignored)
- Thread-safe when used with properly synchronized
NbtUtilsmethods
Example:
@PersistentNbt
private int fuelLevel; // Auto-serialized using GenericNbtAdapter
@PersistentNbt(adapter = BlockPosAdapter.class)
private BlockPos cachedPosition; // Custom serialization
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<? extends INbtAdapter> Specifies a custom serialization strategy for the annotated field.
-
Element Details
-
adapter
Class<? extends INbtAdapter> adapterSpecifies a custom serialization strategy for the annotated field.Defaults to
GenericNbtAdapterwhich uses reflection-based serialization for common Java types. Use custom adapters for:- Legacy data format compatibility
- Optimized handling of complex data structures
- Types lacking default constructors
- Third-party classes without source access
Implementation Note: The adapter must declare a compatible target type through
INbtAdapter.getTargetType()matching the field's declared type.Example:
// Custom adapter for inventory serialization @PersistentNbt(adapter = CompactInventoryAdapter.class) private InventorySection warehouseInventory;- Default:
net.xun.lib.common.api.nbt.adapters.GenericNbtAdapter.class
-