Events/Launch/minified-launch

DownloadAssetsEvent

Gets fired every time a new asset file has been downloaded

Fields

progressdouble

The overall download progress as a value from 0.0 to 1.0

Accessor: progress()
downloadedByteslong

The total number of bytes downloaded so far

Accessor: downloadedBytes()
totalByteslong

The total size of all assets in bytes

Accessor: totalBytes()
currentFileString

The name or path of the asset currently being downloaded

Accessor: currentFile()
currentFileByteslong

The number of bytes downloaded for the current file

Accessor: currentFileBytes()
currentFileSizelong

The total size of the current file in bytes

Accessor: currentFileSize()

When it fires

AssetDownloader downloads assets across a worker pool sized by LaunchConfiguration.downloadThreads (5 by default), so this event fires concurrently from multiple threads - one post per finished file, plus one final call once every future in the pool has completed to guarantee a progress: 1.0 event even if the last file was tiny.

Because progress/downloadedBytes/totalBytes describe the overall asset download (not just currentFile), don't assume events arrive in a strict order by file - two threads can post around the same time with currentFile referring to whichever file each thread just finished. If you're rendering a single progress bar, key off progress; if you want a live "currently downloading" list, track currentFile per listener call rather than assuming monotonic ordering.

This event is only posted when a non-null LaunchContext is available, which is always the case when assets are downloaded as part of Launcher.launchMinecraft(...).

Listening

Subscribe on the EventBus the event is posted to, see Events for which bus that is.

eventBus.subscribe(DownloadAssetsEvent.class, event -> {
    double progress = event.progress();
    long downloadedBytes = event.downloadedBytes();
    long totalBytes = event.totalBytes();
    String currentFile = event.currentFile();
    long currentFileBytes = event.currentFileBytes();
    long currentFileSize = event.currentFileSize();
});

Posted by

API reference: com.dervarex.minified.launch.events.download.assets.DownloadAssetsEvent