resource

package
Version: v1.19.13 Latest Latest
Warning

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

Go to latest
Published: May 8, 2022 License: MIT Imports: 10 Imported by: 6

Documentation

Overview

Package resource implements the compiling of resource packs found in files, directories or raw byte data. It ensures the data in the resource pack is valid (for example, it checks if the manifest is present and holds correct data) and extracts information which may be obtained by calling the exported methods of a *resource.Pack.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capability

type Capability string

Capability is a particular feature that the pack utilises of that isn't necessarily enabled by default.

experimental_custom_ui: Allows HTML files in the pack to be used for custom UI, and scripts in the pack
                        to call and manipulate custom UI.
chemistry:              Allows the pack to add, change or replace Chemistry functionality.

type Dependency

type Dependency struct {
	// UUID is the unique identifier of the pack that this pack depends on. It needs to be the exact same UUID
	// that the pack has defined in the header section of it's manifest file.
	UUID string `json:"uuid"`
	// Version is the specific version of the pack that the pack depends on. Should match the version the
	// other pack has in its manifest file.
	Version [3]int `json:"version"`
}

Dependency describes a pack that this pack depends on in order to work.

type Header struct {
	// Name is the name of the pack as it appears within Minecraft.
	Name string `json:"name"`
	// Description is a short description of the pack. It will appear in the game below the name of the pack.
	Description string `json:"description"`
	// UUID is a unique identifier identifier this pack from any other pack.
	UUID string `json:"uuid"`
	// Version is the version of the pack, which can be used to identify changes in the pack.
	Version [3]int `json:"version"`
	// MinimumGameVersion is the minimum version of the game that this resource pack was written for.
	MinimumGameVersion [3]int `json:"min_engine_version"`
}

Header is the header of a resource pack. It contains information that applies to the entire resource pack, such as the name of the resource pack.

type Manifest

type Manifest struct {
	// FormatVersion defines the current version of the manifest. This is currently always 2.
	FormatVersion int `json:"format_version"`
	// Header is the header of a resource pack. It contains information that applies to the entire resource
	// pack, such as the name of the resource pack.
	Header Header `json:"header"`
	// Modules describes the modules that comprise the pack. Each entry here defines one of the kinds of
	// contents of the pack.
	Modules []Module `json:"modules"`
	// Dependencies describes the packs that this pack depends on in order to work.
	Dependencies []Dependency `json:"dependencies,omitempty"`
	// Capabilities are the different features that the pack makes use of that aren't necessarily enabled by
	// default. For a list of options, see below.
	Capabilities []Capability `json:"capabilities,omitempty"`
	// contains filtered or unexported fields
}

Manifest contains all the basic information about the pack that Minecraft needs to identify it.

type Metadata

type Metadata struct {
	// Author is the name of the author(s) of the pack.
	Author string `json:"authors,omitempty"`
	// License is the license applied to the pack.
	License string `json:"license,omitempty"`
	// URL is the home website of the creator of the pack.
	URL string `json:"url,omitempty"`
}

Metadata contains additional information about the pack that is otherwise optional.

type Module

type Module struct {
	// UUID is a unique identifier for the module in the same format as the pack's UUID in the header. This
	// should be different from the pack's UUID, and different for every module.
	UUID string `json:"uuid"`
	// Description is a short description of the module. This is not user-facing at the moment.
	Description string `json:"description"`
	// Type is the type of the module. Can be any of the following: resources, data, client_data, interface or
	// world_template.
	Type string `json:"type"`
	// Version is the version of the module in the same format as the pack's version in the header. This can
	// be used to further identify changes in the pack.
	Version [3]int `json:"version"`
}

Module describes a module that comprises the pack. Each module defines one of the kinds of contents of the pack.

type Pack

type Pack struct {
	// contains filtered or unexported fields
}

Pack is a container of a resource pack parsed from a directory or a .zip archive (or .mcpack). It holds methods that may be used to get information about the resource pack.

func Compile

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

Compile compiles a resource pack found at the path passed. The resource pack must either be a zip archive (extension does not matter, could be .zip or .mcpack), or a directory containing a resource pack. In the case of a directory, the directory is compiled into an archive and the pack is parsed from that. Compile operates assuming the resource pack has a 'manifest.json' file in it. If it does not, the function will fail and return an error.

