minecraftbedrock

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

AllPackKinds lists all the different kinds of Pack.

View Source
var ErrNotImplemented = errors.New("not implemented")

ErrNotImplemented serves as our foundational sentinel error

Functions

func ExtractZip

func ExtractZip(path string, destDir string) error

ExtractZip extracts the contents of the given file path into destDir. The destDir is created if it does not exist.

func FindActiveWorldDir

func FindActiveWorldDir(serverDir string) (string, error)

FindActiveWorldDir identifies the active world directory inside a Minecraft Bedrock server installation directory. Returns the path to the active world directory. Returns an error otherwise.

func FindAddonsInDir

func FindAddonsInDir(dir string, recursive bool) ([]string, error)

FindAddonsInDir searches dir (resursively, if recursive is true) for files that are valid add-on packs. It returns their absolute paths.

func FindManifestsRelativePathInAddon

func FindManifestsRelativePathInAddon(addonPath string) ([]string, error)

FindManifestsRelativePathInAddon returns the archive-relative paths of every manifest.json file found inside the given archive add-on file. Note that returned paths are using forward slashes, as stored in the zip archive. Returns an error if no manifest.json is found in the addon.

func FindWorldDirectories

func FindWorldDirectories(serverDir string) ([]string, error)

FindActiveWorldDir found the world directories inside a Minecraft Bedrock server installation directory. Returns an error is the server is missing a `worlds` directory. Returns an empty list if the server `worlds` directory is empty. Returns the paths of the worlds otherwise.

func GetDirectoryContentAbsolutePaths

func GetDirectoryContentAbsolutePaths(dirPath string) ([]string, error)

GetDirectoryContentAbsolutePaths recursively walks through the given directory to find all the files under the given directory. Returns a list of all the files found in absolute paths.

func GetFileSize

func GetFileSize(path string) (int64, error)

GetFileSize returns the size of a file in bytes or an error.

func GetFileSizeSafe

func GetFileSizeSafe(path string) int64

GetFileSize returns the size of a file in bytes. Returns 0 if the file does not exists or there is an error.

func GetPacksLongestCommonPathPrefix added in v0.4.0

func GetPacksLongestCommonPathPrefix(packs []*Pack) string

GetPacksLongestCommonPathPrefix finds the longest path prefix shared by all packs in the given slice.

func IsPackRegisteredInRegistryFile

func IsPackRegisteredInRegistryFile(path string, uuid string, version Version) (bool, error)

IsPackRegisteredInRegistryFile checks if a pack entry is registered in the given world registry file. Returns an error if the registry file can not be loaded

func IsValidAddonFile

func IsValidAddonFile(path string) bool

IsValidAddonFile validates that the given path is a directory that matches a Minecraft Bedrock dedicated server installation. Addon files are zip file archives. The file extension must be one of the following: `.zip`, `.mcaddon` or `.mcpack`. Returns true if the given path is a valid add-on. Returns false otherwise.

func IsValidAddonFileExtension

func IsValidAddonFileExtension(path string) bool

IsValidAddonFileExtension checks if the given file path has a valid file extension for an add-on.

func IsValidMcAddonFile

func IsValidMcAddonFile(path string) bool

IsValidMcAddonFile checks that a given file path is a valid MCAddon file.

func IsValidMcPackFile

func IsValidMcPackFile(path string) bool

IsValidMcPackFile checks that a given file path is a valid MCPack file.

func IsValidServerDirectory

func IsValidServerDirectory(path string) bool

IsValidServerDirectory validates that the given path is a directory that matches a Minecraft Bedrock dedicated server installation. It is considered valid if it contains the following: * a server.properties file * a bedrock_server executable * a worlds directory. Returns true if the given path is valid server. Returns false otherwise.

func LoadLanguageProperties added in v0.4.0

func LoadLanguageProperties(path string) (*properties.Properties, error)

func LoadLanguagePropertiesFromBytes added in v0.4.0

func LoadLanguagePropertiesFromBytes(data []byte) (*properties.Properties, error)

LoadLanguagePropertiesFromBytes parses the raw JSON bytes of a language *.lang file file as a *properties.Properties.

func LoadLanguages added in v0.4.0

func LoadLanguages(filePath string) ([]string, error)

func LoadLanguagesFromBytes added in v0.4.0

func LoadLanguagesFromBytes(data []byte) ([]string, error)

LoadLanguagesFromBytes parses the raw JSON bytes of a languages.json file as an []string structure.

func LoadRegistryFile

func LoadRegistryFile(path string) ([]registryEntry, error)

LoadRegistryFile reads the world registry file. A registry file contains a list of registryEntry. If the file does not exist, an empty (not nil-error) list is returned.

func NotImplementedErr

func NotImplementedErr() error

NotImplementedErr dynamically grabs the name of whichever function invokes it

func RegisterPackInRegistryFile

func RegisterPackInRegistryFile(path string, uuid string, version Version) error

RegisterPackInRegistryFile adds (or updates) a pack entry in the given world registry file. Registering an already-registered pack updates the existing entry. It does not create duplicate the entry.

func RemoveFormattingInPackName added in v0.4.0

func RemoveFormattingInPackName(name string) string

func RemoveInvalidFileSystemCharacters

func RemoveInvalidFileSystemCharacters(s string) string

RemoveInvalidFileSystemCharacters removes characters from a string that are not compatible with most filesystems. It returns a string which can safely be used to create files or directories.

func RemoveNonAsciiCharacters

func RemoveNonAsciiCharacters(s string) string

RemoveNonAsciiCharacters removes non-ascii characters from a string

func RemoveNonPrintableCharacters

func RemoveNonPrintableCharacters(s string) string

RemoveNonPrintableCharacters removes non-printable characters from a string. It returns a string which all characters can be printed on the console or a terminal.

func ReplaceInvalidFileSystemCharacters

func ReplaceInvalidFileSystemCharacters(s string, replacement string) string

ReplaceNonAsciiCharacters takes an input string and replaces any characters that are not filesystem compatible (characters such as control characters in a filesystem) with the specified replacement string.

func ReplaceNonAsciiCharacters

func ReplaceNonAsciiCharacters(s string, replacement string) string

ReplaceNonAsciiCharacters takes an input string and replaces any non-ASCII characters (characters with a code point value greater than 127) with the specified replacement string.

func ReplaceNonPrintableCharacters

func ReplaceNonPrintableCharacters(s string, replacement string) string

ReplaceNonPrintableCharacters takes an input string and replaces any non-printable characters (characters not writable on the console or a terminal) with the specified replacement string.

func ResolveAddonByUUID

func ResolveAddonByUUID(uuid string, serverDir string) (string, error)

ResolveAddonByUUID searches serverDir (recursively) for an add-on file containing a pack whose manifest UUID matches the given UUID. Returns the path of the first matching add-on file found. Returns an empty path if no match is found. Returns an error otherwise.

func SanitizeString

func SanitizeString(s string, replacement string) string

SanitizeString takes an input string and replaces all non-ASCII characters from a string, except for Latin alphabet letters (characters with accents such as ó, ò, ô, ö, õ, and ō) with the specified replacement string.

func SortPacksByKind added in v0.4.0

func SortPacksByKind(packs []*Pack)

SortPacksByKind orders a pack slice by kind then by name.

func SortPacksByNames added in v0.4.0

func SortPacksByNames(packs []*Pack)

SortPacksByNames orders a pack slice by name then by kind.

func StringsCompareN

func StringsCompareN(s1, s2 string, n int) bool

func UnregisterPackInRegistryFile

func UnregisterPackInRegistryFile(path string, uuid string, version Version) error

UnregisterPackInRegistryFile removes a pack entry in the given world registry file. Does not return an error if the given uuid is not already registered. To know if a pack is actually unregistered, use IsPackRegisteredInRegistryFile() before and after the call which is expensive.

func ValidateAddonFile

func ValidateAddonFile(path string) error

ValidateAddonFile asserts that the given path is a valid addon file. Addon files are zip file archives. The file extension must be one of the following: `.zip`, `.mcaddon` or `.mcpack`.

func ValidateDirectory

func ValidateDirectory(path string) error

ValidateDirectory asserts that the given path is a valid directory that exists.

func ValidateServerDirectory

func ValidateServerDirectory(path string) error

ValidateServerDirectory asserts that the given path is a directory that matches a Minecraft Bedrock dedicated server installation. It is considered valid if it contains the following: * a server.properties file * a bedrock_server executable * a worlds directory. Returns nil if the given path is server. Returns a valid error otherwise.

