storage

package
v0.0.0-...-ae70652 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package storage implements Minecraft's Anvil region file format for persisting chunk and player data.

Index

Constants

View Source
const DataVersion = 4189

DataVersion for the current protocol (1.21.11 = 4189).

Variables

This section is empty.

Functions

func ChunkToNBT

func ChunkToNBT(col *chunks.ChunkColumn) ([]byte, error)

ChunkToNBT serializes a ChunkColumn to Anvil-format NBT bytes (uncompressed).

func NBTToChunk

func NBTToChunk(data []byte) (*chunks.ChunkColumn, error)

NBTToChunk deserializes a ChunkColumn from Anvil-format NBT bytes.

func SavePlayer

func SavePlayer(dir, uuid string, pd *PlayerData) error

SavePlayer writes player data to <dir>/<uuid>.dat (gzip-compressed NBT).

Types

type InventorySlot

type InventorySlot struct {
	Slot  int8
	ID    string // e.g. "minecraft:stone"
	Count int32
}

InventorySlot represents one item in a player's inventory.

type PlayerData

type PlayerData struct {
	X, Y, Z    float64
	Yaw, Pitch float32
	Dimension  string
	Gamemode   int32
	Inventory  []InventorySlot
	HeldSlot   int32
}

PlayerData holds the data persisted for a player.

func LoadPlayer

func LoadPlayer(dir, uuid string) (*PlayerData, error)

LoadPlayer reads player data from <dir>/<uuid>.dat. Returns nil, nil if file doesn't exist.

type RegionFile

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

RegionFile handles reading and writing chunks in one .mca region file. Each region file holds up to 32×32 = 1024 chunks.

func OpenRegion

func OpenRegion(path string) (*RegionFile, error)

OpenRegion opens or creates a region file at the given path.

func (*RegionFile) Close

func (r *RegionFile) Close() error

Close closes the underlying file.

func (*RegionFile) HasChunk

func (r *RegionFile) HasChunk(chunkX, chunkZ int32) bool

HasChunk returns true if the region file contains data for the given chunk.

func (*RegionFile) ReadChunk

func (r *RegionFile) ReadChunk(chunkX, chunkZ int32) ([]byte, error)

ReadChunk reads and decompresses chunk data. Returns nil, nil if chunk is absent.

func (*RegionFile) WriteChunk

func (r *RegionFile) WriteChunk(chunkX, chunkZ int32, data []byte) error

WriteChunk compresses and writes chunk data to the region file.

type RegionStorage

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

RegionStorage manages a directory of region files with an LRU cache.

func NewRegionStorage

func NewRegionStorage(dir string) (*RegionStorage, error)

NewRegionStorage creates a storage backed by .mca files in dir.

func (*RegionStorage) Close

func (rs *RegionStorage) Close() error

Close closes all open region files.

func (*RegionStorage) HasChunk

func (rs *RegionStorage) HasChunk(chunkX, chunkZ int32) bool

HasChunk checks if a chunk exists in the appropriate region file.

func (*RegionStorage) ReadChunk

func (rs *RegionStorage) ReadChunk(chunkX, chunkZ int32) ([]byte, error)

ReadChunk reads a chunk from the appropriate region file. Returns nil, nil if absent.

func (*RegionStorage) WriteChunk

func (rs *RegionStorage) WriteChunk(chunkX, chunkZ int32, data []byte) error

WriteChunk writes a chunk to the appropriate region file.

Jump to

Keyboard shortcuts

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