Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeSubChunk(s *SubChunk, e Encoding) []byte
- type BlockStorage
- type Chunk
- func (chunk *Chunk) BiomeID(x, z uint8) uint8
- 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) SetBiomeID(x, z, biomeID uint8)
- func (chunk *Chunk) SetBlock(x uint8, y int16, z uint8, layer uint8, runtimeID uint32)
- func (chunk *Chunk) Sub() []*SubChunk
- type Encoding
- type Palette
- type SerialisedData
- 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 = 8 // CurrentBlockVersion is the current version of blocks (states) of the game. This version is composed // of 4 bytes indicating a version, interpreted as a big endian int. The current version represents // 1.19.70.15 {1, 19, 70, 15}. CurrentBlockVersion int32 = (1 << 24) | (19 << 16) | (70 << 8) | 15 LegacyBlockVersion int32 = (1 << 24) | (12 << 16) | (0 << 8) | 1 )
Variables ¶
var NetworkEncoding networkEncoding
NetworkEncoding is the Encoding used for sending a Chunk over network. It does not use NBT and writes varints.
Functions ¶
func EncodeSubChunk ¶
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.
Types ¶
type BlockStorage ¶
type BlockStorage struct {
// contains filtered or unexported fields
}
BlockStorage is a storage of 4096 blocks encoded in a variable amount of uint32s, storages may have blocks with a bit size per block of 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 BlockStorage must not be called simultaneously from multiple goroutines.
func (*BlockStorage) Palette ¶
func (storage *BlockStorage) Palette() *Palette
Palette returns the Palette of the block storage.
func (*BlockStorage) RuntimeID ¶
func (storage *BlockStorage) RuntimeID(x, y, z byte) uint32
RuntimeID returns the runtime ID of the block located at the given x, y and z.
func (*BlockStorage) SetRuntimeID ¶
func (storage *BlockStorage) SetRuntimeID(x, y, z byte, runtimeID uint32)
SetRuntimeID sets the given runtime ID at the given x, y and z. The palette and block storage are expanded automatically to make space for the runtime ID, should that be needed.
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 (*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.
func (*Chunk) SetBiomeID ¶
SetBiomeID sets the biome ID at a specific column in the chunk.
type Encoding ¶
type Encoding interface {
// contains filtered or unexported methods
}
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 Palette ¶
type Palette struct {
// contains filtered or unexported fields
}
Palette is a palette of runtime IDs that every block storage has. Block storages hold 'pointers' to indexes in this palette.
func (*Palette) Add ¶
Add adds a runtime ID to the palette. It does not first if the runtime ID was already set in the palette. The index at which the runtime ID was added is returned. Another bool is returned indicating if the palette was resized as a result of the adding of the runtime ID.
func (*Palette) Index ¶
Index loops through the runtime IDs of the palette and looks for the index of the given runtime ID. If the runtime ID can not be found, -1 is returned.
type SerialisedData ¶
type SerialisedData struct { // sub holds the data of the serialised sub chunks in a chunk. Sub chunks that are empty or that otherwise // don't exist are represented as an empty slice (or technically, nil). SubChunks [][]byte // Data2D is the 2D data of the chunk, which is composed of the biome IDs (256 bytes) and optionally the // height map of the chunk. Data2D []byte // BlockNBT is an encoded NBT array of all blocks that carry additional NBT, such as chests, with all // their contents. BlockNBT []byte }
SerialisedData holds the serialised data of a chunk. It consists of the chunk's block data itself, a height map, the biomes and entities and block entities.
func Encode ¶
func Encode(c *Chunk, e Encoding) SerialisedData
Encode encodes Chunk to an intermediate representation SerialisedData. 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.
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 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) *BlockStorage
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() []*BlockStorage
Layers returns all layers in the sub chunk. This method may also return an empty slice.