chunk

package
v0.0.0-...-2a33acd Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chunk

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

func NewChunk

func NewChunk(version block.Version, constructor func(v block.Version) Section) *Chunk

Creates an empty chunk. Constructor is a function pointer, which should create an empty chunk.

func (*Chunk) CopyFrom

func (c *Chunk) CopyFrom(o *Chunk)

func (*Chunk) Fill

func (c *Chunk) Fill(min, max block.Pos, t *block.Type)

func (*Chunk) FromProto

func (c *Chunk) FromProto(proto *pb.Chunk) bool

Only paletted chunks can be converted from

func (*Chunk) GetBlock

func (c *Chunk) GetBlock(pos block.Pos) *block.Type

func (*Chunk) GetChunkSection

func (c *Chunk) GetChunkSection(y int32) Section

func (*Chunk) HasChunkSection

func (c *Chunk) HasChunkSection(y int32) bool

func (*Chunk) IsAll

func (c *Chunk) IsAll(t *block.Type) bool

func (*Chunk) Serialize

func (c *Chunk) Serialize() *pb.Chunk

func (*Chunk) SetBlock

func (c *Chunk) SetBlock(pos block.Pos, t *block.Type)

type LightChunk

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

Is a chunk of lighting data. If the world has skylight, two light chunks will need to be made.

func NewLightChunk

func NewLightChunk(c *Chunk, sky bool) *LightChunk

Creates a new light chunk. This chunk does not store block data, only lighting data. If you set sky to true, then this chunk will not emit light from light sources, instead it will emit light from the sky downwards. c should be a latest version chunk, which is the chunk that this light chunk is on. c will be used to see where walls are, in order to block light.

func (*LightChunk) AddLightSource

func (l *LightChunk) AddLightSource(pos block.Pos, light byte)

This is a nop for sky light chunks. Pos should be relative to the chunk origin. If pos is outside of the chunk, then light will still be propogated, as if the light were in the given position relative to the chunk.

func (*LightChunk) AddSection

func (l *LightChunk) AddSection(y int32)

Adds a section at the given y position. This is called from MultiChunk automatically. Only call this function if you know what you are doing. If a light section already exists at y, this is a nop.

func (*LightChunk) GetSection

func (l *LightChunk) GetSection(y int32) *LightSection

Gets a light section given then y index. y should be a block y position / 16.

type LightSection

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

A 16x16x16 area of light data. For worlds with skylight, two light sections must be created for every chunk section.

func NewLightSection

func NewLightSection(c *Chunk, sky bool) *LightSection

Creates a new light section. This is a 16x16x16 area of light data.

func (*LightSection) AddLightSource

func (l *LightSection) AddLightSource(pos block.Pos, amount byte) []LightUpdate

Adds light coming from pos with amount intensity. This is a nop for sky chunk sections. Pos must be within the zero chunk column.

type LightUpdate

type LightUpdate struct {
	// Position of the light update. Can
	// be relative or global, depending on
	// where this light update came from.
	Pos block.Pos
	// The light level that pos should be
	// at.
	Amount byte
}

type MultiChunk

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

This is a general representation of a chunk, which contains a seperate struct for each version supported. As more versions get added, this chunk will get larger, as it needs to reference more versions. However, this is the fastest way to do things, as copying and regenerating the chunk for every new client would be far too slow.

func NewMultiChunk

func NewMultiChunk() *MultiChunk

func (*MultiChunk) Fill

func (c *MultiChunk) Fill(min, max block.Pos, t *block.Type)

This sets all blocks within the range min to max within the chunk. For palleted chunks (1.12+), this is much faster than SetBlockType. For fixed size chunks (1.8), this is about the same speed. However, older chunks rely on new chunks to see what is air, so it ends up being a speed improvement no matter what. If min is less than max, then this call will return immediatley.

func (*MultiChunk) GetBlock

func (c *MultiChunk) GetBlock(pos block.Pos) *block.Type

This gets a block within the chunk. NOTE: pos needs to be relative to a chunk. This function will not call pos.ChunkRelPos(), as that is slower than relying on the user. If the pos is outside of the chunk, then the block position will be wrapped, and it will be very hard to predict what will happen.

func (*MultiChunk) GetBlockAt

func (c *MultiChunk) GetBlockAt(pos block.Pos) *block.State

This returns a block state, which is a block within the world. pos should be in absolute coordinates, as that is the position that will be used in the block.State. This will call ChunkRelPos to access the blocks in the chunk.

func (*MultiChunk) HasChunkSection

func (c *MultiChunk) HasChunkSection(y int32) bool

func (*MultiChunk) IsAll

func (c *MultiChunk) IsAll(t *block.Type) bool

This checks if an entire chunk is the given block. It only checks this for the latest version, which is a paletted chunk, so this is pretty fast.

func (*MultiChunk) LoadFromProto

func (c *MultiChunk) LoadFromProto(proto *pb.Chunk)

This takes a protobuf (from a grpc connection) and loads all of the chunk sections accordingly. This is used on the client whenever a chunk packet is recieved. This must always be used with the latest version!

func (*MultiChunk) SaveToDisk

func (c *MultiChunk) SaveToDisk(path string)

func (*MultiChunk) SaveToS3

func (c *MultiChunk) SaveToS3(bucket, key string, uploader *s3manager.Uploader)

func (*MultiChunk) Serialize

func (c *MultiChunk) Serialize(version block.Version) *pb.Chunk

This converts the chunk to a protobuf, for the given protocol version

func (*MultiChunk) SetBlock

func (c *MultiChunk) SetBlock(pos block.Pos, t *block.Type)

This sets a block within the chunk. NOTE: pos needs to be relative to a chunk. This function will not call pos.ChunkRelPos(), as that is slower than relying on the user. If the pos is outside of the chunk, then the block position will be wrapped, and it will be very hard to predict what will happen.

type Section

type Section interface {
	// pos.Y is relative to this section (must be within 0-15)
	// This function is not expected to check that.
	GetBlock(pos block.Pos) *block.Type
	// pos.Y is relative to this section (must be within 0-15)
	// This function is not expected to check that.
	SetBlock(pos block.Pos, t *block.Type)
	// Both positions are relative to the chunk (including y). If max is larger than min,
	// you can expect this function to do nothing/fail in undefined ways.
	Fill(min, max block.Pos, t *block.Type)

	// Used most commonly to check if the chunk is all air
	IsAll(t *block.Type) bool

	// Generates a protobuf that stores all the data in this
	// chunk section.
	Serialize() *pb.Chunk_Section

	// Should overwrite all data with the data of other.
	CopyFrom(other Section)
}

General representation of a chunk section. Chunks use these internally, so that the versioning is all up to the chunk section.

Jump to

Keyboard shortcuts

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