leveldb

package
v0.0.0-...-cbdf446 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagData2D         = 45
	TagData2DLegacy   = 46
	TagSubChunkPrefix = 47
	TagLegacyTerrain  = 48
	TagBlockEntity    = 49
	TagEntity         = 50
	TagPendingTicks   = 51
	TagBlockExtraData = 52
	TagBiomeState     = 53
	TagFinalizedState = 54
	TagVersion        = 118
)
View Source
const (
	SubChunkVersionV120  = 0
	SubChunkVersionV1213 = 1
	SubChunkVersionV130  = 8
)
View Source
const (
	// LevelDataFile is a location of level.dat
	LevelDataFile = "level.dat"

	// DBPath is a location of level data
	DBPath = "/db"
)
View Source
const BlockStorageSize = 16 * 16 * 16

BlockStorageSize is a size of BlockStorage

View Source
const DefaultStorageIndex = 0

DefaultStorageIndex is the default index for StorageIndex

Variables

View Source
var (
	TagLevelName = "LevelName"
	TagGameType  = "GameType"
	TagSpawnX    = "SpawnX"
	TagSpawnY    = "SpawnY"
	TagSpawnZ    = "SpawnZ"
)
View Source
var DefaultOptions = &opt.Options{
	Filter:      filter.NewBloomFilter(10),
	WriteBuffer: 4 * 1024 * 1024,
}

DefaultOptions is a default option for leveldb You can use at NewWithOptions() and LoadWithOptions()

View Source
var DefaultProperties = &Properties{
	Data: &nbt.Compound{
		Value: map[string]nbt.Tag{
			TagLevelName: nbt.NewStringTag("", ""),
			TagGameType:  nbt.NewByteTag("", int8(level.Survival)),
			TagSpawnX:    nbt.NewIntTag("", 0),
			TagSpawnY:    nbt.NewIntTag("", 0),
			TagSpawnZ:    nbt.NewIntTag("", 0),
		},
	},
	Version: 8,
}

DefaultProperties is the default properties for level.dat

Functions

func SaveLevelData

func SaveLevelData(path string, pro *Properties) error

SaveLevelData saves properties to level.dat

Types

type BlockStorage

type BlockStorage struct {
	Palettes []*RawBlockState
	Blocks   []uint16
}

BlockStorage is a storage contains blocks of a subchunk

func NewBlockStorage

func NewBlockStorage() *BlockStorage

NewBlockStorage returns new BlockStorage

func (BlockStorage) At

func (BlockStorage) At(x, y, z int) int

At returns a index for Blocks at blockstorage coordinates

func (*BlockStorage) GetBlock

func (storage *BlockStorage) GetBlock(x, y, z int) (*RawBlockState, error)

GetBlock returns the BlockState at blockstorage coordinates

func (*BlockStorage) SetBlock

func (storage *BlockStorage) SetBlock(x, y, z int, bs *RawBlockState) error

SetBlock set the BlockState at blockstorage coordinates

func (BlockStorage) Vaild

func (BlockStorage) Vaild(x, y, z int) error

Vaild vailds blockstorage coordinates

type Chunk

type Chunk struct {
	Finalization Finalization

	DefaultBlock        *RawBlockState
	DefaultStorageIndex int
	// contains filtered or unexported fields
}

Chunk is a block area which splits a world by 16x16 It has informations of block, biomes and etc...

func NewChunk

func NewChunk(x, y int) *Chunk

NewChunk returns new Chunk

func (*Chunk) AtSubChunk

func (chunk *Chunk) AtSubChunk(y int) (*SubChunk, bool)

AtSubChunk returns a sub chunk

func (*Chunk) Biome

func (chunk *Chunk) Biome(x, y int) byte

Biome returns biome

func (*Chunk) BlockEntities

func (chunk *Chunk) BlockEntities() []*nbt.Compound

BlockEntities returns block entities of nbt data

func (*Chunk) Entities

func (chunk *Chunk) Entities() []*nbt.Compound

Entities returns entities of nbt data

func (*Chunk) GetBlock

func (chunk *Chunk) GetBlock(x, y, z int) (level.BlockState, error)

GetBlock gets a BlockState at a chunk coordinate

func (*Chunk) GetBlockAtStorage

func (chunk *Chunk) GetBlockAtStorage(x, y, z, index int) (*RawBlockState, error)

GetBlockAtStorage gets a BlockState at a chunk coordinate from storage of index

func (*Chunk) GetSubChunk

func (chunk *Chunk) GetSubChunk(index int) (*SubChunk, bool)

GetSubChunk returns a sub chunk

func (*Chunk) Height

func (chunk *Chunk) Height(x, y int) uint16

Height returns the height of the highest block at chunk coordinate

func (*Chunk) SetBiome

func (chunk *Chunk) SetBiome(x, y int, biome byte)

SetBiome set biome

func (*Chunk) SetBlock

func (chunk *Chunk) SetBlock(x, y, z int, bs level.BlockState) error

SetBlock set a BlockState at chunk coordinate

func (*Chunk) SetBlockAtStorage

func (chunk *Chunk) SetBlockAtStorage(x, y, z, index int, bs *RawBlockState) error

SetBlockAtStorage set a BlockState at chunk coordinate to storage of index

func (*Chunk) SetBlockEntities

func (chunk *Chunk) SetBlockEntities(entities []*nbt.Compound)

SetBlockEntities set block entities of nbt data

func (*Chunk) SetEntities

func (chunk *Chunk) SetEntities(entities []*nbt.Compound)

SetEntities set entities of nbt data

func (*Chunk) SetX

func (chunk *Chunk) SetX(x int)

SetX set x coordinate

func (*Chunk) SetY

func (chunk *Chunk) SetY(y int)

SetY set y coordinate

func (*Chunk) SubChunks

func (chunk *Chunk) SubChunks() []*SubChunk

SubChunks returns sub chunks

func (*Chunk) Vaild

func (chunk *Chunk) Vaild(x, y, z int) bool

Vaild vailds a chunk coordinates

func (*Chunk) X

func (chunk *Chunk) X() int

X returns x coordinate

func (*Chunk) Y

func (chunk *Chunk) Y() int

Y returns y coordinate

type ChunkFormat

type ChunkFormat interface {
	// Read reads a chunk by x, y and dimension
	Read(db *lvldb.DB, x, y int, dimension level.Dimension) (*Chunk, error)
	Write(db *lvldb.DB, chunk *Chunk, dimension level.Dimension) error
	Exist(db *lvldb.DB, x, y int, dimension level.Dimension) (bool, error)
}

ChunkFormat is a chunk format reader and writer

type ChunkFormatV100

type ChunkFormatV100 struct {
	// SubChunkVersion is used a format when it writes a chunk
	SubChunkVersion int

	DisabledData2D      bool
	DisabledEntity      bool
	DisabledBlockEntity bool
}

ChunkFormatV100 is a chunk format v1.0.0 or after

func (*ChunkFormatV100) Exist

func (format *ChunkFormatV100) Exist(db *lvldb.DB, x, y int, dimension level.Dimension) (bool, error)

Exist returns whether a chunk is generated

func (*ChunkFormatV100) Read

func (format *ChunkFormatV100) Read(db *lvldb.DB, x, y int, dimension level.Dimension) (*Chunk, error)

Read reads a chunk

func (*ChunkFormatV100) ReadCompounds

func (format *ChunkFormatV100) ReadCompounds(b []byte) ([]*nbt.Compound, error)

ReadCompounds reads compounds

func (*ChunkFormatV100) ReadSubChunk

func (format *ChunkFormatV100) ReadSubChunk(y byte, b []byte) (sub *SubChunk, err error)

ReadSubChunk reads a subchunk from bytes b

func (*ChunkFormatV100) Write

func (format *ChunkFormatV100) Write(db *lvldb.DB, chunk *Chunk, dimension level.Dimension) error

Write writes a chunk

func (*ChunkFormatV100) WriteCompounds

func (format *ChunkFormatV100) WriteCompounds(tags []*nbt.Compound) ([]byte, error)

WriteCompounds writes compounds

func (*ChunkFormatV100) WriteSubChunk

func (format *ChunkFormatV100) WriteSubChunk(sub *SubChunk) (b []byte, err error)

WriteSubChunk reads a subchunk from bytes b

type Finalization

type Finalization int

Finalization show the status of a chunk It's introduced in mcpe v1.1

const (
	// Unsupported is unsupported finalization by the chunk format
	Unsupported Finalization = iota

	// NotGenerated is not generated a chunk if it's set
	NotGenerated

	// NotSpawnMobs is not spawned mobs if it's set
	NotSpawnMobs

	// Generated is generated a chunk if it's set
	Generated
)

