level

package
v0.0.0-...-c10fe95 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkToSave

func ChunkToSave(c *Chunk, dst *save.Chunk) (err error)

ChunkToSave convert level.Chunk to save.Chunk

Types

type BiomesState

type BiomesState = biome.Type

type BitStorage

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

BitStorage implement the compacted data array used in chunk storage and heightmaps. You can think of this as a []intN whose N is indicated by "bits". For more info, see: https://wiki.vg/Chunk_Format This implementation is compatible with the format since Minecraft 1.16

func NewBitStorage

func NewBitStorage(bits, length int, data []uint64) (b *BitStorage)

NewBitStorage create a new BitStorage.

The "bits" is the number of bits per value, which can be calculated by math/bits.Len() The "length" is the number of values. The "data" is optional for initializing. It will panic if data != nil && len(data) != calcBitStorageSize(bits, length).

Example (Heightmaps)
// Create a BitStorage
bs := NewBitStorage(bits.Len(256), 16*16, nil)
// Fill your data
for i := 0; i < 16; i++ {
	for j := 0; j < 16; j++ {
		bs.Set(i*16+j, 0)
	}
}
// Encode as NBT, and this is ready for packet.Marshal
type HeightMaps struct {
	MotionBlocking []uint64 `nbt:"MOTION_BLOCKING"`
}
_ = pk.NBT(HeightMaps{bs.Raw()})
Output:

func (*BitStorage) Fix

func (b *BitStorage) Fix(bits int) error

Fix recalculate BitStorage internal values for given bits. Typically, you should call this method after ReadFrom is called, internal data is changed.

func (*BitStorage) Get

func (b *BitStorage) Get(i int) int

Get gets [i] value.

func (*BitStorage) Len

func (b *BitStorage) Len() int

Len is the number of stored values.

func (*BitStorage) Raw

func (b *BitStorage) Raw() []uint64

Raw return the underling array of uint64 for encoding/decoding.

func (*BitStorage) ReadFrom

func (b *BitStorage) ReadFrom(r io.Reader) (int64, error)

func (*BitStorage) Set

func (b *BitStorage) Set(i, v int)

Set sets v into [i].

func (*BitStorage) Swap

func (b *BitStorage) Swap(i, v int) (old int)

Swap sets v into [i], and return the previous [i] value.

func (*BitStorage) WriteTo

func (b *BitStorage) WriteTo(w io.Writer) (int64, error)

type BlockEntity

type BlockEntity struct {
	XZ   int8
	Y    int16
	Type block.EntityType
	Data nbt.RawMessage
}

func (*BlockEntity) PackXZ

func (b *BlockEntity) PackXZ(X, Z int) bool

func (*BlockEntity) ReadFrom

func (b *BlockEntity) ReadFrom(r io.Reader) (n int64, err error)

func (BlockEntity) UnpackXZ

func (b BlockEntity) UnpackXZ() (X, Z int)

func (BlockEntity) WriteTo

func (b BlockEntity) WriteTo(w io.Writer) (n int64, err error)

type BlocksState

type BlocksState = block.StateID

type Chunk

type Chunk struct {
	Sections    []Section
	HeightMaps  HeightMaps
	BlockEntity []BlockEntity
	Status      ChunkStatus
}

func ChunkFromSave

func ChunkFromSave(c *save.Chunk) (*Chunk, error)

ChunkFromSave convert save.Chunk to level.Chunk.

func EmptyChunk

func EmptyChunk(secs int) *Chunk

func (*Chunk) Data

func (c *Chunk) Data() ([]byte, error)

func (*Chunk) PutData

func (c *Chunk) PutData(data []byte) error

func (*Chunk) ReadFrom

func (c *Chunk) ReadFrom(r io.Reader) (int64, error)

func (*Chunk) WriteTo

func (c *Chunk) WriteTo(w io.Writer) (int64, error)

type ChunkPos

type ChunkPos [2]int32

func (*ChunkPos) ReadFrom

func (c *ChunkPos) ReadFrom(r io.Reader) (n int64, err error)

func (ChunkPos) WriteTo

func (c ChunkPos) WriteTo(w io.Writer) (n int64, err error)

type ChunkStatus

type ChunkStatus string
const (
	StatusEmpty               ChunkStatus = "empty"
	StatusStructureStarts     ChunkStatus = "structure_starts"
	StatusStructureReferences ChunkStatus = "structure_references"
	StatusBiomes              ChunkStatus = "biomes"
	StatusNoise               ChunkStatus = "noise"
	StatusSurface             ChunkStatus = "surface"
	StatusCarvers             ChunkStatus = "carvers"
	StatusLiquidCarvers       ChunkStatus = "liquid_carvers"
	StatusFeatures            ChunkStatus = "features"
	StatusLight               ChunkStatus = "light"
	StatusSpawn               ChunkStatus = "spawn"
	StatusHeightmaps          ChunkStatus = "heightmaps"
	StatusFull                ChunkStatus = "full"
)

type HeightMaps

type HeightMaps struct {
	MotionBlocking         *BitStorage
	MotionBlockingNoLeaves *BitStorage
	OceanFloor             *BitStorage
	WorldSurface           *BitStorage
}

type PaletteContainer

type PaletteContainer[T State] struct {
	// contains filtered or unexported fields
}

func NewBiomesPaletteContainer

func NewBiomesPaletteContainer(length int, defaultValue BiomesState) *PaletteContainer[BiomesState]

func NewBiomesPaletteContainerWithData

func NewBiomesPaletteContainerWithData(length int, data []uint64, pat []BiomesState) *PaletteContainer[BiomesState]

func NewStatesPaletteContainer

func NewStatesPaletteContainer(length int, defaultValue BlocksState) *PaletteContainer[BlocksState]

func NewStatesPaletteContainerWithData

func NewStatesPaletteContainerWithData(length int, data []uint64, pat []BlocksState) *PaletteContainer[BlocksState]

func (*PaletteContainer[T]) Get

func (p *PaletteContainer[T]) Get(i int) T

func (*PaletteContainer[T]) ReadFrom

func (p *PaletteContainer[T]) ReadFrom(r io.Reader) (n int64, err error)

func (*PaletteContainer[T]) Set

func (p *PaletteContainer[T]) Set(i int, v T)

func (*PaletteContainer[T]) WriteTo

func (p *PaletteContainer[T]) WriteTo(w io.Writer) (n int64, err error)

type Section

type Section struct {
	BlockCount int16
	States     *PaletteContainer[BlocksState]
	Biomes     *PaletteContainer[BiomesState]
	// Half a byte per light value.
	// Could be nil if not exist
	SkyLight   []byte // len() == 2048
	BlockLight []byte // len() == 2048
}

func (*Section) GetBlock

func (s *Section) GetBlock(i int) BlocksState

func (*Section) ReadFrom

func (s *Section) ReadFrom(r io.Reader) (int64, error)

func (*Section) SetBlock

func (s *Section) SetBlock(i int, v BlocksState)

func (*Section) WriteTo

func (s *Section) WriteTo(w io.Writer) (int64, error)

type State

type State interface {
	~int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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