func FromBytes added in v0.3.0

func FromBytes(data []byte) (*Pack, error)

FromBytes parses an archived resource pack written to a raw byte slice passed. The data must be a valid zip archive and contain a pack manifest in order for the function to succeed. FromBytes saves the data to a temporary archive.

func MustCompile

func MustCompile(path string) *Pack

MustCompile compiles a resource pack found at the path passed. The resource pack must either be a zip archive (extension does not matter, could be .zip or .mcpack), or a directory containing a resource pack. In the case of a directory, the directory is compiled into an archive and the pack is parsed from that. Compile operates assuming the resource pack has a 'manifest.json' file in it. If it does not, the function will fail and return an error. Unlike Compile, MustCompile does not return an error and panics if an error occurs instead.

func (*Pack) Checksum

func (pack *Pack) Checksum() [32]byte

Checksum returns the SHA256 checksum made from the full, compressed content of the resource pack archive. It is transmitted as a string over network.

func (*Pack) ContentKey added in v1.14.1

func (pack *Pack) ContentKey() string

ContentKey returns the encryption key used to encrypt the resource pack. If the pack is not encrypted then this can be empty.

func (*Pack) DataChunkCount

func (pack *Pack) DataChunkCount(length int) int

DataChunkCount returns the amount of chunks the data of the resource pack is split into if each chunk has a specific length.

func (*Pack) Dependencies

func (pack *Pack) Dependencies() []Dependency

Dependencies returns all dependency resource packs that must be loaded in order for this resource pack to function correctly.

func (*Pack) Description

func (pack *Pack) Description() string

Description returns the description of the resource pack.

func (*Pack) Encrypted added in v1.14.1

func (pack *Pack) Encrypted() bool

Encrypted returns if the resource pack has been encrypted with a content key or not.

func (*Pack) HasBehaviours

func (pack *Pack) HasBehaviours() bool

HasBehaviours checks if any of the modules of the resource pack have either the type 'data' or 'client_data', meaning they contain behaviours (or scripts).

func (*Pack) HasScripts

func (pack *Pack) HasScripts() bool

HasScripts checks if any of the modules of the resource pack have the type 'client_data', meaning they have scripts in them.

func (*Pack) HasTextures added in v0.9.2

func (pack *Pack) HasTextures() bool

HasTextures checks if any of the modules of the resource pack have the type 'resources', meaning they have textures in them.

func (*Pack) HasWorldTemplate added in v0.9.2

func (pack *Pack) HasWorldTemplate() bool

HasWorldTemplate checks if the resource compiled holds a level.dat in it, indicating that the resource is a world template.

func (*Pack) Len

func (pack *Pack) Len() int

Len returns the total length in bytes of the content of the archive that contained the resource pack.

func (*Pack) Manifest

func (pack *Pack) Manifest() Manifest

Manifest returns the manifest found in the manifest.json of the resource pack. It contains information about the pack such as its name.

func (*Pack) Modules

func (pack *Pack) Modules() []Module

Modules returns all modules that the resource pack exists out of. Resource packs usually have only one module, but may have more depending on their functionality.

func (*Pack) Name

func (pack *Pack) Name() string

Name returns the name of the resource pack.

func (*Pack) ReadAt

func (pack *Pack) ReadAt(b []byte, off int64) (n int, err error)

ReadAt reads len(b) bytes from the resource pack's archive data at offset off and copies it into b. The amount of bytes read n is returned.

func (*Pack) String added in v1.0.0

func (pack *Pack) String() string

String returns a readable representation of the resource pack. It implements the Stringer interface.

func (*Pack) UUID

func (pack *Pack) UUID() string

UUID returns the UUID of the resource pack.

func (*Pack) Version

func (pack *Pack) Version() string

Version returns the string version of the resource pack. It is guaranteed to have 3 digits in it, joined by a dot.

func (Pack) WithContentKey added in v1.14.1

func (pack Pack) WithContentKey(key string) *Pack

WithContentKey creates a copy of the pack and sets the encryption key to the key provided, after which the new Pack is returned.

Jump to

Keyboard shortcuts

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