Contents
Interface AssetPackUtil
public interface AssetPackUtil
-
Field Summary
Fields -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic <T extends JsonAssetWithMap<String,M>, M extends AssetMap<String, T>>
voidexportAsset(AssetPack pack, String name, org.bson.BsonDocument asset, Class<T> type) Exports the specified asset into the given asset pack.static CompletableFuture<AssetPack> getOrCreatePack(String group, String name) Retrieves an existingAssetPackinstance or creates a new one if it does not exist.static PathgetStorePath(Path root, String type, AssetStore<?, ?, ?> store) Resolves and constructs a store path based on the specified root path, type, and asset store.
-
Field Details
-
ASSET_STORE_TYPE
- See Also:
-
INSTANCES_PATH
- See Also:
-
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 existingAssetPackinstance or creates a new one if it does not exist. The asset pack is identified by the combination of the providedgroupandname. 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 nullname- the name of the asset pack. Must not be null- Returns:
- a
CompletableFuturethat completes with theAssetPackinstance if retrieval or creation succeeds, or exceptionally with anIOExceptionif the resolved pack path is not inside the mods directory
-
exportAsset
static <T extends JsonAssetWithMap<String,M>, M extends AssetMap<String, void exportAssetT>> (@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 registeredAssetStorefor 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 extendsJsonAssetWithMap<String, M>.M- the type of the asset map associated with the base asset.- Parameters:
pack- theAssetPackinstance 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 appropriateAssetStore. 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 noAssetStoreis 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
Pathobject.
-