Migrating from LDLib SyncData
Simple example
This simple example covers the majority of use cases when adding sync/save fields to a standard machine, machine trait or cover.
With LDLib:
class CustomMachine extends SimpleTieredMachine {
protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(CustomMachine.class,
SimpleTieredMachine.MANAGED_FIELD_HOLDER);
@Override
public ManagedFieldHolder getFieldHolder() {
return MANAGED_FIELD_HOLDER;
}
@Getter
@Persisted
@DescSynced
@RequireRerender
protected int customIntValue;
@Persisted(key = "customNBTKey")
protected String customStringValue;
public void setCustomIntValue(int newValue) {
this.customIntValue = newValue;
}
}
New System:
class CustomMachine extends SimpleTieredMachine {
@Getter
@SaveField
@SyncToClient
protected int customIntValue;
@SaveField(nbtKey = "customNBTKey")
protected String customStringValue;
public void setCustomIntValue(int newValue) {
this.customIntValue = newValue;
////// IMPORTANT: markClientSyncFieldDirty must be called to update client synced fields.
getSyncDataHolder().markClientSyncFieldDirty("customIntValue");
}
}
General migration guidelines
- Remove all
ManagedFieldHolderfields. - Replace
FieldManagedStoragefields withSyncDataHolderfields. - Replace
IEnhancedManagedobjects withISyncManaged. - Replace
IAsyncAutoSyncBlockEntity,IAutoPersistBlockEntity,IAutoSyncBlockEntityandIManagedBlockEntityby extendingManagedSyncBlockEntity.
Annotations
Warning
Client sync fields do not automatically detect changes. When changing a client sync field, call ISyncManaged.syncDataHolder.markClientSyncFieldDirty(FIELD_NAME)
@DescSynced->@SyncToClient@RequireRerender->@RerenderOnChanged@Persisted->@SaveField@UpdateListener->@ClientFieldChangeListeneron listener method.@DropSaved- Removed, make machines implementIDropSaveMachineinstead@ReadOnlyManagedand@LazyManagedSee usage docs for instructions on complex sync objects
Other changes
saveCustomPersistedData&loadCustomPersistedDatamethods, and serialization of custom data types - SeeValueTransformer<T>andValueTransformersclasses.