Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Asset manager

Mark Vainomaa edited this page Jan 13, 2020 · 4 revisions

Asset manager

As all mods are loaded to singe classloader, then it means that resources cannot have same name. To "workaround" that issue, an asset manager was created to make things prettier.

Adding assets to own mod

You must add assets to /assets/<your mod id>/ in jar, e.g resources directory in your IDE should look like this:

Then you can access it using injected AssetManager instance.

Using asset manager

In mod class:

@Inject
private AssetManager assetManager;

@Inject
@Named("configurationPath")
private Path configurationPath;

assetManager.copyAsset(configurationPath, "config.cfg");

To get other mods' assets:

@Inject
private Orion orion;

ModInfo fooMod = orion.getMod("foo");
AssetManager fooAssetManager = orion.getAssetManager().forMod(fooMod);

InputStream configStream;
if ((configStream = fooAssetManager.getAsset("config.cfg")) == null) {
    throw new IllegalStateException("Could not get asset 'config.cfg' from mod 'foo'!");
}
Clone this wiki locally