Class Property<T>
java.lang.Object
com.github.darksoulq.abyssallib.world.block.property.Property<T>
- Type Parameters:
T- the type of the value held by this property
A generic container for a block or entity property that supports automatic serialization.
Each property is associated with a Codec to handle the conversion
between the object-oriented value and a serialized format.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<D> DataResult<Void> decode(DynamicOps<D> ops, D input) Decodes a value from a serialized format and updates the property.<D> DataResult<D> encode(DynamicOps<D> ops) Encodes the current value into a serialized format.get()Retrieves the current value of the property.Retrieves the default value defined at creation.voidSets the change listener callback for this property.voidUpdates the current value of the property and triggers the change listener.
-
Constructor Details
-
Property
Constructs a new Property with a codec and an initial value.- Parameters:
codec- the codec for serializationinitialValue- the starting value and default value
-
-
Method Details
-
onChange
Sets the change listener callback for this property.- Parameters:
onChange- the runnable to execute on changes
-
get
Retrieves the current value of the property.- Returns:
- the current value
-
getDefault
Retrieves the default value defined at creation.- Returns:
- the default value
-
set
Updates the current value of the property and triggers the change listener.- Parameters:
value- the new value to set
-
encode
Encodes the current value into a serialized format.- Type Parameters:
D- the data format type- Parameters:
ops- the dynamic operations logic- Returns:
- a DataResult containing the encoded data object
-
decode
Decodes a value from a serialized format and updates the property.- Type Parameters:
D- the data format type- Parameters:
ops- the dynamic operations logicinput- the serialized data object- Returns:
- a DataResult representing the success or partial failure of the operation
-