func WriteRegistryFile

func WriteRegistryFile(path string, entries []registryEntry) error

WriteRegistryFile write the given registry entries the world registry file. A registry file contains a list of registryEntry. If the file does not exist, the file is created an empty (not nil-error) list is returned.

func ZipFilePathGetParentDir added in v0.3.0

func ZipFilePathGetParentDir(path string) string

ZipFilePathGetParentDir returns the parent directory of a given path. The function supports both forward slashes and backslashes.

func ZipFilePathJoin added in v0.3.0

func ZipFilePathJoin(elem ...string) string

ZipFilePathJoin joins any number of path elements into a single path, separating them with a the ZIP specific separator `/`. Empty elements are ignored.

Types

type AddonManifest

type AddonManifest struct {
	FormatVersion int          `json:"format_version"`
	Header        Header       `json:"header"`
	Modules       []Module     `json:"modules,omitempty"`
	Dependencies  []Dependency `json:"dependencies,omitempty"`
	Capabilities  []string     `json:"capabilities,omitempty"`
	Metadata      *Metadata    `json:"metadata,omitempty"`
}

AddonManifest mirrors the structure of a Minecraft Bedrock pack manifest.json file.

func LoadManifestFromBytes

func LoadManifestFromBytes(data []byte) (*AddonManifest, error)

LoadManifestFromBytes parses the raw JSON bytes of a manifest.json file as an AddonManifest structure.

func LoadManifestFromFile

func LoadManifestFromFile(path string) (*AddonManifest, error)

LoadManifestFromFile loads a manifest.json data from a file path as an AddonManifest structure.

type Command

type Command int
const (
	Install   Command = iota // 0
	Uninstall                // 1
)

func (Command) String

func (command Command) String() string

type Dependency

type Dependency struct {
	UUID       string  `json:"uuid,omitempty"`
	ModuleName string  `json:"module_name,omitempty"`
	Version    Version `json:"version,omitempty"`
}

Dependency mirrors an entry of the "dependencies" array of a manifest.json.

type Header struct {
	Name             string  `json:"name"`
	Description      string  `json:"description,omitempty"`
	UUID             string  `json:"uuid"`
	Version          Version `json:"version"`
	MinEngineVersion Version `json:"min_engine_version,omitempty"`
}

Header mirrors the "header" object of a Minecraft Bedrock manifest.json.

type Metadata

type Metadata struct {
	Authors []string `json:"authors,omitempty"`
	License string   `json:"license,omitempty"`
	URL     string   `json:"url,omitempty"`
}

Metadata mirrors the optional "metadata" object of a manifest.json.

type Module

type Module struct {
	Type        string  `json:"type"`
	UUID        string  `json:"uuid,omitempty"`
	Version     Version `json:"version"`
	Description string  `json:"description,omitempty"`
	Entry       string  `json:"entry,omitempty"`
}

Module mirrors an entry of the "modules" array of a manifest.json.

type Pack

type Pack struct {
	Path         string
	Manifest     *AddonManifest
	LanguageList []string
	LanguageMap  map[string]*properties.Properties
}

func FilterPacksByKind

func FilterPacksByKind(packs []*Pack, kind PackKind) []*Pack

FilterPacksByKind filters a given list of packs by PackKind.

func FilterPacksByUUID

func FilterPacksByUUID(packs []*Pack, uuid string) []*Pack

FilterPacksByUUID filters a given list of packs by UUID. There should not be multiple packs with the same UUID in the same list. This function is mostly for cleanup and integrity.

func FindPackByUUID

func FindPackByUUID(packs []*Pack, uuid string) *Pack

FindPackByUUID searches a given list of packs for a pack with the given UUID.

func InstallAddonInServer

func InstallAddonInServer(addonPath string, serverDir string) ([]*Pack, error)

InstallAddonInServer installs every pack contained in the given add-on file (addonPath) into the given Minecraft Bedrock server located at serverDir. Returns the list of packs that were installed. Returns an error otherwise.

func ListInstalledPacks

func ListInstalledPacks(serverDir string) ([]*Pack, error)

ListInstalledPacks lists the packs currently registered for a given Minecraft Bedrock server located at serverDir. For each registered UUID, it attempts to resolve the name of the pack by scanning the corresponding behavior_packs/ or resource_packs/ directories for a matching manifest.json.

