launcher

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package launcher provides the necessary functions to start the game.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInstanceExist

func IsInstanceExist(id string) bool

IsInstanceExist reports whether an instance with the specified ID exists.

func Launch

func Launch(launchEnv LaunchEnvironment, runner Runner) error

Launch starts a LaunchEnvironment with the specified runner.

The Java executable is checked and the classpath and command arguments are finalized.

func RemoveInstance

func RemoveInstance(id string) error

RemoveInstance removes the instance with the specified ID.

Types

type AssetsResolvedEvent

type AssetsResolvedEvent struct {
	Assets int
}

AssetsResolvedEvent is called when all game assets have been identified and filtered.

type ConsoleRunner

type ConsoleRunner struct{}

An ConsoleRunner is an implementation of Runner which logs game output to the console.

func (ConsoleRunner) Run

func (ConsoleRunner) Run(cmd *exec.Cmd) error

type DownloadingEvent

type DownloadingEvent struct {
	Completed int
	Total     int
}

DownloadingEvent is called when a download has progressed.

type EnvOptions

type EnvOptions struct {
	Session            auth.Session
	Config             InstanceConfig
	QuickPlayServer    string
	Demo               bool
	DisableMultiplayer bool
	DisableChat        bool
	// contains filtered or unexported fields
}

EnvOptions represents configuration options when preparing an instance to be launched.

type EventWatcher

type EventWatcher interface {
	Handle(event any)
}

An EventWatcher is a controller that handles game preparation events.

type Instance

type Instance struct {
	Name          string         `json:"-"`
	GameVersion   string         `json:"game_version"`
	Loader        Loader         `json:"mod_loader"`
	LoaderVersion string         `json:"mod_loader_version,omitempty"`
	Config        InstanceConfig `json:"config"`
}

An Instance represents a full installation of Minecraft and its information.

func CreateInstance

func CreateInstance(options InstanceOptions) (Instance, error)

CreateInstance creates a new instance with the specified options.

func FetchAllInstances added in v1.1.0

func FetchAllInstances() ([]Instance, error)

AllInstances retrieves all valid instances within env.InstancesDir.

func FetchInstance added in v1.1.0

func FetchInstance(id string) (Instance, error)

GetInstance retrieves the instance with the specified ID.

func (*Instance) Dir

func (inst *Instance) Dir() string

func (*Instance) Rename added in v1.1.0

func (inst *Instance) Rename(new string) error

Rename renames instance to the specified new name

func (*Instance) WriteConfig added in v1.1.0

func (inst *Instance) WriteConfig() error

WriteConfig marshals inst and writes it to the instance configuration file. This is used to save the instance configuration.

The Name field is ignored, as it is based on the instance's directory.

type InstanceConfig

type InstanceConfig struct {
	WindowResolution struct {
		Width  int `json:"width"`
		Height int `json:"height"`
	} `json:"resolution"`
	Java      string `json:"java"`
	MinMemory int    `json:"min_memory"`
	MaxMemory int    `json:"max_memory"`
}

InstanceConfig represents the configurable values of an Instance.

type InstanceOptions

type InstanceOptions struct {
	Name          string
	GameVersion   string
	Loader        Loader
	LoaderVersion string
}

type LaunchEnvironment added in v1.1.0

type LaunchEnvironment struct {
	GameDir   string
	JavaPath  string
	MainClass string
	Classpath []string
	JavaArgs  []string
	GameArgs  []string
}

A LaunchEnvironment represents the data needed to start the game.

func Prepare

func Prepare(inst Instance, options EnvOptions, watcher EventWatcher) (LaunchEnvironment, error)

Prepare prepares the instance to be launched, returning a LaunchEnvironment, with the provided options and sends events to watcher.

type LibrariesResolvedEvent

type LibrariesResolvedEvent struct {
	Libraries int
}

LibrariesResolvedEvent is called when all game libraries have been identified and filtered.

type Loader

type Loader string

Loader represents a game mod loader.

const (
	LoaderVanilla  Loader = "vanilla"
	LoaderFabric   Loader = "fabric"
	LoaderQuilt    Loader = "quilt"
	LoaderNeoForge Loader = "neoforge"
	LoaderForge    Loader = "forge"
)

func (Loader) String

func (loader Loader) String() string

type MetadataResolvedEvent added in v1.1.0

type MetadataResolvedEvent struct{}

MetadataResolvedEvent is called when all metadata has been retrieved

type Runner

type Runner interface {
	Run(cmd *exec.Cmd) error
}

A Runner is a controller which manages the starting of the game.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL