mcdb

package
v0.9.16 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: MIT Imports: 19 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnIterator added in v0.9.5

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

ColumnIterator iterates over a DB's position/column pairs in key order.

When an error is encountered, any call to Next will return false and will yield no position/chunk pairs. The error can be queried by calling the Error method. Calling Release is still necessary.

An iterator must be released after use, but it is not necessary to read an iterator until exhaustion. Also, an iterator is not necessarily safe for concurrent use, but it is safe to use multiple iterators concurrently, with each in a dedicated goroutine.

func (*ColumnIterator) Column added in v0.9.5

func (iter *ColumnIterator) Column() *world.Column

Column returns the value of the current position/column pair, or nil if none.

func (*ColumnIterator) Dimension added in v0.9.5

func (iter *ColumnIterator) Dimension() world.Dimension

Dimension returns the dimension of the current position/column pair, or nil if none.

func (*ColumnIterator) Error added in v0.9.5

func (iter *ColumnIterator) Error() error

Error returns any accumulated error. Exhausting all the key/value pairs is not considered to be an error.

func (*ColumnIterator) Next added in v0.9.5

func (iter *ColumnIterator) Next() bool

Next moves the iterator to the next key/value pair. It returns false if the iterator is exhausted.

func (*ColumnIterator) Position added in v0.9.5

func (iter *ColumnIterator) Position() world.ChunkPos

Position returns the position of the current position/column pair.

func (*ColumnIterator) Release added in v0.9.5

func (iter *ColumnIterator) Release()

Release releases associated resources. Release should always success and can be called multiple times without causing error.

type Config added in v0.9.5

type Config struct {
	// Log is the Logger that will be used to log errors and debug messages to.
	// If set to nil, a Logrus logger will be used.
	Log Logger
	// Compression specifies the compression to use for compressing new data in
	// the database. Decompression of the database will happen based on IDs
	// found in the compressed blocks and is therefore uninfluenced by this
	// field. If left empty, Compression will default to opt.FlateCompression.
	Compression opt.Compression
	// BlockSize specifies the size of blocks to be compressed. The default
	// value, when left empty, is 16KiB (16 * opt.KiB). Higher values generally
	// lead to better compression ratios at the expense of slightly higher
	// memory usage while (de)compressing.
	BlockSize int
	// ReadOnly opens the DB in read-only mode. This will leave the data in the
	// database unedited.
	ReadOnly bool

	// Entities is an EntityRegistry with all entity types registered that may
	// be read from the DB. Entities will default to entity.DefaultRegistry.
	Entities world.EntityRegistry
}

Config holds the optional parameters of a DB.

func (Config) Open added in v0.9.5

func (conf Config) Open(dir string) (*DB, error)

Open creates a new DB reading and writing from/to files under the path passed. If a world is present at the path, Open will parse its data and initialise the world with it. If the data cannot be parsed, an error is returned.

type DB added in v0.9.5

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

DB implements a world provider for the Minecraft world format, which is based on a leveldb database.

func Open added in v0.9.5

func Open(dir string) (*DB, error)

Open creates a new provider reading and writing from/to files under the path passed using default options. If a world is present at the path, Open will parse its data and initialise the world with it. If the data cannot be parsed, an error is returned.

func (*DB) Close added in v0.9.5

func (db *DB) Close() error

Close closes the provider, saving any file that might need to be saved, such as the level.dat.

func (*DB) LoadColumn added in v0.9.5

func (db *DB) LoadColumn(pos world.ChunkPos, dim world.Dimension) (*world.Column, error)

LoadColumn reads a world.Column from the DB at a position and dimension in the DB. If no column at that position exists, errors.Is(err, leveldb.ErrNotFound) equals true.

func (*DB) LoadPlayerSpawnPosition added in v0.9.5

func (db *DB) LoadPlayerSpawnPosition(id uuid.UUID) (pos cube.Pos, exists bool, err error)

LoadPlayerSpawnPosition loads the players spawn position stored in the level.dat from their UUID.

func (*DB) NewColumnIterator added in v0.9.5

func (db *DB) NewColumnIterator(r *IteratorRange) *ColumnIterator

NewColumnIterator returns a ColumnIterator that may be used to iterate over all position/chunk pairs in a database. An IteratorRange r may be passed to specify limits in terms of what chunks should be read. r may be set to nil to read all chunks from the DB.

func (*DB) SavePlayerSpawnPosition added in v0.9.5

func (db *DB) SavePlayerSpawnPosition(id uuid.UUID, pos cube.Pos) error

SavePlayerSpawnPosition saves the player spawn position passed to the levelDB database.

func (*DB) SaveSettings added in v0.9.5

func (db *DB) SaveSettings(s *world.Settings)

SaveSettings saves the world.Settings passed to the level.dat.

func (*DB) Settings added in v0.9.5

func (db *DB) Settings() *world.Settings

Settings returns the world.Settings of the world loaded by the DB.

func (*DB) StoreColumn added in v0.9.5

func (db *DB) StoreColumn(pos world.ChunkPos, dim world.Dimension, col *world.Column) error

StoreColumn stores a world.Column at a position and dimension in the DB. An error is returned if storing was unsuccessful.

type IteratorRange added in v0.9.5

type IteratorRange struct {
	// Min and Max limit what chunk positions are returned by a ColumnIterator.
	// A zero value for both Min and Max causes all positions to be within the
	// range.
	Min, Max world.ChunkPos
	// Dimension specifies what world.Dimension chunks should be accumulated
	// from. If nil, all dimensions will be read from.
	Dimension world.Dimension
}

IteratorRange is a range used to limit what columns are accumulated by a ColumnIterator.

type Logger added in v0.8.4

type Logger interface {
	Errorf(format string, a ...any)
	Debugf(format string, a ...any)
}

Logger is a logger implementation that may be passed to the Log field of Config. World will send errors and debug messages to this Logger when appropriate.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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