minecraft

package
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const SupportedLauncherVersion = 21

SupportedLauncherVersion indicates the maximum Launch Manifest version that is supported

Variables

This section is empty.

Functions

func FallbackJVMArgs added in v0.1.23

func FallbackJVMArgs(os string) []string

FallbackJVMArgs returns some default jvm arguments for the given OS. This can be used if no jvm args are defined in the manifest. Old versions of minecraft do not define any jvm args.

Note that this contains the following variables that need to be replaced:

  • ${natives_directory}
  • ${classpath}
  • ${launcher_name}
  • ${launcher_version}

func MergeManifests added in v0.1.23

func MergeManifests(source *LaunchManifest, manifests ...*LaunchManifest)

MergeManifests merges important properties from the given manifests by modifying the source manifest. It merges libraries, game args and jvm args by appending them. This is a simple implementation. it does not merge everything and does not care for duplicates.

Example
package main

import (
	"fmt"

	"github.com/minepkg/minepkg/internals/minecraft"
)

func main() {
	source := &minecraft.LaunchManifest{
		ID: "1.18.2",
		Libraries: []minecraft.Library{
			{Name: "commons-logging:commons-logging:1.2"},
		},
	}
	manifest2 := &minecraft.LaunchManifest{
		ID: "overwritten",
		Libraries: []minecraft.Library{
			{Name: "io.minepkg.test:lib:1.0.0"},
		},
	}
	// MergeManifest modifies the source manifest
	minecraft.MergeManifests(source, manifest2)

	// Print the modified source manifest
	fmt.Println("ID:", source.ID)
	fmt.Println("Libraries:")
	for _, arg := range source.Libraries {
		fmt.Println(" - ", arg.Name)
	}
}
Output:

ID: overwritten
Libraries:
 -  commons-logging:commons-logging:1.2
 -  io.minepkg.test:lib:1.0.0

Types

type ActualArgument added in v0.1.23

type ActualArgument struct {
	// Value is the actual argument
	Value stringSlice `json:"value"`
	Rules []Rule      `json:"rules"`
}

type Argument added in v0.1.23

type Argument struct{ ActualArgument }

Argument is slice of command values that can be applied to the JVM or Game they can have rules that are used to determine if they should be applied Example:

{
	"value": "-Xss1M"
	"rules": [{
		"action": "allow",
		"os": { "arch": "x86" }
	}]
}

func (*Argument) Applies added in v0.1.23

func (a *Argument) Applies() bool

Applies returns true if every Rule in this argument applies (to this OS).

func (*Argument) UnmarshalJSON added in v0.1.23

func (a *Argument) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON is needed because argument sometimes is a string

type Arguments added in v0.1.23

type Arguments struct {
	Game []Argument `json:"game"`
	JVM  []Argument `json:"jvm"`
}

type Artifact added in v0.1.23

type Artifact struct {
	// Path of the jar file relative to the libraries folder
	// Path is not set for the minecraft client itself
	Path string `json:"path,omitempty"`
	Sha1 string `json:"sha1"`
	// Size in bytes
	Size json.Number `json:"size"`
	// URL to download the jar file
	URL string `json:"url"`
}

Artifact is an object describing a "thing" that can be downloaded It is used to download libraries and the minecraft client itself

type AssetIndex

type AssetIndex struct {
	// Objects is a map of AssetObjects
	// The key is the readable file name
	Objects map[string]AssetObject
}

AssetIndex is the representation of a json file that contains a list of all assets (textures, sounds, etc.)

type AssetObject

type AssetObject struct {
	Hash string
	Size int
}

AssetObject is one minecraft asset (e.g. a texture) Assets do not have file endings The AssetIndex can be used to map the hash to the "actual" file name

func (*AssetObject) Directory added in v0.1.23

func (a *AssetObject) Directory() string

Directory returns the directory name of this asset that it should be stored in. This is the first two characters of the hash.

func (*AssetObject) DownloadURL

func (a *AssetObject) DownloadURL() string

