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

public class Property<T> extends Object
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
    Constructor
    Description
    Property(Codec<T> codec, T initialValue)
    Constructs a new Property with a codec and an initial value.
  • Method Summary

    Modifier and Type
    Method
    Description
    <D> void
    decode(DynamicOps<D> ops, D input)
    Decodes a value from a serialized format and updates the property.
    <D> D
    Encodes the current value into a serialized format.
    get()
    Retrieves the current value of the property.
    Retrieves the default value defined at creation.
    void
    set(T value)
    Updates the current value of the property.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Property

      public Property(Codec<T> codec, T initialValue)
      Constructs a new Property with a codec and an initial value.
      Parameters:
      codec - the codec for serialization
      initialValue - the starting value and default value
  • Method Details

    • get

      public T get()
      Retrieves the current value of the property.
      Returns:
      the current value
    • getDefault

      public T getDefault()
      Retrieves the default value defined at creation.
      Returns:
      the default value
    • set

      public void set(T value)
      Updates the current value of the property.
      Parameters:
      value - the new value to set
    • encode

      public <D> D encode(DynamicOps<D> ops) throws Codec.CodecException
      Encodes the current value into a serialized format.
      Type Parameters:
      D - the data format type
      Parameters:
      ops - the dynamic operations logic
      Returns:
      the encoded data object
      Throws:
      Codec.CodecException - if serialization fails
    • decode

      public <D> void decode(DynamicOps<D> ops, D input) throws Codec.CodecException
      Decodes a value from a serialized format and updates the property.
      Type Parameters:
      D - the data format type
      Parameters:
      ops - the dynamic operations logic
      input - the serialized data object
      Throws:
      Codec.CodecException - if deserialization fails