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
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 -
Method Summary
Modifier and TypeMethodDescription<D> voiddeserialize(DynamicOps<D> ops, D input) Deserializes properties from a dynamic map into this instance.getType()Gets the associated type or owner of this entity.voidonLoad()Called when the entity is loaded into the world.voidonSave()Called before the entity is saved to the world data.voidCalled during a random world tick.<D> Dserialize(DynamicOps<D> ops) Serializes all discovered properties into a dynamic map.voidCalled every server tick.
-
Constructor Details
-
AbstractPropertyEntity
Constructs a new AbstractPropertyEntity.- Parameters:
type- the associated type or owner
-
-
Method Details
-
getType
-
serverTick
public void serverTick()Called every server tick. Override to provide active logic. -
randomTick
public void randomTick()Called during a random world tick. -
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
Serializes all discovered properties into a dynamic map.This method iterates through all declared fields in the class and its superclasses (up to
AbstractPropertyEntity), identifyingPropertyinstances 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
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 logicinput- the serialized map data- Throws:
Exception- if reflection or decoding fails
-