DownloadURL returns the download url for this asset

func (*AssetObject) UnixPath

func (a *AssetObject) UnixPath() string

UnixPath returns the path including the folder Example: /fe/fe32f3b8…

type LaunchAuthData added in v0.1.5

type LaunchAuthData interface {
	// GetAccessToken returns the access token (strictly required)
	GetAccessToken() string
	// GetAccessToken returns the users UUID (strictly required)
	GetUUID() string
	// GetPlayerName returns the users player name (the one that also appears in game)
	GetPlayerName() string
	// GetUserType returns the users user type (legacy, mojang or msa).
	// "legacy" is the old minecraft account type (should not be encountered anymore)
	// "mojang" was the new minecraft account type (being replaced by "msa")
	// "msa" is the new microsoft account type
	GetUserType() string
	// GetXUID returns the users XUID (only for xbox live accounts – user type "msa"))
	GetXUID() string
}

LaunchAuthData is an interface defining the data required to authenticate

type LaunchManifest

type LaunchManifest struct {
	// MinecraftArguments are used before 1.13 (?)
	// It is a string that only contains the arguments to be passed to Minecraft (no JVM arguments).
	// It is replaced by the Arguments field in 1.13
	MinecraftArguments string `json:"minecraftArguments"`
	// Arguments is an object that contains the arguments to be passed to Minecraft and the JVM.
	// It is used in 1.13 and newer.
	Arguments *Arguments `json:"arguments,omitempty"`
	// MainClass is the main class to launch (eg. net.minecraft.client.main.Main) – modded versions (like fabric) usually override this
	MainClass string `json:"mainClass"`

	// Downloads contains the client and server artifacts (jar files)
	// Newer versions also contain the mappings txt files (client_mappings and server_mappings)
	Downloads *struct {
		// Client is the main client jar file ("minecraft.jar")
		Client         Artifact `json:"client"`
		Server         Artifact `json:"server"`
		ClientMappings Artifact `json:"client_mappings,omitempty"`
		ServerMappings Artifact `json:"server_mappings,omitempty"`
	} `json:"downloads"`
	// Libraries is a list of libraries that are required to launch the game.
	// They need to be downloaded and added to the classpath.
	// Libraries can have rules that are used to determine if they should be applied.
	Libraries []Library `json:"libraries"`

	// JavaVersion is the version of the Java Runtime that is required to launch the game.
	JavaVersion *struct {
		Component    string `json:"component"`    // The official launcher uses these names (they are not that useful)
		MajorVersion int    `json:"majorVersion"` // Java Version number required (eg. 16, 17)
	} `json:"javaVersion"`
	// Assets is the ID of the assets index (eg. 1.16)
	Assets string `json:"assets"`
	// AssetIndex is some metadata about the assets index file
	// The assets index is a json file that contains a list of all assets (textures, sounds, etc.)
	// The "URL" can be fetched and unmarshalled into an AssetIndex struct
	AssetIndex struct {
		ID        string `json:"id"`
		Sha1      string `json:"sha1"`
		Size      int    `json:"size"`
		TotalSize int    `json:"totalSize"`
		URL       string `json:"url"`
	} `json:"assetIndex,omitempty"`

	// ID is the version number (eg. 1.16.5)
	ID string `json:"id"`
	// InheritsFrom is used by modded versions to inherit from a vanilla version
	InheritsFrom string `json:"inheritsFrom"`
	// Type is the type of the version (eg. release, snapshot, old_alpha, old_beta)
	Type string `json:"type"`
	// unsure what this is, might be a modding thing
	Jar string `json:"jar"`
	// MinimumLauncherVersion is the minimum launcher version required to launch this version.
	// This indicates the version of the launch manifest.
	MinimumLauncherVersion int `json:"minimumLauncherVersion"`
}

LaunchManifest is a version.json manifest that is used to launch minecraft instances Example files:

func (*LaunchManifest) FullArgs added in v0.1.23

func (l *LaunchManifest) FullArgs() []string

