| title | Annotations |
|---|
The following annotations define the sync/save behaviour for an ISyncManaged object.
The @SaveField annotation defines a field that should be saved to the server. nbtKey is optional, the key will default to the field name.
@SaveField(nbtKey="nbtKeyToSaveTo")
public int mySaveInt = 10;The @SyncToClient annotation defines a field with a value that should be synced to clients.
!!! warning
Client sync fields do not automatically detect changes. When changing a client sync field, call ISyncManaged.getSyncDataHolder().markClientSyncFieldDirty(FIELD_NAME)
@SaveField(nbtKey="nbtKeyToSaveTo")
@SyncToClient
public int mySaveAndSyncInt = 10;
@SyncToClient
@RerenderOnChanged
public long mySyncRerenderLong = 10000L;
public void serverTick() {
int newIntValue = getNewIntValue();
long newLongValue = getNewLongValue();
if (mySaveAndSyncInt != newIntValue) {
mySaveAndSyncInt = newIntValue;
getSyncDataHolder().markClientSyncFieldDirty("mySaveAndSyncInt");
}
if (mySyncRerenderLong != newLongValue) {
mySyncRerenderLong = newLongValue;
getSyncDataHolder().markClientSyncFieldDirty("mySyncRerenderLong");
}
}The @ClientFieldChangeListener annotation defines a method to be called on the client when a client sync field has changed value;
Annotating a @SyncToClient field with @RerenderOnChanged will cause clients to rerender the block entity when this field changes.
@SyncToClient
@SaveField
@RerenderOnChanged
public boolean isWorkingEnabled = true;
@ClientFieldChangeListener(fieldName="isWorkingEnabled")
public void isWorkingChanged() {
setRenderState(getRenderState().setValue(GTMachineModelProperties.IS_WORKING_ENABLED, isWorkingEnabled));
}The @SaveToItemStack annotation defines a field on a BlockEntity that should be saved when the block is broken or cloned.
The annotation has two parameters, saveToDroppedStack and saveToPickedStack, which both default to true.