func GetFinalization

func GetFinalization(id int) (Finalization, bool)

GetFinalization returns Finalization by id

func (Finalization) ID

func (f Finalization) ID() byte

type LevelDB

type LevelDB struct {
	Database *lvldb.DB

	Format ChunkFormat
	// contains filtered or unexported fields
}

LevelDB is a level format for mcbe

func Load

func Load(path string) (*LevelDB, error)

Load loads a leveldb level

func LoadWithOptions

func LoadWithOptions(path string, options *opt.Options) (*LevelDB, error)

LoadWithOptions loads a leveldb level with leveldb options

func New

func New(path string) (*LevelDB, error)

New returns new LevelDB The path is a directory for save

func NewWithOptions

func NewWithOptions(path string, options *opt.Options) (*LevelDB, error)

NewWithOptions returns new LevelDB with leveldb options

func (*LevelDB) AllProperties

func (lvl *LevelDB) AllProperties() *nbt.Compound

AllProperties returns all properties

func (*LevelDB) Chunk

func (lvl *LevelDB) Chunk(x, y int) (level.Chunk, error)

Chunk returns a chunk. If a chunk is not loaded, it will be loaded

func (*LevelDB) Close

func (lvl *LevelDB) Close() error

Close closes database of leveldb You must close after you use the format It's should not run other functions after format is closed

func (*LevelDB) Dimension

func (lvl *LevelDB) Dimension() level.Dimension

Dimension return dimension of the level

func (*LevelDB) GameType

func (lvl *LevelDB) GameType() level.GameType

GameType returns the default game mode of level

func (*LevelDB) GenerateChunk

func (lvl *LevelDB) GenerateChunk(x, y int) error

GenerateChunk generates a chunk and loads

func (*LevelDB) HasGeneratedChunk

func (lvl *LevelDB) HasGeneratedChunk(x, y int) (bool, error)

HasGeneratedChunk returns whether the chunk is generaged

func (*LevelDB) IsLoadedChunk

func (lvl *LevelDB) IsLoadedChunk(x, y int) bool

IsLoadedChunk returns weather a chunk is loaded.

func (*LevelDB) LoadChunk

func (lvl *LevelDB) LoadChunk(x, y int, create bool) error

LoadChunk loads a chunk. If create is enabled, generates a chunk if it doesn't exist

func (*LevelDB) LoadedChunks

func (lvl *LevelDB) LoadedChunks() []level.Chunk

LoadedChunks returns loaded chunks.

func (*LevelDB) Name

func (lvl *LevelDB) Name() string

Name returns name of level

func (*LevelDB) PropertiesVersion

func (lvl *LevelDB) PropertiesVersion() int

PropertiesVersion returns properties version

func (*LevelDB) Property

func (lvl *LevelDB) Property(name string) (tag nbt.Tag, ok bool)

Property returns a property of level.dat

func (*LevelDB) SaveChunk

func (lvl *LevelDB) SaveChunk(x, y int) error

SaveChunk saves a chunk.

func (*LevelDB) SaveChunks

func (lvl *LevelDB) SaveChunks() error

SaveChunks saves all chunks.

func (*LevelDB) SetAllProperties

func (lvl *LevelDB) SetAllProperties(com *nbt.Compound)

SetAllProperties sets all properties

func (*LevelDB) SetDimension

func (lvl *LevelDB) SetDimension(dimension level.Dimension)

SetDimension set dimension of the level

func (*LevelDB) SetGameType

func (lvl *LevelDB) SetGameType(typ level.GameType)

SetGameType sets the game mode of level

func (*LevelDB) SetName

func (lvl *LevelDB) SetName(name string)

SetName sets the name of level

func (*LevelDB) SetPropertiesVersion

func (lvl *LevelDB) SetPropertiesVersion(ver int)

SetPropertiesVersion sets properties version

func (*LevelDB) SetProperty

func (lvl *LevelDB) SetProperty(tag nbt.Tag)

SetProperty sets a property

func (*LevelDB) SetSpawn

func (lvl *LevelDB) SetSpawn(x, y, z int)

SetSpawn sets the default spawn of level

func (*LevelDB) Spawn

func (lvl *LevelDB) Spawn() (x, y, z int)

Spawn returns the default spawn of level

func (*LevelDB) UnloadChunk

func (lvl *LevelDB) UnloadChunk(x, y int) error

