Class AbstractPropertyEntity<T>

java.lang.Object
com.github.darksoulq.abyssallib.world.entity.AbstractPropertyEntity<T>
Type Parameters:
T - the type of the parent/owner of this entity (e.g., CustomBlock)
Direct Known Subclasses:
BlockEntity

public abstract class AbstractPropertyEntity<T> extends Object
A base class for entities that utilize the property-based serialization system.

This class uses reflection to automatically discover Property fields and handle their persistence. Subclasses can define properties as fields, and they will be automatically saved to and loaded from the world data.

  • Constructor Details

    • AbstractPropertyEntity

      public AbstractPropertyEntity(T type)
      Constructs a new AbstractPropertyEntity.
      Parameters:
      type - the associated type or owner
  • Method Details

    • getType

      public T getType()
      Gets the associated type or owner of this entity.
      Returns:
      the owner instance
    • onLoad

      public void onLoad()
      Called when the entity is loaded into the world.
    • onSave

      public void onSave()
      Called before the entity is saved to the world data.
    • serialize

      public <D> DataResult<D> serialize(DynamicOps<D> ops)
      Serializes all discovered properties into a dynamic map.

      This method iterates through all declared fields in the class and its superclasses (up to AbstractPropertyEntity), identifying Property instances and encoding them.

      Type Parameters:
      D - the data format type
      Parameters:
      ops - the dynamic operations logic
      Returns:
      a DataResult containing the serialized map of property names to values
    • deserialize

      public <D> DataResult<Void> deserialize(DynamicOps<D> ops, D input)
      Deserializes properties from a dynamic map into this instance.

      Matches keys in the serialized map to field names in the class hierarchy that are instances of Property.

      Type Parameters:
      D - the data format type
      Parameters:
      ops - the dynamic operations logic
      input - the serialized map data
      Returns:
      a DataResult representing the success or partial failure of the decoding process