Data Sync Lib
No reviews yet
Annotation-driven automatic data sync and persistence framework for Minecraft mod development.
Forge is a popular mod loader for versions 1.1+ of Minecraft.
Community voices
Reviews
Click once to include, again to exclude, again to clear
No reviews yet. Be the first to review this project!
Get it on
Available Platforms
About
Project Details
For authors
Embed Badge
If you're the author of this project, you can embed a live badge anywhere that supports HTML or Markdown. It updates automatically whenever ratings change.
Use HTML for any page that supports it, or Markdown for README files and Markdown-based descriptions.
Identifiers
Platform IDs
About
Description
DataSyncLib
Annotation-driven automatic data sync and persistence framework for Minecraft mod development.
๐ Overview
DataSyncLib is a powerful data synchronization library designed for Minecraft mod developers. It eliminates the boilerplate of manual network packet handling and NBT persistence by using declarative Java annotations.
Simply annotate your fields with @SyncToClient, @SyncToServer, or @SaveToDisk, and DataSyncLib automatically handles:
- ๐ Client-server field synchronization โ async-safe, incremental delta sync
- ๐พ Disk persistence โ automatic NBT save/load with change detection
- ๐ก Network transmission โ index-addressed protocol, only changed fields are sent
- ๐ง Custom codecs โ 30+ pre-registered types, extensible via
@Codec
โจ Key Features
| Feature | Description |
|---|---|
| ๐ Bidirectional Sync | @SyncToClient and @SyncToServer handle serverโclient field sync. Fully async-safe. |
| ๐พ Auto Persistence | @SaveToDisk fields are automatically written to and read from NBT. |
| ๐ก Incremental Sync | Built-in dirty flag detection โ only changed fields are transmitted over the network. |
| ๐ง Extensible Codec System | DataSyncCodec registry with 30+ pre-registered types. Register custom codecs via @Codec. |
| ๐ข Change Notification | Per-field listener callbacks + NotifiableHolder system for reactive UI updates. |
| ๐ฆ DataComponent System | Identity-keyed component data model with DataComponentRegistry + DataComponentMap. |
| ๐๏ธ Registry Utility | Generic registry with freeze/unfreeze lifecycle and built-in serialization. |
| โก High Performance | MethodHandle instead of reflection, FastUtil collections, multi-level caching, VarInt encoding. |
| ๐๏ธ Compact Data Format | Custom 19-type binary Data system, more compact than NBT Tag. |
| ๐งฉ Ready to Use | Extend FieldDataHolderBlockEntity โ full capabilities out of the box. |
| ๐ช Nested Holders | @AdditionalHolder recursively discovers annotated fields in nested objects. |
| ๐ฏ Custom Strategies | @Strategy for custom hash/equality change detection on complex types (ItemStack, FluidStack, etc.). |
๐ Quick Start
public class MyBlockEntity extends FieldDataHolderBlockEntity {
@SyncToClient
@SaveToDisk
private int energy = 0;
@SyncToClient(notifyUpdate = true) // Triggers scheduleUpdate on client
private String status = "idle";
@SyncToServer(autoUpdate = false) // Only synced when explicitly marked
private int clientConfig = 0;
public MyBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.MY_BLOCK_ENTITY.get(), pos, state);
}
public void serverTick(ServerLevel level) {
energy++;
setChanged(); // Mark chunk for saving
DataSyncNetwork.syncBlockEntityToClient(this, false, true); // Async-safe
}
@Override
public void scheduleUpdate(LogicalSide side) {
if (side.isClient()) {
// Re-render or refresh UI on client
}
}
}
Nested Holders
public class MachineBlockEntity extends FieldDataHolderBlockEntity {
@AdditionalHolder // Scans InventoryData for annotated fields
private InventoryData inventory = new InventoryData();
@AdditionalHolder
private EnergyData energy = new EnergyData();
}
class InventoryData {
@SaveToDisk @SyncToClient
private int itemCount;
}
class EnergyData {
@SaveToDisk @SyncToClient(condition = "shouldSyncEnergy")
private long storedEnergy;
private boolean shouldSyncEnergy(long value) {
return value > 0; // Skip sync when empty
}
}
Custom Codec
// 1. Define codec โ FieldDataManager auto-discovers @SaveToDisk fields on the POJO
private static final FieldDataCodec<MyConfig> CONFIG_CODEC =
FieldDataManager.createCodec(MyConfig.class, MyConfig::new);
// 2. Reference on the field
@SaveToDisk @SyncToClient
@Codec(saveCodec = "CONFIG_CODEC", syncCodec = "CONFIG_CODEC")
private MyConfig config = new MyConfig();
Entity Sync
public class MyEntity extends Entity implements IFieldDataHolder {
private final LazyFieldDataManager fieldDataManager = new LazyFieldDataManager(this);
@SyncToClient
private int state = 0;
@Override
public FieldDataManager getFieldDataManager() {
return fieldDataManager.get();
}
@Override
public void tick() {
if (!level().isClientSide()) {
state = calculateState();
DataSyncNetwork.syncEntityToClient(this);
}
}
}
๐ Annotation Reference
| Annotation | Purpose | Key Attributes |
|---|---|---|
@SyncToClient |
ServerโClient sync | autoUpdate, notifyUpdate, condition, listener |
@SyncToServer |
ClientโServer sync | autoUpdate, notifyUpdate, condition, listener |
@SaveToDisk |
Disk persistence | key, condition, saveNull, defaultValue, defaultValueGetter |
@Access |
Force access-mode for containers | createInstance |
@AdditionalHolder |
Recursively scan nested object fields | โ |
@Codec |
Custom serialization | saveCodec / syncCodec / writeToData / readFromData |
@Strategy |
Custom change detection strategy | value (static field name) |
@Generic |
Force generic-type factory resolution | โ |
@AddToManager |
Add to manager without auto sync/persist | โ |
๐ฆ Installation
Prerequisites
- Java 21
For Developers
repositories {
maven {
url = "https://maven.gtodyssey.com/releases"
}
}
dependencies {
implementation fg.deobf("com.gto:datasynclib-forge-1.20.1:26.7.4")
}
๐ Full Documentation
Detailed documentation with architecture diagrams, data flow charts, API reference, and advanced usage guides:
- English Documentation โ Open in browser for best experience
- ไธญๆๆๆกฃ โ ไธญๆๅฎๆดๆๆกฃ
๐๏ธ Architecture
Annotations โ FieldDefinitionStorage โ DataFieldDefinition[]
โ
IFieldDataHolder โ LazyFieldDataManager โ FieldDataManager โ DataField[]
(DCL lazy init) (per-instance) (AbstractField / AbstractFieldAccess)
| Component | Role |
|---|---|
| FieldDefinitionStorage | Global cache โ scans class hierarchy for annotated fields |
| FieldDataManager | Per-instance lifecycle manager โ field discovery, change detection, serialization |
| DataField hierarchy | AbstractField (primitive values), ObjField (objects with codecs), AbstractFieldAccess (collections/maps/arrays) |
| DataSyncCodec | Unified codec registry pairing ByteStreamCodec (network) with DataCodec (persistence) |
| Data type system | 19-type sealed binary format, more compact than NBT, with VarInt encoding |
๐ก Inspiration
This project draws inspiration from LDLib's syncdata package by Low-Drag-MC, a powerful multi-loader library for Minecraft mod development.
๐ License
This project is licensed under the GNU LGPL 3.0 โ you are free to use, modify, and distribute this library in your own mods.
Screenshots
Gallery
Versions
Files
Relations
Project Relations
More like this
Similar Mods
Suggestions use data such as tags, dependencies, dependents, descriptions, titles, and more to rank how much they overlap with this mod.
On ModDex
Community snapshot
By the numbers
Statistics
Want to reach Minecraft players?
We're looking for a server hosting partner to feature here and other parts of the site. Interested? Send us a message!
Get in touchGet it on
Available Platforms
On ModDex
Community snapshot
By the numbers