Skip to main content
The minecraft/resource package handles compiling, reading, and managing Minecraft Bedrock Edition resource packs from files, directories, or raw data.

Reading Resource Packs

ReadPath

func ReadPath(path string) (*Pack, error)
Reads a resource pack from a file path. The path can be either:
  • A .zip or .mcpack archive
  • A directory (will be compiled into an archive)
path
string
Path to the resource pack file or directory
*Pack
The compiled resource pack
error
Error if reading or compilation fails

MustReadPath

func MustReadPath(path string) *Pack
Like ReadPath but panics on error. Useful for initialization.

ReadURL

func ReadURL(url string) (*Pack, error)
Downloads and compiles a resource pack from a URL.
url
string
URL to download the resource pack from

MustReadURL

func MustReadURL(url string) *Pack
Like ReadURL but panics on error.

Read

func Read(r io.Reader) (*Pack, error)
Reads a resource pack from a byte stream.
r
io.Reader
Reader containing the resource pack archive data

Pack Type

type Pack struct {
    // Internal fields
}
Represents a compiled resource pack.

Metadata Methods

Name

func (pack *Pack) Name() string
Returns the resource pack name.

UUID

func (pack *Pack) UUID() uuid.UUID
Returns the resource pack UUID.

Description

func (pack *Pack) Description() string
Returns the resource pack description.

Version

func (pack *Pack) Version() string
Returns the version as a string (e.g., “1.0.0”).

Modules

func (pack *Pack) Modules() []Module
Returns all modules in the resource pack.

Dependencies

func (pack *Pack) Dependencies() []Dependency
Returns all dependency resource packs.

Content Type Methods

HasScripts

func (pack *Pack) HasScripts() bool
Returns true if the pack contains client scripts.

HasBehaviours

func (pack *Pack) HasBehaviours() bool
Returns true if the pack contains behaviours or scripts.

HasTextures

func (pack *Pack) HasTextures() bool
Returns true if the pack contains textures.

HasWorldTemplate

func (pack *Pack) HasWorldTemplate() bool
Returns true if the pack is a world template (contains level.dat).

Network Methods

DownloadURL

func (pack *Pack) DownloadURL() string
Returns the URL for HTTP download. Empty string means RakNet transfer.

Checksum

func (pack *Pack) Checksum() [32]byte
Returns the SHA256 checksum of the pack.

Len

func (pack *Pack) Len() int
Returns the total size in bytes.

DataChunkCount

func (pack *Pack) DataChunkCount(length int) int
Calculates the number of chunks for a given chunk size.
length
int
The size of each chunk in bytes

ReadAt

func (pack *Pack) ReadAt(b []byte, off int64) (n int, err error)
Reads data from the pack at a specific offset.

Encryption Methods

Encrypted

func (pack *Pack) Encrypted() bool
Returns true if the pack is encrypted.

ContentKey

func (pack *Pack) ContentKey() string
Returns the encryption key (empty if not encrypted).

WithContentKey

func (pack Pack) WithContentKey(key string) *Pack
Creates a copy with an encryption key set.
key
string
The encryption key to set

Other Methods

ReadFile

func (p *Pack) ReadFile(filePath string) ([]byte, error)
Reads a specific file from within the pack.
filePath
string
Path to the file within the pack

Manifest

func (pack *Pack) Manifest() Manifest
Returns the pack’s manifest data.

Manifest Type

type Manifest struct {
    FormatVersion int
    Header        Header
    Modules       []Module
    Dependencies  []Dependency
}
type Header struct {
    Name        string
    Description string
    UUID        uuid.UUID
    Version     [3]int
    MinEngineVersion [3]int
}

Module

type Module struct {
    Type        string
    UUID        uuid.UUID
    Version     [3]int
    Description string
}
Module types include:
  • "resources" - Textures and assets
  • "data" - Behaviour packs
  • "client_data" - Client scripts

Dependency

type Dependency struct {
    UUID    uuid.UUID
    Version [3]int
}

Example Usage

Loading a Resource Pack

import "github.com/sandertv/gophertunnel/minecraft/resource"

// From a directory
pack, err := resource.ReadPath("./my_resource_pack")
if err != nil {
    panic(err)
}

// From a .zip/.mcpack file
pack, err = resource.ReadPath("./pack.mcpack")

// From a URL
pack, err = resource.ReadURL("https://example.com/pack.mcpack")

Pack Information

fmt.Println("Name:", pack.Name())
fmt.Println("UUID:", pack.UUID())
fmt.Println("Version:", pack.Version())
fmt.Println("Size:", pack.Len(), "bytes")

if pack.HasTextures() {
    fmt.Println("Pack has textures")
}

if pack.HasBehaviours() {
    fmt.Println("Pack has behaviours")
}

Using with Listener

pack := resource.MustReadPath("./my_pack")

config := minecraft.ListenConfig{
    ResourcePacks: []*resource.Pack{pack},
    TexturePacksRequired: true,
}

listener, err := config.Listen("raknet", ":19132")
if err != nil {
    panic(err)
}

Reading Pack Files

// Read a specific file from the pack
data, err := pack.ReadFile("textures/blocks/stone.png")
if err != nil {
    panic(err)
}

// Use the file data
img, err := png.Decode(bytes.NewReader(data))

Encrypted Packs

pack := resource.MustReadPath("./encrypted_pack")

// Set encryption key
encryptedPack := pack.WithContentKey("my-encryption-key")

if encryptedPack.Encrypted() {
    fmt.Println("Pack is encrypted with key:", encryptedPack.ContentKey())
}