Interface AssetPackUtil


public interface AssetPackUtil
  • Field Details

    • ASSET_STORE_TYPE

      static final String ASSET_STORE_TYPE
      See Also:
    • INSTANCES_PATH

      static final String INSTANCES_PATH
      See Also:
    • DEFAULT_VERSION

      static final Semver DEFAULT_VERSION
    • JSON_SETTINGS

      static final org.bson.json.JsonWriterSettings JSON_SETTINGS
  • Method Details

    • getOrCreatePack

      @Nonnull static CompletableFuture<AssetPack> getOrCreatePack(@Nonnull String group, @Nonnull String name)
      Retrieves an existing AssetPack instance or creates a new one if it does not exist. The asset pack is identified by the combination of the provided group and name. If the asset pack does not exist, it is created along with an associated manifest file.
      Parameters:
      group - the group identifier for the asset pack. Must not be null
      name - the name of the asset pack. Must not be null
      Returns:
      a CompletableFuture that completes with the AssetPack instance if retrieval or creation succeeds, or exceptionally with an IOException if the resolved pack path is not inside the mods directory
    • exportAsset

      static <T extends JsonAssetWithMap<String,M>, M extends AssetMap<String,T>> void exportAsset(@Nonnull AssetPack pack, @Nonnull String name, @Nonnull org.bson.BsonDocument asset, @Nonnull Class<T> type) throws IOException
      Exports the specified asset into the given asset pack. The asset is written to disk using the registered AssetStore for the asset type. The method ensures that the directory structure for the asset path exists before writing. If the resolved filepath of the given asset already exists on disk, no write occurs to prevent overwriting the existing file.
      Type Parameters:
      T - the type of the base asset, which extends JsonAssetWithMap<String, M>.
      M - the type of the asset map associated with the base asset.
      Parameters:
      pack - the AssetPack instance into which the asset will be exported. Must not be null. The asset pack must not be immutable.
      name - the name of the asset. This is used as the filename when exporting the asset. Must not be null.
      asset - the BSON representation of the asset to be exported. Must not be null.
      type - the class type of the base asset. This is used to locate the appropriate AssetStore. Must not be null.
      Throws:
      IOException - if the asset pack is immutable, or if there is an error during file creation or writing.
      IllegalArgumentException - if no AssetStore is found for the provided asset type.
    • getStorePath

      static Path getStorePath(@Nonnull Path root, @Nonnull String type, @Nonnull AssetStore<?,?,?> store)
      Resolves and constructs a store path based on the specified root path, type, and asset store. The method replaces filesystem-specific path separators in the asset store's path to ensure compatibility with the provided file system.
      Parameters:
      root - the base root path to resolve the store path. Must not be null.
      type - the type of the asset store, used as a subdirectory under the root path. Must not be null.
      store - the asset store instance containing the path to be resolved. Must not be null.
      Returns:
      the fully resolved store path as a Path object.