Documentation ¶
Index ¶
- Constants
- Variables
- func SaveLevelData(path string, pro *Properties) error
- type BlockStorage
- type Chunk
- func (chunk *Chunk) AtSubChunk(y int) (*SubChunk, bool)
- func (chunk *Chunk) Biome(x, y int) byte
- func (chunk *Chunk) BlockEntities() []*nbt.Compound
- func (chunk *Chunk) Entities() []*nbt.Compound
- func (chunk *Chunk) GetBlock(x, y, z int) (level.BlockState, error)
- func (chunk *Chunk) GetBlockAtStorage(x, y, z, index int) (*RawBlockState, error)
- func (chunk *Chunk) GetSubChunk(index int) (*SubChunk, bool)
- func (chunk *Chunk) Height(x, y int) uint16
- func (chunk *Chunk) SetBiome(x, y int, biome byte)
- func (chunk *Chunk) SetBlock(x, y, z int, bs level.BlockState) error
- func (chunk *Chunk) SetBlockAtStorage(x, y, z, index int, bs *RawBlockState) error
- func (chunk *Chunk) SetBlockEntities(entities []*nbt.Compound)
- func (chunk *Chunk) SetEntities(entities []*nbt.Compound)
- func (chunk *Chunk) SetX(x int)
- func (chunk *Chunk) SetY(y int)
- func (chunk *Chunk) SubChunks() []*SubChunk
- func (chunk *Chunk) Vaild(x, y, z int) bool
- func (chunk *Chunk) X() int
- func (chunk *Chunk) Y() int
- type ChunkFormat
- type ChunkFormatV100
- func (format *ChunkFormatV100) Exist(db *lvldb.DB, x, y int, dimension level.Dimension) (bool, error)
- func (format *ChunkFormatV100) Read(db *lvldb.DB, x, y int, dimension level.Dimension) (*Chunk, error)
- func (format *ChunkFormatV100) ReadCompounds(b []byte) ([]*nbt.Compound, error)
- func (format *ChunkFormatV100) ReadSubChunk(y byte, b []byte) (sub *SubChunk, err error)
- func (format *ChunkFormatV100) Write(db *lvldb.DB, chunk *Chunk, dimension level.Dimension) error
- func (format *ChunkFormatV100) WriteCompounds(tags []*nbt.Compound) ([]byte, error)
- func (format *ChunkFormatV100) WriteSubChunk(sub *SubChunk) (b []byte, err error)
- type Finalization
- type LevelDB
- func (lvl *LevelDB) AllProperties() *nbt.Compound
- func (lvl *LevelDB) Chunk(x, y int) (level.Chunk, error)
- func (lvl *LevelDB) Close() error
- func (lvl *LevelDB) Dimension() level.Dimension
- func (lvl *LevelDB) GameType() level.GameType
- func (lvl *LevelDB) GenerateChunk(x, y int) error
- func (lvl *LevelDB) HasGeneratedChunk(x, y int) (bool, error)
- func (lvl *LevelDB) IsLoadedChunk(x, y int) bool
- func (lvl *LevelDB) LoadChunk(x, y int, create bool) error
- func (lvl *LevelDB) LoadedChunks() []level.Chunk
- func (lvl *LevelDB) Name() string
- func (lvl *LevelDB) PropertiesVersion() int
- func (lvl *LevelDB) Property(name string) (tag nbt.Tag, ok bool)
- func (lvl *LevelDB) SaveChunk(x, y int) error
- func (lvl *LevelDB) SaveChunks() error
- func (lvl *LevelDB) SetAllProperties(com *nbt.Compound)
- func (lvl *LevelDB) SetDimension(dimension level.Dimension)
- func (lvl *LevelDB) SetGameType(typ level.GameType)
- func (lvl *LevelDB) SetName(name string)
- func (lvl *LevelDB) SetPropertiesVersion(ver int)
- func (lvl *LevelDB) SetProperty(tag nbt.Tag)
- func (lvl *LevelDB) SetSpawn(x, y, z int)
- func (lvl *LevelDB) Spawn() (x, y, z int)
- func (lvl *LevelDB) UnloadChunk(x, y int) error
- type Properties
- type RawBlockState
- func (block *RawBlockState) Equal(b *RawBlockState) bool
- func (block *RawBlockState) Name() string
- func (block *RawBlockState) ToBlockIDMeta() (id int, meta int, ok bool)
- func (block *RawBlockState) ToBlockNameMeta() (name string, meta int, ok bool)
- func (block *RawBlockState) ToBlockNameProperties() (name string, properties map[string]string, ok bool)
- func (block *RawBlockState) Value() int
- type StorageType
- type SubChunk
- type SubChunkFormat
- type SubChunkFormatV1213
- func (format *SubChunkFormatV1213) Read(y byte, b []byte) (*SubChunk, error)
- func (format *SubChunkFormatV1213) ReadBlockStorage(stream *binary.Stream) (*BlockStorage, error)
- func (format *SubChunkFormatV1213) Write(sub *SubChunk) ([]byte, error)
- func (format *SubChunkFormatV1213) WriteBlockStorage(stream *binary.Stream, storage *BlockStorage) error
Constants ¶
const ( TagData2D = 45 TagData2DLegacy = 46 TagSubChunkPrefix = 47 TagLegacyTerrain = 48 TagBlockEntity = 49 TagEntity = 50 TagPendingTicks = 51 TagBlockExtraData = 52 TagBiomeState = 53 TagFinalizedState = 54 TagVersion = 118 )
const ( SubChunkVersionV120 = 0 SubChunkVersionV1213 = 1 SubChunkVersionV130 = 8 )
const ( // LevelDataFile is a location of level.dat LevelDataFile = "level.dat" // DBPath is a location of level data DBPath = "/db" )
const BlockStorageSize = 16 * 16 * 16
BlockStorageSize is a size of BlockStorage
const DefaultStorageIndex = 0
DefaultStorageIndex is the default index for StorageIndex
Variables ¶
var ( TagLevelName = "LevelName" TagGameType = "GameType" TagSpawnX = "SpawnX" TagSpawnY = "SpawnY" TagSpawnZ = "SpawnZ" )
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()
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 (*Chunk) AtSubChunk ¶
AtSubChunk returns a sub chunk
func (*Chunk) BlockEntities ¶
BlockEntities returns block 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 ¶
GetSubChunk returns a sub chunk
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 ¶
SetBlockEntities set block entities of nbt data
func (*Chunk) SetEntities ¶
SetEntities set entities of nbt data
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) 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 LoadWithOptions ¶
LoadWithOptions loads a leveldb level with leveldb options
func NewWithOptions ¶
NewWithOptions returns new LevelDB with leveldb options
func (*LevelDB) AllProperties ¶
AllProperties returns all properties
func (*LevelDB) Close ¶
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) GenerateChunk ¶
GenerateChunk generates a chunk and loads
func (*LevelDB) HasGeneratedChunk ¶
HasGeneratedChunk returns whether the chunk is generaged
func (*LevelDB) IsLoadedChunk ¶
IsLoadedChunk returns weather a chunk is loaded.
func (*LevelDB) LoadChunk ¶
LoadChunk loads a chunk. If create is enabled, generates a chunk if it doesn't exist
func (*LevelDB) LoadedChunks ¶
LoadedChunks returns loaded chunks.
func (*LevelDB) PropertiesVersion ¶
PropertiesVersion returns properties version
func (*LevelDB) SetAllProperties ¶
SetAllProperties sets all properties
func (*LevelDB) SetDimension ¶
SetDimension set dimension of the level
func (*LevelDB) SetGameType ¶
SetGameType sets the game mode of level
func (*LevelDB) SetPropertiesVersion ¶
SetPropertiesVersion sets properties version
func (*LevelDB) SetProperty ¶
SetProperty sets a property
func (*LevelDB) UnloadChunk ¶
UnloadChunk unloads a chunk.
type Properties ¶
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) 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
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 (*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
type SubChunkFormat ¶
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