Class SyncedWorldSaveData<T>
java.lang.Object
dev.scsupercraft.mc.libraries.corelib.api.data.SaveData<T>
dev.scsupercraft.mc.libraries.corelib.api.data.WorldSaveData<T>
dev.scsupercraft.mc.libraries.corelib.api.data.SyncedWorldSaveData<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 SyncedWorldSaveData<T>
extends WorldSaveData<T>
implements SyncedData<T>
A helper class for save data.
Automatically saves and loads data on server start and stop.
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
ConstructorsConstructorDescriptionSyncedWorldSaveData(Supplier<@NotNull T> defaultValue, CodecHolder<T> codecHolder, Function<net.minecraft.server.MinecraftServer, File> fileGetter, SaveData.Type type, net.minecraft.util.Identifier id) Creates new synced world 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.WorldSaveData
isLoadedMethods 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
-
SyncedWorldSaveData
@AvailableSince("1.0.0") public SyncedWorldSaveData(Supplier<@NotNull T> defaultValue, CodecHolder<T> codecHolder, Function<net.minecraft.server.MinecraftServer, File> fileGetter, SaveData.Type type, net.minecraft.util.Identifier id) Creates new synced world 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 function that accepts the current server and 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. -
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.
-