Skip to main content

MinecraftInstance

Concrete implementation of BaseInstance for Minecraft instances. Class: MinecraftInstance
Header: launcher/minecraft/MinecraftInstance.h
Inherits: BaseInstance

Constructor

MinecraftInstance(
    SettingsObject* globalSettings,
    std::unique_ptr<SettingsObject> settings,
    const QString& rootDir
);

Directory Structure

gameRoot()
QString
Returns the Minecraft game directory (.minecraft).
binRoot()
QString
Returns the binary directory for Minecraft executables.
modsRoot()
QString
Returns the mods root directory.
jarModsDir()
QString
Returns the jar mods directory.
resourcePacksDir()
QString
Returns the resource packs directory.
texturePacksDir()
QString
Returns the texture packs directory.
shaderPacksDir()
QString
Returns the shader packs directory.
dataPacksDir()
QString
Returns the data packs directory.
worldDir()
QString
Returns the saves/worlds directory.
libDir()
QString
Returns the libraries directory.
resourcesDir()
QString
Returns the resources directory.

Path Helpers

QDir jarmodsPath() const;
QDir librariesPath() const;
QDir versionsPath() const;
QString instanceConfigFolder() const override;
QString getNativePath() const;
QString getLocalLibraryPath() const;

Resource Management

Access various resource folder models:
loaderModList()
ModFolderModel*
Returns the loader mods folder model.
coreModList()
ModFolderModel*
Returns the core mods folder model.
nilModList()
ModFolderModel*
Returns the nil mods folder model.
resourcePackList()
ResourcePackFolderModel*
Returns the resource packs folder model.
texturePackList()
TexturePackFolderModel*
Returns the texture packs folder model.
shaderPackList()
ShaderPackFolderModel*
Returns the shader packs folder model.
dataPackList()
DataPackFolderModel*
Returns the data packs folder model.
worldList()
WorldList*
Returns the worlds list.
resourceLists()
QList<ResourceFolderModel*>
Returns all resource folder models.

Profile Management

getPackProfile()
PackProfile*
Returns the component/version profile for this instance.

Launch Configuration

QList<Task::Ptr> createUpdateTask() override;
Creates update tasks for the instance (downloads libraries, assets, etc.).
LaunchTask* createLaunchTask(
    AuthSessionPtr account,
    MinecraftTarget::Ptr targetToJoin
) override;
Creates a launch task for starting the game.

Java Configuration

getJavaVersion()
JavaVersion
Returns the Java version required by this instance.
QStringList getClassPath();
QStringList getNativeJars();
QString getMainClass() const;

Utility Methods

supportsDemo()
bool
Returns true if the instance supports Minecraft demo mode.
getJarMods()
QList<Mod*>
Returns list of jar mods in the instance.
getLauncher()
QString
Returns the launcher type/wrapper to use.
shouldApplyOnlineFixes()
bool
Returns true if online fixes should be applied.

Example Usage

#include "minecraft/MinecraftInstance.h"
#include "Application.h"

// Get a Minecraft instance
BaseInstance* base = APPLICATION->instances()->getInstanceById("my_instance");
MinecraftInstance* inst = dynamic_cast<MinecraftInstance*>(base);

if (inst) {
    // Access resource lists
    ModFolderModel* mods = inst->loaderModList();
    qDebug() << "Mods:" << mods->size();
    
    // Get directories
    qDebug() << "Mods dir:" << inst->modsRoot();
    qDebug() << "World dir:" << inst->worldDir();
    qDebug() << "Resource packs:" << inst->resourcePacksDir();
    
    // Work with pack profile
    PackProfile* profile = inst->getPackProfile();
    qDebug() << "Minecraft version:" << profile->getComponentVersion("net.minecraft");
    
    // Create launch task
    AuthSessionPtr session = /* get account session */;
    LaunchTask* task = inst->createLaunchTask(session, nullptr);
    connect(task, &Task::finished, [task]() {
        qDebug() << "Launch task finished";
    });
    task->start();
}