func LoadAllPacksFromDirectoriesOrSubdirectories

func LoadAllPacksFromDirectoriesOrSubdirectories(root string) ([]*Pack, error)

LoadAllPacksFromDirectoriesOrSubdirectories recursively traverses the given directory to detect and load directories containing Packs. This function is compatible with `.mcpack` and `.mcaddon` files. Extension `.mcpack` have a manifest.json file at the root directory. Extension `.mcaddon` have a manifest.json file in each sub directory. Returns an error if a directory containing a manifest.json which fails to load as a pack. Returns am empty pack list when no manifest.json files is found.

func LoadPackFromDirectory

func LoadPackFromDirectory(path string) (*Pack, error)

LoadPackFromDirectory loads a pack stored in the given directory. The given directory path must contains a manifest.json file to be a valid pack. Returns a valid pack or an error otherwise.

func LoadPackFromZip added in v0.3.0

func LoadPackFromZip(zipPath string, packDir string) (*Pack, error)

LoadPackFromZip loads a pack stored in the given relative zip directory. The given relative directory path must contains a manifest.json file to be a valid pack. Returns a valid pack or an error otherwise.

func LoadPacksFromSubdirectories

func LoadPacksFromSubdirectories(path string) ([]*Pack, error)

LoadPacksFromSubdirectories browse the sub directories from the given directory and loads a pack from each subdir. All sub directories must be a valid pack directory, otherwise the function returns an error. Returns a valid list of packs. Returns an empty list if there are no subdirectories. Returns an error otherwise.

func LoadPacksFromZip added in v0.3.0

func LoadPacksFromZip(zipPath string) ([]*Pack, error)

LoadPacksFromZip recursively traverses the given zip file to detect and load directories containing Packs. This function is compatible with `.mcpack` and `.mcaddon` files. Extension `.mcpack` have a manifest.json file at the root directory. Extension `.mcaddon` have a manifest.json file in each sub directory. Returns an error if a directory containing a manifest.json which fails to load as a pack. Returns am empty pack list when no manifest.json files is found.

func UninstallAddonInServer

func UninstallAddonInServer(addonPath, serverDir string) ([]*Pack, error)

UninstallAddonInServer uninstalls every pack contained in the add-on file at the given addonPath from the Minecraft Bedrock server installed at serverDir. It returns the list of packs that were uninstalled or an error.

func UninstallPackInServerByUUID

func UninstallPackInServerByUUID(uuid, serverDir string) (*Pack, error)

UninstallPackInServerByUUID uninstalls a single pack, identified by a UUID from the Minecraft Bedrock server installed at serverDir. This function is useful when the original add-on file is no longer available or has been deleted.

func (Pack) Description

func (p Pack) Description() string

func (Pack) GetDefaultLocalizedTextValue added in v0.4.0

func (p Pack) GetDefaultLocalizedTextValue(textKey string) (value string, exists bool)

func (Pack) GetFirstLocalizedLanguage added in v0.4.0

func (p Pack) GetFirstLocalizedLanguage() string

func (Pack) GetLocalizedTextValue added in v0.4.0

func (p Pack) GetLocalizedTextValue(langKey, textKey string) (value string, exists bool)

func (Pack) HasLanguages added in v0.4.0

func (p Pack) HasLanguages() bool

func (Pack) Kind

func (p Pack) Kind() (PackKind, error)

func (Pack) KindSafe

func (p Pack) KindSafe() PackKind

func (Pack) Name

func (p Pack) Name() string

func (Pack) NameSanitized

func (p Pack) NameSanitized() string

func (Pack) NameWithoutFormatting added in v0.4.0

func (p Pack) NameWithoutFormatting() string

func (Pack) UUID

func (p Pack) UUID() string

type PackKind

type PackKind int

PackKind identifies whether a pack found inside an add-on is a behavior or a resource pack.

const (
	// UnknownPack is returned when the pack kind could not be determined from its manifest.
	UnknownPack PackKind = iota

	// BehaviorPack identifies a Minecraft Bedrock behavior pack.
	BehaviorPack

	// ResourcePack identifies a Minecraft Bedrock resource pack.
	ResourcePack
)

func IdentifyPackKind

func IdentifyPackKind(m *AddonManifest) (PackKind, error)

