Class MinecraftBlockSerializer
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic <D> voiddeserialize(org.bukkit.block.data.BlockData data, Map<D, D> map, DynamicOps<D> ops) Applies serialized block state data onto an existingBlockDatainstance.static <D> voiddeserializeTile(org.bukkit.block.BlockState state, Map<D, D> data, DynamicOps<D> ops) Restores tile entity data onto aBlockStatefrom a serialized map.static <D> Map<D, D> serialize(org.bukkit.block.data.BlockData data, DynamicOps<D> ops) Serializes aBlockDatainstance into a generic key-value map using the providedDynamicOpsformat.static <D> Map<D, D> serializeTile(org.bukkit.block.BlockState state, DynamicOps<D> ops) Serializes tile entity data (block entity / NBT-like metadata) from aBlockState.
-
Constructor Details
-
MinecraftBlockSerializer
public MinecraftBlockSerializer()
-
-
Method Details
-
serialize
Serializes aBlockDatainstance into a generic key-value map using the providedDynamicOpsformat.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 theDynamicOpsinstance.- Parameters:
data- TheBlockDatainstance to serialize. Must not be null.ops- TheDynamicOpsimplementation 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 existingBlockDatainstance.This method mutates the provided
dataobject by applying all properties found in the given map. Any missing properties are left unchanged.- Type Parameters:
D- The generic data type used by theDynamicOpsinstance.- Parameters:
data- The targetBlockDatainstance to modify. Must not be null.map- The serialized property map previously produced byserialize(BlockData, DynamicOps). May be null or empty, in which case no changes are applied.ops- TheDynamicOpsinstance used to interpret the map values.
-
serializeTile
Serializes tile entity data (block entity / NBT-like metadata) from aBlockState.This method only operates on instances of
TileState. If the provided state is not a tile entity, this method returnsnull.Examples of supported tile states include:
- Chests
- Furnaces
- Signs
- Containers with persistent metadata
- Type Parameters:
D- The generic data type used by theDynamicOpsinstance.- Parameters:
state- TheBlockStateto extract tile data from.ops- TheDynamicOpsimplementation defining the output format.- Returns:
- A map containing serialized tile data, or
nullif:- The state is not a
TileState - The tile contains no serializable data
- The state is not a
-
deserializeTile
public static <D> void deserializeTile(org.bukkit.block.BlockState state, Map<D, D> data, DynamicOps<D> ops) Restores tile entity data onto aBlockStatefrom a serialized map.This method only applies to
TileStateinstances. 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 theDynamicOpsinstance.- Parameters:
state- The targetBlockStateto apply tile data to.data- The serialized tile data map. May be null or empty, in which case no changes are applied.ops- TheDynamicOpsinstance used to interpret the serialized values.
-