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 Summary

    Constructors
    Constructor
    Description
    Constructs a new AbstractPropertyEntity.
  • Method Summary

    Modifier and Type
    Method
    Description
    <D> void
    deserialize(DynamicOps<D> ops, D input)
    Deserializes properties from a dynamic map into this instance.
    Gets the associated type or owner of this entity.
    void
    Called when the entity is loaded into the world.
    void
    Called before the entity is saved to the world data.
    <D> D
    Serializes all discovered properties into a dynamic map.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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> D serialize(DynamicOps<D> ops) throws Exception
      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 serialized map of property names to values
      Throws:
      Exception - if reflection or encoding fails
    • deserialize

      public <D> void deserialize(DynamicOps<D> ops, D input) throws Exception
      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
      Throws:
      Exception - if reflection or decoding fails