FullArgs returns the launch arguments defined in the manifest as a string slice. This is a concatenation of LaunchManifest.JVMArgs the MainClass and LaunchManifest.GameArgs. Uses FallbackJVMArgs if no JVM Arguments are defined in this manifest (in "LaunchManifest.Arguments.JVM").

These arguments should be able to launch the game after replacing variables when launched with a java executable.

func (*LaunchManifest) GameArgs added in v0.1.23

func (l *LaunchManifest) GameArgs() []string

GameArgs returns the game arguments that apply to this OS as a slice of strings eg ["--username", "${auth_player_name}"] may contain variables that need to be replaced

func (*LaunchManifest) JVMArgs added in v0.1.23

func (l *LaunchManifest) JVMArgs() []string

JVMArgs returns the jvm arguments that apply to this OS as a slice of strings eg ["-Xmx1G", "-Xms1G", "-Djava.library.path=${natives_directory]"] may contain variables that need to be replaced note that this can be an empty slice (eg for 1.12 or older)

func (*LaunchManifest) JarName

func (l *LaunchManifest) JarName() string

JarName returns this manifests jar name (for example `1.12.0.jar`)

func (*LaunchManifest) MinecraftVersion

func (l *LaunchManifest) MinecraftVersion() string

MinecraftVersion returns the minecraft version

type Library added in v0.1.23

type Library struct {
	// Name can be used to identify the library, but is not required otherwise.
	Name      string `json:"name"`
	Downloads struct {
		Artifact Artifact `json:"artifact"`
		// Classifiers is a list of additional artifacts.
		// It is used to download native libraries.
		// The `Natives` field is used to determine which classifier to use.
		// This field is no longer used starting with 1.19
		Classifiers map[string]Artifact `json:"classifiers"`
	} `json:"downloads,omitempty"`
	URL string `json:"url"`
	// Rules is a list of rules that determine whether this library should be included.
	// If no rules are specified, the library is included by default.
	Rules []Rule `json:"rules"`
	// Natives is a map of OS names to native library names.
	// This field is no longer used starting with 1.19
	// Newer library versions extract the native library from a jar at runtime.
	Natives map[string]string `json:"natives"`
}

Library is a minecraft library

func RequiredLibraries added in v0.1.23

func RequiredLibraries(libraries []Library) []Library

RequiredLibraries returns a slice of libraries that are required for the current platform

func (*Library) Applies added in v0.1.23

func (l *Library) Applies() bool

Applies returns true if every Rule in this argument applies (to this OS).

func (*Library) DownloadURL added in v0.1.23

func (l *Library) DownloadURL() string

DownloadURL returns the Download URL this library

func (*Library) Filepath added in v0.1.23

func (l *Library) Filepath() string

Filepath returns the target filepath for this library

type OS added in v0.1.23

type OS struct {
	Name string `json:"name"`
	// Version of the os (can be a regex string)
	Version string `json:"version"`
	// Arch of the system
	Arch string `json:"arch"`
}

OS defines the feature of an OS that can be used in a Rule to determine if it should be applied.

type Rule added in v0.1.23

type Rule struct {
	Action   string          `json:"action"`
	OS       OS              `json:"os"`
	Features map[string]bool `json:"features"`
}

Rule is a rule that can be applied to an argument or library. It can be used to determine if the argument or library should be applied to a specific OS.

func (Rule) Applies added in v0.1.23

func (r Rule) Applies() bool

type ServerProperties

type ServerProperties map[string]string

ServerProperties is a map of server props

func ParseServerProps

func ParseServerProps(buf []byte) ServerProperties

ParseServerProps returns a ServerProperties object that contains the parsed props

func (*ServerProperties) String

func (s *ServerProperties) String() string

String returns ServerProperties as a string (config file)

Directories

Path Synopsis
Package mojang allows to login to a mojang account in order to start Minecraft
Package mojang allows to login to a mojang account in order to start Minecraft

Jump to

Keyboard shortcuts

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