Skip to content

server.resource

Constants #

const pack_chunk_size = 1024 * 1024

Bedrock caps resource pack chunks at 1 MiB.

const pack_type_resources = 6

pack_type sent in ResourcePackDataInfo - 6 is a resources pack.

fn discover #

fn discover(dir string) []string

discover lists the pack files (.zip / .mcpack) inside dir.

fn new_cdn_pack #

fn new_cdn_pack(uuid string, version string, url string, size u64) !&ResourcePack

new_cdn_pack builds a pack the client downloads from a url instead of over the wire. size may be 0 when unknown.

fn new_local_pack #

fn new_local_pack(path string) !&ResourcePack

new_local_pack reads a pack file, extracts its uuid/version from the embedded manifest.json and hashes its bytes for the chunked-upload handshake.

fn parse_cdn_packs #

fn parse_cdn_packs(encoded string) []&ResourcePack

parse_cdn_packs decodes the vedrock.yml cdn-packs value. Format: uuid,version,url,size ; uuid,version,url,size size is optional. Malformed entries are skipped.

struct PackRegistry #

@[heap]
struct PackRegistry {
pub mut:
	packs       []&ResourcePack
	must_accept bool
mut:
	by_id map[string]&ResourcePack
}

fn (PackRegistry) add #

fn (mut r PackRegistry) add(pack &ResourcePack)

fn (PackRegistry) set_must_accept #

fn (mut r PackRegistry) set_must_accept(value bool)

fn (PackRegistry) is_empty #

fn (r &PackRegistry) is_empty() bool

fn (PackRegistry) find #

fn (r &PackRegistry) find(id string) ?&ResourcePack

find resolves a pack from an id the client sends. The id is normally "uuid_version"; fall back to matching the uuid alone.

struct ResourcePack #

@[heap]
struct ResourcePack {
pub:
	uuid    string
	version string
	size    u64
	sha256  string
	cdn_url string
mut:
	uuid_raw []u8
	data     []u8
}

ResourcePack is a single pack the server offers to clients. Local packs carry their raw zip bytes for chunked upload; CDN packs carry only a url and let the client download the file itself.

fn (ResourcePack) id #

fn (p &ResourcePack) id() string

fn (ResourcePack) is_cdn #

fn (p &ResourcePack) is_cdn() bool

fn (ResourcePack) uuid_bytes #

fn (p &ResourcePack) uuid_bytes() []u8

fn (ResourcePack) chunk_count #

fn (p &ResourcePack) chunk_count() int

fn (ResourcePack) chunk #

fn (p &ResourcePack) chunk(index int) []u8