Skip to content

Data Pipeline

Aram edited this page Sep 11, 2025 · 1 revision

Overview

This section provides a view of the integrated BlueLib cache system, combining JSON deserialization, CODECs, CompoundTags, and DataComponentTypes for a robust preset storage and loading system.

The system allows you to:

  • Easily define caches for different types.
  • Serialize/deserialize them via JSON, NBT, or dynamic formats.
  • Attach them to objects like ItemStack or entities.
  • Reuse patterns across multiple types without duplicating code.

Supported Preset Caches

The following caches are included and fully integrated:

  • IntRange – Stores integer ranges.
  • FloatRange – Stores float ranges.
  • DoubleRange – Stores double ranges.
  • LongRange – Stores long ranges.
  • ShortRange – Stores short ranges.
  • ByteRange – Stores byte ranges.
  • BlockPos – Supports conversion between BlockPosCache and BlockPos.
  • Vector2 (Float) – Supports conversion between Vector2Cache and Vector2f.
  • Vector3 (Float) – Supports conversion between Vector3Cache and Vector3f.
  • RGBAColor – Supports conversion between RGBAColorCache and a color object.
  • RGBColor – Supports conversion between RGBColorCache and a color object.

How Everything Fits Together

  1. JSON Deserializers

    • Each cache has a custom deserializer to read JSON into the cache object.
    • Ensures validation, default values, and consistent parsing across all cache types.
  2. CODECs

    • Each cache has a dedicated CODEC, bridging the cache with Dynamic and CompoundTag.
    • Handles automatic serialization/deserialization for Minecraft systems.
  3. CompoundTags

    • writeToNBT and readFromNBT methods provide the foundation for persistent storage.
    • Ensures all cache objects can save/load to/from NBT.
  4. DataComponentTypes

    • Each cache has its own DataComponentType, registered for global access.
    • Allows attaching caches to ItemStack, entities, and other objects directly.
    • Uses the CODEC for persistence automatically.

Example Workflow

Here is a typical workflow for a cache object:

JSON → Cache → CODEC → CompoundTag → DataComponentType → Object

And in code:

ExampleCache cache = GsonFactory.INSTANCE.fromJson(jsonString, ExampleCache.class);

Dynamic<?> dynamic = new Dynamic<>(NbtOps.INSTANCE, new CompoundTag());
ExampleCache fromCodec = ExampleCache.CODEC.parse(dynamic).getOrThrow(false, System.err::println);

ItemStack stack = new ItemStack(Items.DIAMOND);
stack.set(ExampleCache.EXAMPLE_CACHE_TYPE, cache);

ExampleCache stored = stack.get(ExampleCache.EXAMPLE_CACHE_TYPE);

Key Benefits

  • Consistency – All caches use the same pattern for deserialization, storage, and attachment.
  • Reusability – Add new cache types with minimal boilerplate.
  • Persistence – DataComponentTypes and CODECs ensure caches are saved automatically.
  • Integration – Works seamlessly with Minecraft’s NBT system, Dynamic, and Gson.

Summary

By integrating JSON deserializers, CODECs, CompoundTags, and DataComponentTypes, BlueLib provides a complete caching system for presets. This setup simplifies saving, loading, and attaching cache objects for mods and other systems, while maintaining type safety, consistency, and extensibility.

Clone this wiki locally