Documentation
¶
Index ¶
- Constants
- Variables
- func ChunkPos(worldX, worldZ int) (int32, int32)
- func DecodeBlockEntry(entry int64) (stateID int32, localX, localY, localZ int)
- func DecodeSectionPosition(packed int64) (sectionX, sectionY, sectionZ int32)
- func LocalCoords(worldX, worldY, worldZ int) (int, int, int)
- func SectionIndex(worldY int) int
- type ChunkColumn
- type ChunkSection
- func (s *ChunkSection) Decode(buf *ns.PacketBuffer) error
- func (s *ChunkSection) Encode(buf *ns.PacketBuffer) error
- func (s *ChunkSection) GetBiome(x, y, z int) int32
- func (s *ChunkSection) GetBlockState(x, y, z int) int32
- func (s *ChunkSection) SetBiome(x, y, z int, biomeID int32)
- func (s *ChunkSection) SetBlockState(x, y, z int, stateID int32)
- type ContainerKind
- type PalettedContainer
- func (p *PalettedContainer) BitsPerEntry() int
- func (p *PalettedContainer) Decode(buf *ns.PacketBuffer) error
- func (p *PalettedContainer) Encode(buf *ns.PacketBuffer) error
- func (p *PalettedContainer) Get(index int) int32
- func (p *PalettedContainer) GetXYZ(x, y, z int) int32
- func (p *PalettedContainer) Set(index int, value int32)
- func (p *PalettedContainer) SetXYZ(x, y, z int, value int32)
Constants ¶
const ( // SectionCount is the number of vertical sections in a chunk column (1.21.x: Y -64 to 319). SectionCount = 24 // MinY is the minimum world Y coordinate. MinY = -64 // MaxY is the maximum world Y coordinate (exclusive). MaxY = MinY + SectionCount*16 )
Variables ¶
var ( BlockStatesKind = ContainerKind{EntryCount: 4096, MinIndirectBits: 4, MaxIndirectBits: 8, DirectBits: 15} BiomesKind = ContainerKind{EntryCount: 64, MinIndirectBits: 1, MaxIndirectBits: 3, DirectBits: 6} )
Functions ¶
func DecodeBlockEntry ¶
DecodeBlockEntry decodes a VarLong block entry from S2CSectionBlocksUpdate.
Bit layout: block state ID at bits 12+, local position at bits 0-11 (X at bits 8-11, Z at bits 4-7, Y at bits 0-3).
func DecodeSectionPosition ¶
DecodeSectionPosition decodes the packed section position from S2CSectionBlocksUpdate.
Bit layout: X (22 bits, signed) at bits 42-63, Z (22 bits) at 20-41, Y (20 bits) at 0-19.
func LocalCoords ¶
LocalCoords extracts the local 0-15 coordinates from world coordinates.
func SectionIndex ¶
SectionIndex returns the section array index for the given world Y coordinate. Returns -1 if Y is out of range.
Types ¶
type ChunkColumn ¶
type ChunkColumn struct {
X, Z int32
Sections [SectionCount]*ChunkSection
Heightmaps map[int32][]int64
BlockEntities []ns.BlockEntity
Light *ns.LightData
}
ChunkColumn represents a vertical column of chunk sections with associated data.
func ParseChunkColumn ¶
ParseChunkColumn decodes a ChunkColumn from protocol-level types.
func (*ChunkColumn) ComputeSkylight ¶
func (c *ChunkColumn) ComputeSkylight()
ComputeSkylight computes simple vertical sky light propagation. For each XZ column, sky light starts at 15 from the top and is blocked by any non-air block. This does not perform horizontal light spreading (sufficient for flat worlds).
func (*ChunkColumn) EncodeSections ¶
func (c *ChunkColumn) EncodeSections() ([]byte, error)
EncodeSections encodes all chunk sections back to raw bytes (the ChunkData.Data portion).
func (*ChunkColumn) GetBlockState ¶
func (c *ChunkColumn) GetBlockState(x, y, z int) int32
GetBlockState returns the block state ID at absolute world coordinates. Returns 0 (air) if the coordinates are out of range or the section is nil.
func (*ChunkColumn) SetBlockState ¶
func (c *ChunkColumn) SetBlockState(x, y, z int, stateID int32)
SetBlockState sets the block state ID at absolute world coordinates. Creates an empty section if the target section is nil.
type ChunkSection ¶
type ChunkSection struct {
BlockCount int16
BlockStates *PalettedContainer
Biomes *PalettedContainer
}
ChunkSection represents a 16x16x16 section of blocks and a 4x4x4 grid of biomes.
func NewEmptySection ¶
func NewEmptySection() *ChunkSection
NewEmptySection creates a section with all air blocks and a single-value biome (ID 0).
func (*ChunkSection) Decode ¶
func (s *ChunkSection) Decode(buf *ns.PacketBuffer) error
Decode reads a ChunkSection from the buffer.
func (*ChunkSection) Encode ¶
func (s *ChunkSection) Encode(buf *ns.PacketBuffer) error
Encode writes a ChunkSection to the buffer.
func (*ChunkSection) GetBiome ¶
func (s *ChunkSection) GetBiome(x, y, z int) int32
GetBiome returns the biome ID at local biome coordinates (0-3 each).
func (*ChunkSection) GetBlockState ¶
func (s *ChunkSection) GetBlockState(x, y, z int) int32
GetBlockState returns the block state ID at local coordinates (0-15 each).
func (*ChunkSection) SetBiome ¶
func (s *ChunkSection) SetBiome(x, y, z int, biomeID int32)
SetBiome sets the biome ID at local biome coordinates (0-3 each).
func (*ChunkSection) SetBlockState ¶
func (s *ChunkSection) SetBlockState(x, y, z int, stateID int32)
SetBlockState sets the block state ID at local coordinates (0-15 each).
type ContainerKind ¶
ContainerKind defines the palette strategy parameters for a paletted container.
type PalettedContainer ¶
type PalettedContainer struct {
// contains filtered or unexported fields
}
PalettedContainer stores entries (block state IDs or biome IDs) using palette compression.
Three modes:
- Single-value (bitsPerEntry=0): all entries share one value
- Indirect (bitsPerEntry in [minIndirect, maxIndirect]): palette maps indices to IDs
- Direct (bitsPerEntry=directBits): no palette, data stores IDs directly
func NewSingleValue ¶
func NewSingleValue(kind ContainerKind, value int32) *PalettedContainer
NewSingleValue creates a container where all entries have the same value.
func (*PalettedContainer) BitsPerEntry ¶
func (p *PalettedContainer) BitsPerEntry() int
BitsPerEntry returns the current bits per entry.
func (*PalettedContainer) Decode ¶
func (p *PalettedContainer) Decode(buf *ns.PacketBuffer) error
Decode reads a PalettedContainer from the buffer. Wire format (1.21.11): byte bpe | palette data | fixed-size long array (no length prefix).
func (*PalettedContainer) Encode ¶
func (p *PalettedContainer) Encode(buf *ns.PacketBuffer) error
Encode writes a PalettedContainer to the buffer.
func (*PalettedContainer) Get ¶
func (p *PalettedContainer) Get(index int) int32
Get returns the entry at the given flat index.
func (*PalettedContainer) GetXYZ ¶
func (p *PalettedContainer) GetXYZ(x, y, z int) int32
GetXYZ returns the entry at the given x, y, z coordinates. For blocks: 0-15 each. For biomes: 0-3 each.
func (*PalettedContainer) Set ¶
func (p *PalettedContainer) Set(index int, value int32)
Set sets the entry at the given flat index.
func (*PalettedContainer) SetXYZ ¶
func (p *PalettedContainer) SetXYZ(x, y, z int, value int32)
SetXYZ sets the entry at the given x, y, z coordinates.