level

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 12 Imported by: 6

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkToSave added in v1.18.2

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

ChunkToSave convert level.Chunk to save.Chunk

Types

type BiomesState added in v1.18.2

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 added in v1.19.0

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, which cause 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 added in v1.18.2

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

func (*BlockEntity) PackXZ added in v1.19.3

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

func (*BlockEntity) ReadFrom added in v1.18.2

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

func (BlockEntity) UnpackXZ added in v1.18.2

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

func (BlockEntity) WriteTo added in v1.18.2

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

type BlocksState added in v1.18.2

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 added in v1.18.2

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

func (*Chunk) ReadFrom added in v1.18.2

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 added in v1.18.2

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

func (ChunkPos) WriteTo added in v1.18.2

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

type ChunkStatus added in v1.19.0

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 {
	WorldSurfaceWG         *BitStorage // test = NOT_AIR
	WorldSurface           *BitStorage // test = NOT_AIR
	OceanFloorWG           *BitStorage // test = MATERIAL_MOTION_BLOCKING
	OceanFloor             *BitStorage // test = MATERIAL_MOTION_BLOCKING
	MotionBlocking         *BitStorage // test = BlocksMotion or isFluid
	MotionBlockingNoLeaves *BitStorage // test = BlocksMotion or isFluid
}

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]) Palette added in v1.19.4

func (p *PaletteContainer[T]) Palette() []T

Palette export the raw palette values for @maxsupermanhd. Others shouldn't call this because this might be removed after max doesn't need it anymore.

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 added in v1.18.2

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