Class 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.
  • 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: SaveData
      Tell the savable that it was updated. Failing to call this method after an update will result in the data not getting saved.
      Overrides:
      markDirty in class SaveData<T>
    • getSyncedData

      public T getSyncedData()
      Description copied from interface: SyncedData
      Get the data synced over from the server.
      Specified by:
      getSyncedData in interface SyncedData<T>
      Returns:
      The synced data.
    • setSyncedData

      public void setSyncedData(T syncedData)
      Description copied from interface: SyncedData
      Set the data synced from the server. Please don't use this, it should only be called by CoreLib during data synchronisation.
      Specified by:
      setSyncedData in interface SyncedData<T>
      Parameters:
      syncedData - The new data
    • getSyncId

      public net.minecraft.util.Identifier getSyncId()
      Description copied from interface: SyncedData
      Used to get the id of this object.
      Specified by:
      getSyncId in interface SyncedData<T>
      Returns:
      The object's id.