Data Synchronization Module >=26.1
The package dev.anvilcraft.lib.v2.sync provides a declarative field synchronization system that automatically synchronizes Java object field values between client and server using the @Sync annotation and SyncProxy<T> proxies. It supports directional control, dimension-aware distribution, and bytecode injection that auto-associates proxies with parent objects, field names, and directions — completely transparent to users.
Availability
This module is only available in Minecraft 26.1.
Architecture Overview
- Annotation Layer —
@Syncmarks synchronizable classes, specifying the sync direction - Proxy Layer —
SyncProxy<T>wraps field values, providing automatic codec and change notification - Management Layer —
SyncManagermaintains the registry and coordinates data transmission - Network Layer —
SyncPayloadtransmits data between both sides viaIInsensitiveBiPacket - Injection Layer —
SyncBytecodeInjectorauto-associates proxies with their parent objects, field names, and directions via bytecode injection — completely transparent to users - Configuration Layer —
SyncConfigManagerassigns unique IDs to sync fields, compressing field names to integers during network transmission viaSyncConfigurationPayload
Document Index
| Document | Contents |
|---|---|
| Core API | @Sync annotation, SyncProxy, SyncDirection, SyncManager, SyncRegisterEntry |
| Usage Guide | Complete usage examples, bytecode injection, registration flow |
Quick Start
java
// 1. Mark a class as synchronizable
@Sync(SyncDirection.BOTH)
public class MySyncObject {
public final SyncProxy<Integer> counter = new SyncProxy<>(0);
public final SyncProxy<String> name = new SyncProxy<>("");
}
// 2. Use
MySyncObject obj = new MySyncObject();
obj.counter.setValue(42); // Automatically syncs to the other side
int val = obj.counter.getValue(); // Get current valueDependency Management
groovy
dependencies {
implementation "dev.anvilcraft.lib:anvillib-sync-neoforge-26.1:2.0.0"
}Notes
SyncProxyfields must be declaredpublic final- 18 built-in types have default StreamCodec support (CompoundTag, String, Integer, Vector3fc, etc.)
- Custom types require specifying a codec via
SyncProxy(value, customCodec) - Sync direction is controlled at runtime by
SyncDirection:BOTH/C2S/S2C