Class MinecraftBlockSerializer

java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.MinecraftBlockSerializer

public class MinecraftBlockSerializer extends Object
Provides a complete utility layer for serializing and deserializing native Bukkit BlockData and TileState instances into generic data representations via DynamicOps.

This class acts as a low-level bridge between Minecraft's internal block state system and AbyssalLib's abstract serialization framework, enabling:

  • Conversion of block states into generic map-based formats
  • Reconstruction of block states from serialized data
  • Extraction and restoration of tile entity (NBT-like) metadata

All operations are stateless and thread-safe provided the underlying DynamicOps implementation is thread-safe.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <D> void
    deserialize(org.bukkit.block.data.BlockData data, Map<D,D> map, DynamicOps<D> ops)
    Applies serialized block state data onto an existing BlockData instance.
    static <D> void
    deserializeTile(org.bukkit.block.BlockState state, Map<D,D> data, DynamicOps<D> ops)
    Restores tile entity data onto a BlockState from a serialized map.
    static <D> Map<D,D>
    serialize(org.bukkit.block.data.BlockData data, DynamicOps<D> ops)
    Serializes a BlockData instance into a generic key-value map using the provided DynamicOps format.
    static <D> Map<D,D>
    serializeTile(org.bukkit.block.BlockState state, DynamicOps<D> ops)
    Serializes tile entity data (block entity / NBT-like metadata) from a BlockState.

    Methods inherited from class Object

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

    • MinecraftBlockSerializer

      public MinecraftBlockSerializer()
  • Method Details

    • serialize

      public static <D> Map<D,D> serialize(org.bukkit.block.data.BlockData data, DynamicOps<D> ops)
      Serializes a BlockData instance into a generic key-value map using the provided DynamicOps format.

      This includes all block state properties such as:

      • Facing direction
      • Power levels
      • Waterlogged state
      • Any other block-specific properties
      Type Parameters:
      D - The generic data type used by the DynamicOps instance.
      Parameters:
      data - The BlockData instance to serialize. Must not be null.
      ops - The DynamicOps implementation defining the output format (e.g., JSON, NBT-like structures).
      Returns:
      A map representing the serialized block state. Never null, but may be empty if the block has no configurable properties.
    • deserialize

      public static <D> void deserialize(org.bukkit.block.data.BlockData data, Map<D,D> map, DynamicOps<D> ops)
      Applies serialized block state data onto an existing BlockData instance.

      This method mutates the provided data object by applying all properties found in the given map. Any missing properties are left unchanged.

      Type Parameters:
      D - The generic data type used by the DynamicOps instance.
      Parameters:
      data - The target BlockData instance to modify. Must not be null.
      map - The serialized property map previously produced by serialize(BlockData, DynamicOps). May be null or empty, in which case no changes are applied.
      ops - The DynamicOps instance used to interpret the map values.
    • serializeTile

      public static <D> Map<D,D> serializeTile(org.bukkit.block.BlockState state, DynamicOps<D> ops)
      Serializes tile entity data (block entity / NBT-like metadata) from a BlockState.

      This method only operates on instances of TileState. If the provided state is not a tile entity, this method returns null.

      Examples of supported tile states include:

      • Chests
      • Furnaces
      • Signs
      • Containers with persistent metadata
      Type Parameters:
      D - The generic data type used by the DynamicOps instance.
      Parameters:
      state - The BlockState to extract tile data from.
      ops - The DynamicOps implementation defining the output format.
      Returns:
      A map containing serialized tile data, or null if:
      • The state is not a TileState
      • The tile contains no serializable data
    • deserializeTile

      public static <D> void deserializeTile(org.bukkit.block.BlockState state, Map<D,D> data, DynamicOps<D> ops)
      Restores tile entity data onto a BlockState from a serialized map.

      This method only applies to TileState instances. If the provided state is not a tile entity, the method safely exits without performing any action.

      The provided data should originate from serializeTile(BlockState, DynamicOps) to ensure compatibility.

      Type Parameters:
      D - The generic data type used by the DynamicOps instance.
      Parameters:
      state - The target BlockState to apply tile data to.
      data - The serialized tile data map. May be null or empty, in which case no changes are applied.
      ops - The DynamicOps instance used to interpret the serialized values.