Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeBiomes(c *Chunk, e Encoding) []byte
- func EncodeSubChunk(s *SubChunk, e Encoding, pe PaletteEncoding, subChunkVer subChunkVersion, ...) []byte
- func NetworkEncode(air uint32, c *Chunk, oldFormat bool, pe PaletteEncoding) ([]byte, error)
- type BlockPaletteEncoding
- type Chunk
- func (chunk *Chunk) Biome(x uint8, y int16, z uint8) uint32
- func (chunk *Chunk) BiomeSub() []*PalettedStorage
- func (chunk *Chunk) Block(x uint8, y int16, z uint8, layer uint8) uint32
- func (chunk *Chunk) Compact()
- func (chunk *Chunk) HighestBlock(x, z uint8) int16
- func (chunk *Chunk) Range() cube.Range
- func (chunk *Chunk) SetBiome(x uint8, y int16, z uint8, biome uint32)
- func (chunk *Chunk) SetBlock(x uint8, y int16, z uint8, layer uint8, block uint32)
- func (chunk *Chunk) Sub() []*SubChunk
- type Encoding
- type NetworkPersistentEncoding
- type Palette
- type PaletteEncoding
- type PalettedStorage
- type SubChunk
Constants ¶
const ( // SubChunkVersion is the current version of the written sub chunks, specifying the format they are // written on disk and over network. SubChunkVersion = 9 )
Variables ¶
var ( // SubChunkVersion9 subChunkVersion9 SubChunkVersion9 subChunkVersion9 // SubChunkVersion8 subChunkVersion8 SubChunkVersion8 subChunkVersion8 // NetworkEncoding is the Encoding used for sending a Chunk over network. It does not use NBT and writes varints. NetworkEncoding networkEncoding // BiomePaletteEncoding is the paletteEncoding used for encoding a palette of biomes. BiomePaletteEncoding biomePaletteEncoding )
Functions ¶
func EncodeBiomes ¶
EncodeBiomes encodes the biomes of a chunk into bytes. An Encoding may be passed to encode either for network or disk purposed, the most notable difference being that the network encoding generally uses varints and no NBT.
func EncodeSubChunk ¶
func EncodeSubChunk(s *SubChunk, e Encoding, pe PaletteEncoding, subChunkVer subChunkVersion, r cube.Range, ind int) []byte
EncodeSubChunk encodes a sub-chunk from a chunk into bytes. An Encoding may be passed to encode either for network or disk purposed, the most notable difference being that the network encoding generally uses varints and no NBT.
func NetworkEncode ¶
Types ¶
type BlockPaletteEncoding ¶
type BlockPaletteEncoding struct {
// contains filtered or unexported fields
}
BlockPaletteEncoding implements the encoding of block palettes to disk.
func NewBlockPaletteEncoding ¶
func NewBlockPaletteEncoding(block mapping.Block, version int32) BlockPaletteEncoding
NewBlockPaletteEncoding returns a new BlockPaletteEncoding using the block and version passed.
type Chunk ¶
Chunk is a segment in the world with a size of 16x16x256 blocks. A chunk contains multiple sub chunks and stores other information such as biomes. It is not safe to call methods on Chunk simultaneously from multiple goroutines.
func NetworkDecode ¶
func NetworkDecode(air uint32, buf *bytes.Buffer, count int, oldFormat bool, r cube.Range, pse Encoding, pe PaletteEncoding) (*Chunk, error)
NetworkDecode decodes the network serialised data passed into a Chunk if successful. If not, the chunk returned is nil and the error non-nil. The sub chunk count passed must be that found in the LevelChunk packet. noinspection GoUnusedExportedFunction
func (*Chunk) BiomeSub ¶
func (chunk *Chunk) BiomeSub() []*PalettedStorage
BiomeSub returns a list of all biome sub chunks present in the chunk.
func (*Chunk) Block ¶
Block returns the runtime ID of the block at a given x, y and z in a chunk at the given layer. If no sub chunk exists at the given y, the block is assumed to be air.
func (*Chunk) Compact ¶
func (chunk *Chunk) Compact()
Compact compacts the chunk as much as possible, getting rid of any sub chunks that are empty, and compacts all storages in the sub chunks to occupy as little space as possible. Compact should be called right before the chunk is saved in order to optimise the storage space.
func (*Chunk) HighestBlock ¶
HighestBlock iterates from the highest non-empty sub chunk downwards to find the Y value of the highest non-air block at an x and z. If no blocks are present in the column, 0 is returned.
type Encoding ¶
type Encoding interface { EncodePalette(buf *bytes.Buffer, p *Palette, e PaletteEncoding) DecodePalette(buf *bytes.Buffer, blockSize paletteSize, e PaletteEncoding) (*Palette, error) Network() byte }
Encoding is an encoding type used for Chunk encoding. Implementations of this interface are DiskEncoding and NetworkEncoding, which can be used to encode a Chunk to an intermediate disk or network representation respectively.
type NetworkPersistentEncoding ¶
type NetworkPersistentEncoding struct {
// contains filtered or unexported fields
}
NetworkPersistentEncoding implements the Chunk encoding for sending over network with a persistent palette.
func NewNetworkPersistentEncoding ¶
func NewNetworkPersistentEncoding(block mapping.Block, version int32) NetworkPersistentEncoding
NewNetworkPersistentEncoding returns a new NetworkPersistentEncoding using the block and version passed.
func (NetworkPersistentEncoding) DecodePalette ¶
func (n NetworkPersistentEncoding) DecodePalette(buf *bytes.Buffer, blockSize paletteSize, _ PaletteEncoding) (*Palette, error)
func (NetworkPersistentEncoding) EncodePalette ¶
func (n NetworkPersistentEncoding) EncodePalette(buf *bytes.Buffer, p *Palette, _ PaletteEncoding)
func (NetworkPersistentEncoding) Network ¶
func (n NetworkPersistentEncoding) Network() byte
type Palette ¶
type Palette struct {
// contains filtered or unexported fields
}
Palette is a palette of values that every PalettedStorage has. Storages hold 'pointers' to indices in this palette.
func (*Palette) Add ¶
Add adds a values to the Palette. It does not first check if the value was already set in the Palette. The index at which the value was added is returned. Another bool is returned indicating if the Palette was resized as a result of adding the value.
func (*Palette) Index ¶
Index loops through the values of the Palette and looks for the index of the given value. If the value could not be found, -1 is returned.
type PaletteEncoding ¶
type PaletteEncoding interface { Encode(buf *bytes.Buffer, v uint32) Decode(buf *bytes.Buffer) (uint32, error) }
PaletteEncoding is an encoding type used for Chunk encoding. It is used to encode different types of palettes (for example, blocks or biomes) differently.
type PalettedStorage ¶
type PalettedStorage struct {
// contains filtered or unexported fields
}
PalettedStorage is a storage of 4096 blocks encoded in a variable amount of uint32s, storages may have values with a bit size per block of 0, 1, 2, 3, 4, 5, 6, 8 or 16 bits. 3 of these formats have additional padding in every uint32 and an additional uint32 at the end, to cater for the blocks that don't fit. This padding is present when the storage has a block size of 3, 5 or 6 bytes. Methods on PalettedStorage must not be called simultaneously from multiple goroutines.
func (*PalettedStorage) At ¶
func (storage *PalettedStorage) At(x, y, z byte) uint32
At returns the value of the PalettedStorage at a given x, y and z.
func (*PalettedStorage) Equal ¶
func (storage *PalettedStorage) Equal(other *PalettedStorage) bool
Equal checks if two PalettedStorages are equal value wise. False is returned if either of the storages are nil.
func (*PalettedStorage) Palette ¶
func (storage *PalettedStorage) Palette() *Palette
Palette returns the Palette of the PalettedStorage.
func (*PalettedStorage) Set ¶
func (storage *PalettedStorage) Set(x, y, z byte, v uint32)
Set sets a value at a specific x, y and z. The Palette and PalettedStorage are expanded automatically to make space for the value, should that be needed.
type SubChunk ¶
type SubChunk struct {
// contains filtered or unexported fields
}
SubChunk is a cube of blocks located in a chunk. It has a size of 16x16x16 blocks and forms part of a stack that forms a Chunk.
func DecodeSubChunk ¶
func DecodeSubChunk(air uint32, r cube.Range, buf *bytes.Buffer, index *byte, e Encoding, pse Encoding, pe PaletteEncoding) (*SubChunk, error)
DecodeSubChunk decodes a SubChunk from a bytes.Buffer. The Encoding passed defines how the block storages of the SubChunk are decoded.
func NewSubChunk ¶
NewSubChunk creates a new sub chunk. All sub chunks should be created through this function
func (*SubChunk) Block ¶
Block returns the runtime ID of the block located at the given X, Y and Z. X, Y and Z must be in a range of 0-15.
func (*SubChunk) Empty ¶
Empty checks if the SubChunk is considered empty. This is the case if the SubChunk has 0 block storages or if it has a single one that is completely filled with air.
func (*SubChunk) Layer ¶
func (sub *SubChunk) Layer(layer uint8) *PalettedStorage
Layer returns a certain block storage/layer from a sub chunk. If no storage at the layer exists, the layer is created, as well as all layers between the current highest layer and the new highest layer.
func (*SubChunk) Layers ¶
func (sub *SubChunk) Layers() []*PalettedStorage
Layers returns all layers in the sub chunk. This method may also return an empty slice.