UnloadChunk unloads a chunk.

type Properties

type Properties struct {
	Data    *nbt.Compound
	Version int
}

Properties is data of level from level.dat

func LoadLevelData

func LoadLevelData(path string) (*Properties, error)

LoadLevelData loads properties from level.dat

type RawBlockState

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

RawBlockState is a raw block information

func FromRawBlockState

func FromRawBlockState(bs level.BlockState) (*RawBlockState, error)

FromRawBlockState returns new RawBlockState

func NewRawBlockState

func NewRawBlockState(name string, value int) *RawBlockState

NewRawBlockState returns new RawBlockState

func (*RawBlockState) Equal

func (block *RawBlockState) Equal(b *RawBlockState) bool

Equal returns whether block is equal b

func (*RawBlockState) Name

func (block *RawBlockState) Name() string

Name returns block name

func (*RawBlockState) ToBlockIDMeta

func (block *RawBlockState) ToBlockIDMeta() (id int, meta int, ok bool)

ToBlockIDMeta returns block id and meta If it's not supported, returns false for ok

func (*RawBlockState) ToBlockNameMeta

func (block *RawBlockState) ToBlockNameMeta() (name string, meta int, ok bool)

ToBlockNameMeta returns block name and meta If it's not supported, returns false for ok

func (*RawBlockState) ToBlockNameProperties

func (block *RawBlockState) ToBlockNameProperties() (name string, properties map[string]string, ok bool)

ToBlockNameProperties returns block name and properties If it's not supported, returns false for ok

func (*RawBlockState) Value

func (block *RawBlockState) Value() int

Value returns block value

type StorageType

type StorageType int

StorageType is a type of BlockStorage

const (
	TypePalette1  StorageType = 1
	TypePalette2  StorageType = 2
	TypePalette3  StorageType = 3
	TypePalette4  StorageType = 4
	TypePalette5  StorageType = 5
	TypePalette6  StorageType = 6
	TypePalette8  StorageType = 8
	TypePalette16 StorageType = 16
)

func GetStorageTypeFromSize

func GetStorageTypeFromSize(size uint) StorageType

GetStorageTypeFromSize returns

func (StorageType) BitsPerBlock

func (t StorageType) BitsPerBlock() int

BitsPerBlock retunrs bits per a block for BlockStorage

func (StorageType) PaletteSize

func (t StorageType) PaletteSize() int

PaletteSize returns a size of palette for StorageType

type SubChunk

type SubChunk struct {
	Y byte

	Storages []*BlockStorage
}

SubChunk is a 16x16x16 blocks segment for a chunk

func NewSubChunk

func NewSubChunk(y byte) *SubChunk

NewSubChunk returns new SubChunk

func (*SubChunk) GetBlock

func (sub *SubChunk) GetBlock(x, y, z, index int) (*RawBlockState, error)

GetBlock returns BlockState at the subchunk coordinates

func (*SubChunk) GetBlockStorage

func (sub *SubChunk) GetBlockStorage(index int) (*BlockStorage, bool)

GetBlockStorage returns BlockStorage which subchunk contained with index

func (*SubChunk) SetBlock

func (sub *SubChunk) SetBlock(x, y, z, index int, bs *RawBlockState) error

SetBlock returns BlockState at the subchunk coordinates

type SubChunkFormat

type SubChunkFormat interface {
	Read(y byte, b []byte) (*SubChunk, error)
}

SubChunkFormat is a formatter for subchunk

type SubChunkFormatV1213

type SubChunkFormatV1213 struct {
	OldFormat bool
}

SubChunkFormatV1213 is a subchunk formatter v1.2.13 or after

func (*SubChunkFormatV1213) Read

func (format *SubChunkFormatV1213) Read(y byte, b []byte) (*SubChunk, error)

func (*SubChunkFormatV1213) ReadBlockStorage

func (format *SubChunkFormatV1213) ReadBlockStorage(stream *binary.Stream) (*BlockStorage, error)

ReadBlockStorage reads a block storage

func (*SubChunkFormatV1213) Write

func (format *SubChunkFormatV1213) Write(sub *SubChunk) ([]byte, error)

func (*SubChunkFormatV1213) WriteBlockStorage

func (format *SubChunkFormatV1213) WriteBlockStorage(stream *binary.Stream, storage *BlockStorage) error

WriteBlockStorage writes a block storage

Jump to

Keyboard shortcuts

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