IdentifyPackKind inspects a AddonManifest sutrct to determines if the manifest matches a behavior pack or a resource pack. Behavior packs use module types "data" or "script". Resource packs use module types "resources", "client_data" or "interface".

func (PackKind) InstallDirName

func (k PackKind) InstallDirName() (string, error)

InstallDirName returns the directory name where a pack of the given kind must be installed in a world. Possible return values are `behavior_packs`, `resource_packs` or an error.

func (PackKind) RegistryFileName

func (k PackKind) RegistryFileName() (string, error)

RegistryFileName returns the world registry file name that manages the given kind of pack. Possible return values are `world_behavior_packs.json`, `world_resource_packs.json` or an error.

func (PackKind) String

func (k PackKind) String() string

String implements fmt.Stringer for PackKind.

type Server

type Server struct {
	Path string
}

func GetServer

func GetServer(path string) (*Server, error)

func (Server) ActiveWorld

func (s Server) ActiveWorld() (*World, error)

func (Server) IsValid

func (s Server) IsValid() bool

type Version

type Version [3]int

Version represents a Minecraft Bedrock manifest [major, minor, patch] version triplet.

func (Version) String

func (v Version) String() string

String renders the version as "major.minor.patch".

func (*Version) UnmarshalJSON

func (v *Version) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal a Version from an array of 3 integers (`[1, 2, 3]`) or from a string (`"4.5.6"`). Some manifest specifies versions as string instead of the offical 3 integer array.

type World

type World struct {
	Path string
}

func (World) InstallAddon

func (w World) InstallAddon(addonPath string) ([]*Pack, error)

InstallAddonInWorld installs every pack contained in the given add-on file (addonPath) into the given Minecraft Bedrock world directory at worldDir. Returns the list of packs that were installed. Returns an error otherwise.

func (World) InstallPack

func (w World) InstallPack(pack *Pack) (*Pack, error)

InstallPackInWorld installs the given pack into the given Minecraft Bedrock world directory at worldDir. During the installation process, the pack's original directory is moved to a new location. Returns the pack's updated information if installed succesfully. Returns an error otherwise.

func (World) IsPackOwnedByWorld

func (w World) IsPackOwnedByWorld(pack *Pack) bool

IsPackOwnedByWorld defines if a given pack is owned by this world. A pack is owned when it is installed in an official kind directory. Returns true when the given pack is owned by this world. Returns false otherwise.

func (World) IsPackRegistered

func (w World) IsPackRegistered(pack *Pack) (bool, error)

IsPackRegistered checks if the given pack is registered in the world. Returns an error if the registry file can not be loaded

func (World) Name

func (w World) Name() (string, error)

Name returns the name of the World. The name of a level is stored in file `levelname.txt`. If this file is missing, the function fall back to using the directory name as the name of the world.

func (World) Packs

func (w World) Packs() ([]*Pack, error)

Packs returns the packs installed in this world.

func (World) PacksByKind

func (w World) PacksByKind(kind PackKind) ([]*Pack, error)

PacksByKind returns the packs installed in this world that matches the given kind of pack.

func (World) PacksByUUID

func (w World) PacksByUUID(uuid string) (*Pack, error)

PacksByKind searches the packs installed in this world and returns the pack that matches the given UUID. Returns nil if the pack is not found (no error)

func (World) PacksInstallDir

func (w World) PacksInstallDir(kind PackKind) (string, error)

PacksInstallDir provides the installation directory path for a given kind of packs.

func (World) RegisterPack

func (w World) RegisterPack(pack *Pack) error

RegisterPack registers the given pack in the world.

func (World) UninstallAddon

func (w World) UninstallAddon(addonPath string) ([]*Pack, error)

UninstallAddonInWorld uninstalls every pack contained in the given add-on file (addonPath) from the given Minecraft Bedrock world directory at worldDir. Returns the list of packs that were installed. Returns an error otherwise.

func (World) UninstallPack

func (w World) UninstallPack(pack *Pack) (*Pack, error)

UninstallPackInWorld uninstalls the given pack from the given Minecraft Bedrock world directory at worldDir.

func (World) UnregisterPack

func (w World) UnregisterPack(pack *Pack) error

UnregisterPack unregisters the given pack in the world.

Jump to

Keyboard shortcuts

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