Class SyncedAutoSaveData<T>
java.lang.Object
dev.scsupercraft.mc.libraries.corelib.api.data.SaveData<T>
dev.scsupercraft.mc.libraries.corelib.api.data.AutoSaveData<T>
dev.scsupercraft.mc.libraries.corelib.api.data.SyncedAutoSaveData<T>
- Type Parameters:
T- The type of the data being saved.
- All Implemented Interfaces:
Data<T>,SyncedData<T>
@AvailableSince("1.0.0")
public final class SyncedAutoSaveData<T>
extends AutoSaveData<T>
implements SyncedData<T>
A helper class for save data.
Automatically saves and loads data.
Additionally, this class automatically syncs data to client using the utility class,
Synchronisation.-
Nested Class Summary
Nested classes/interfaces inherited from class dev.scsupercraft.mc.libraries.corelib.api.data.SaveData
SaveData.Type -
Constructor Summary
ConstructorsConstructorDescriptionSyncedAutoSaveData(Supplier<@NotNull T> defaultValue, CodecHolder<T> codecHolder, Supplier<File> fileGetter, SaveData.Type type, net.minecraft.util.Identifier id) Creates new synced auto save data. -
Method Summary
Modifier and TypeMethodDescriptionGet the data synced over from the server.net.minecraft.util.IdentifierUsed to get the id of this object.voidTell the savable that it was updated.voidsetSyncedData(T syncedData) Set the data synced from the server.Methods inherited from class dev.scsupercraft.mc.libraries.corelib.api.data.SaveData
getCodecHolder, getData, load, save, setDataMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.scsupercraft.mc.libraries.corelib.api.data.Data
getData, setDataMethods inherited from interface dev.scsupercraft.mc.libraries.corelib.api.data.SyncedData
sync, sync
-
Constructor Details
-
SyncedAutoSaveData
@AvailableSince("1.0.0") public SyncedAutoSaveData(Supplier<@NotNull T> defaultValue, CodecHolder<T> codecHolder, Supplier<File> fileGetter, SaveData.Type type, net.minecraft.util.Identifier id) Creates new synced auto save data.- Parameters:
defaultValue- A supplier that returns the default value for this savable. Used if there isn't any existing data during loading.codecHolder- A codec holder for serializing the save data.fileGetter- A supplier that returns the file that the data will be saved to.type- What should the data be saved as.id- The id of this synced object. Used to find the synced object on the client.
-
-
Method Details
-
markDirty
public void markDirty()Description copied from class:SaveDataTell the savable that it was updated. Failing to call this method after an update will result in the data not getting saved.- Overrides:
markDirtyin classAutoSaveData<T>
-
getSyncedData
Description copied from interface:SyncedDataGet the data synced over from the server.- Specified by:
getSyncedDatain interfaceSyncedData<T>- Returns:
- The synced data.
-
setSyncedData
Description copied from interface:SyncedDataSet the data synced from the server. Please don't use this, it should only be called by CoreLib during data synchronisation.- Specified by:
setSyncedDatain interfaceSyncedData<T>- Parameters:
syncedData- The new data
-
getSyncId
public net.minecraft.util.Identifier getSyncId()Description copied from interface:SyncedDataUsed to get the id of this object.- Specified by:
getSyncIdin interfaceSyncedData<T>- Returns:
- The object's id.
-