PackProfile

Manages the component profile for a Minecraft instance (versions, mods, loaders). Class: PackProfile
Header: launcher/minecraft/PackProfile.h
Inherits: QAbstractListModel

Constructor

explicit PackProfile(MinecraftInstance* instance);

Component Management

getComponent(const QString& id)
ComponentPtr
Returns a component by its unique ID (e.g., “net.minecraft”, “net.fabricmc.fabric-loader”).
getComponent(size_t index)
ComponentPtr
Returns a component by its index in the profile.
appendComponent(ComponentPtr component)
void
Adds a component to the profile.

Version Management

getComponentVersion(const QString& uid)
QString
Returns the version string for a component.
setComponentVersion(const QString& uid, const QString& version, bool important)
bool
Sets the version for a component. Returns true on success.
void setOldConfigVersion(const QString& uid, const QString& version);
Sets legacy version mapping from instance config.

Installation

void installJarMods(QStringList selectedFiles);
Installs jar mods to the instance.
void installCustomJar(QString selectedFile);
Installs a custom jar as the main game jar.

Component Operations

enum MoveDirection { MoveUp, MoveDown };
move(int index, MoveDirection direction)
void
Moves a component up or down in the load order.
remove(int index)
bool
Removes a component by index. Returns true on success.
remove(const QString& id)
bool
Removes a component by ID. Returns true on success.
customize(int index)
bool
Customizes a component (creates editable patch). Returns true on success.
revertToBase(int index)
bool
Reverts a customized component to its base version. Returns true on success.

Profile Operations

reload(Net::Mode netmode)
Result
Reloads the component list and resolves dependencies.
resolve(Net::Mode netmode)
void
Resolves component dependencies without reloading.
saveNow()
void
Saves the profile immediately (normally saves are scheduled).

Launch Profile

getProfile()
std::shared_ptr<LaunchProfile>
Returns the computed launch profile after resolving all components.
invalidateLaunchProfile()
void
Marks the launch profile as invalid, requiring recomputation.

Mod Loader Detection

getModLoaders()
std::optional<ModPlatform::ModLoaderTypes>
Returns the active mod loader types (Forge, Fabric, Quilt, NeoForge).
getSupportedModLoaders()
std::optional<ModPlatform::ModLoaderTypes>
Returns supported mod loaders including compatible ones (e.g., Quilt supports Fabric).
getModLoadersList()
QList<ModPlatform::ModLoaderType>
Returns list of individual mod loader types.

Model Columns

enum Columns {
    NameColumn = 0,
    VersionColumn,
    NUM_COLUMNS
};

Signals

signals:
    void minecraftChanged();

Example Usage

#include "minecraft/PackProfile.h"
#include "minecraft/MinecraftInstance.h"

MinecraftInstance* inst = /* ... */;
PackProfile* profile = inst->getPackProfile();

// Get Minecraft version
QString mcVersion = profile->getComponentVersion("net.minecraft");
qDebug() << "Minecraft version:" << mcVersion;

// Change Minecraft version
if (profile->setComponentVersion("net.minecraft", "1.20.1", true)) {
    qDebug() << "Version changed successfully";
}

// Install Fabric
if (profile->installEmpty("net.fabricmc.fabric-loader", "Fabric Loader")) {
    profile->setComponentVersion("net.fabricmc.fabric-loader", "0.15.0");
}

// Check mod loaders
auto loaders = profile->getModLoaders();
if (loaders.has_value()) {
    qDebug() << "Has mod loader installed";
}

// Reload profile with network access
auto result = profile->reload(Net::Mode::Online);
if (result) {
    qDebug() << "Profile reloaded successfully";
} else {
    qDebug() << "Error:" << result.error;
}

// Get component by ID
ComponentPtr mc = profile->getComponent("net.minecraft");
if (mc) {
    qDebug() << "Component name:" << mc->getName();
}