-
Notifications
You must be signed in to change notification settings - Fork 41
MinecraftPath
Represents minecraft directory path and structure.
You can get default game directory path using MinecraftPath.GetOSDefaultPath()
, or create new instance of MinecraftPath
without any arguments.
- Windows: %appdata%.minecraft
- Linux: $HOME/.minecraft
- macOS: $HOME/Library/Application Support/minecraft
Root directory : BasePath
| - assets : Assets
| | - indexes
| | | - {asset id}.json : GetIndexFilePath(assetId)
| | - objects : GetAssetObjectPath(assetId)
| | - virtual
| | - legacy : GetAssetLegacyPath(assetId)
|
| - libraries : Library
| - resources : Resource
| - runtime : Runtime
| - versions : Versions
| - {version name}
| - {version name}.jar : GetVersionJarPath(id)
| - {version name}.json : GetVersionJsonPath(id)
| - natives : GetNativePath(id)
This example shows creating default directory structure with specific game path.
// create default path
MinecraftPath defaultPath = new MinecraftPath();
// windows: %appdata%\.minecraft
// linux: $HOME/.minecraft
// mac: $HOME/Library/Application Support/minecraft
// create instance with the specific path
// root directory (myPath.BasePath): ./games
MinecraftPath myPath = new MinecraftPath("./games");
// myPath.BasePath : ./games
// myPath.Library : ./games/libraries
// myPath.Resource : ./games/resources
// myPath.Versions : ./games/versions
// myPath.GetVersionJarPath("1.16.5") : ./games/versions/1.16.5/1.16.5.jar
// myPath.GetIndexFilePath("1.16.5") : ./games/assets/indexes/1.16.5.json
Note : all paths are converted to absolute path.
There are two ways to make custom directory structure.
Choose what you need.
Set path properties to what you want.
MinecraftPath myPath = new MinecraftPath();
myPath.Libraries = "./commons/libs";
myPath.Versions = "./commons/versions";
myPath.Assets = MinecraftPath.GetOSDefaultPath() + "/assets";
Create derived class of MinecraftPath
, and override methods.
Each methods (CreateDirs
, NormalizePath
, etc) are described below.
class MyMinecraftPath : MinecraftPath
{
public MyMinecraftPath(string p)
{
BasePath = NormalizePath(p);
Library = NormalizePath(BasePath + "/libs");
Versions = NormalizePath(BasePath + "/vers");
Resource = NormalizePath(BasePath + "/resources");
Runtime = NormalizePath(BasePath + "/java");
Assets = NormalizePath(BasePath + "/assets");
CreateDirs();
}
public override string GetVersionJarPath(string id)
=> NormalizePath($"{Versions}/{id}/client.jar");
public override string GetVersionJsonPath(string id)
=> NormalizePath($"{Versions}/{id}/client.json");
public override string GetAssetObjectPath(string assetId)
=> NormalizePath($"{Assets}/files");
}
Type: string
Root directory path
Type: string
Type: string
Type: string
Type: string
The default download path of MJava
Type: string
Old minecraft versions use this path as Assets directory.
Initialize instance with default path.
Same as new MinecraftPath(MinecraftPath.GetOSDefaultPath())
.
Initializze instance with the specific path, p
.
Call Initialize(p)
and CreateDirs()
.
Create BasePath
, Assets
, Library
, Versions
, Runtime
, Resouce
directory.
Get asset index file path.
Get asset object directory path.
Get asset legacy directory path.
Get client jar path.
Get client json path.
Get native directory path.
Native dll files will be stored here.
Normalize path
and create directory.
Normalize path
. Convert relative path to absolute path and replace invalid directory separator. (In windows, replace /
to \
)