protocol

package
v0.0.0-...-8eced28 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CurrentProtocol is the current protocol version for the version below.
	CurrentProtocol = 756
	// CurrentMinecraftVersion is the current version of Minecraft.
	CurrentMinecraftVersion = "1.17.1"
	// CurrentVersion is the current version of Expresso.
	CurrentVersion = "Expresso v0.1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BitStorage

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

BitStorage implements the compacted data storage format used in chunks since Minecraft v1.16. https://wiki.vg/Chunk_Format

func NewBitStorageWithData

func NewBitStorageWithData(bitsPerEntry int32, size int32, data []int64) (*BitStorage, error)

NewBitStorageWithData creates a new BitStorage instance with the provided data.

func NewEmptyBitStorage

func NewEmptyBitStorage(bitsPerEntry int32, size int32) *BitStorage

NewEmptyBitStorage creates a new empty BitStorage.

func (*BitStorage) Get

func (b *BitStorage) Get(index int32) (int32, error)

Get returns the value at the given index.

func (*BitStorage) Set

func (b *BitStorage) Set(index, value int32) error

Set sets the value at the given index.

type BlockPos

type BlockPos [3]int32

BlockPos represents a block position.

func (BlockPos) X

func (p BlockPos) X() int32

X returns the X of the position

func (BlockPos) Y

func (p BlockPos) Y() int32

Y returns the Y of the position

func (BlockPos) Z

func (p BlockPos) Z() int32

Z returns the Z of the position

type Chunk

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

Chunk is an implementation of the modern Minecraft chunk.

func NewEmptyChunk

func NewEmptyChunk() *Chunk

NewEmptyChunk creates a new empty chunk.

func (*Chunk) Empty

func (c *Chunk) Empty() bool

Empty returns true if the chunk is empty.

func (*Chunk) GetBlockState

func (c *Chunk) GetBlockState(x, y, z int32) (int32, error)

GetBlockState returns the block state at the given position.

func (*Chunk) SetBlockState

func (c *Chunk) SetBlockState(x, y, z, state int32) error

SetBlockState sets the block state at the given position.

type Column

type Column struct {
	// Position is the position of the column.
	Position ColumnPos
	// Chunks contain all chunks associated with the column.
	Chunks map[int32]*Chunk
	// Tiles contains all tile entities associated with the column.
	Tiles []map[string]interface{}
	// HeightMaps contains all height maps associated with the column.
	HeightMaps map[string]interface{}
	// Biomes contains all biomes associated with the column.
	Biomes []int32
}

Column represents a chunk column, which contains chunk data, the chunk position, biomes, and other useful information for the client.

func NewColumn

func NewColumn(pos ColumnPos) *Column

NewColumn initializes a new empty chunk column.

func (*Column) GetBlockState

func (c *Column) GetBlockState(pos BlockPos) (int32, error)

GetBlockState returns the state ID of a block position.

func (*Column) SetBlockState

func (c *Column) SetBlockState(pos BlockPos, state int32) error

SetBlockState sets the state ID of a block position.

type ColumnPos

type ColumnPos [2]int32

ColumnPos represents a position of a column.

func (ColumnPos) X

func (p ColumnPos) X() int32

X returns the X of the column position.

func (ColumnPos) Z

func (p ColumnPos) Z() int32

Z returns the Z of the column position.

type GlobalPalette

type GlobalPalette struct{}

GlobalPalette is a global palette that maps one to one.

func NewGlobalPalette

func NewGlobalPalette() *GlobalPalette

NewGlobalPalette returns a new global palette.

func (*GlobalPalette) IDToState

func (*GlobalPalette) IDToState(id int32) int32

IDToState converts the storage ID to a block state. If it is not mapped, then it will return false as it's second return value.

func (*GlobalPalette) Size

func (*GlobalPalette) Size() int32

Size returns the known number of block states in the palette.

func (*GlobalPalette) StateToID

func (*GlobalPalette) StateToID(state int32) int32

StateToID converts the block state to a storage ID. If it is not mapped, then the palette will attempt to map it. If all else fails, it will return false as it's second return value.

type IO

type IO interface {
	// Uint8 reads/writes an uint8 from/to the underlying buffer.
	Uint8(x *uint8)
	// Int16 reads/writes an int16 from/to the underlying buffer.
	Int16(x *int16)
	// Int32 reads/writes an int32 from/to the underlying buffer.
	Int32(x *int32)
	// Int64 reads/writes an int64 from/to the underlying buffer.
	Int64(x *int64)

	// Float32 reads/writes a float32 from/to the underlying buffer.
	Float32(x *float32)
	// Float64 reads/writes a float64 from/to the underlying buffer.
	Float64(x *float64)

	// Varint32 reads/writes a variable int32 from/to the underlying buffer.
	Varint32(x *int32)
	// Varint64 reads/writes a variable int64 from/to the underlying buffer.
	Varint64(x *int64)

	// ByteSlice reads/writes a byte slice from the underlying buffer, similarly to String.
	ByteSlice(x *[]byte)
	// Bytes reads all remaining bytes in the reader, or appends the bytes to the buffer if it is a writer.
	Bytes(b *[]byte)
	// Bool reads/writes a bool as either 0x00 or 0x01 to the underlying buffer.
	Bool(x *bool)
	// String reads/writes a string, prefixed with a variable int32, from/to the underlying buffer.
	String(x *string)

	// UUID reads/writes a UUID from/to the underlying buffer.
	UUID(x *uuid.UUID)
	// Text reads/writes Minecraft-style text from/to the underlying buffer.
	Text(x *text.Text)
	// Chunk reads/writes a chunk from/to the underlying buffer.
	Chunk(x *Chunk)

	// NBT reads/writes a map as a compound tag from/to the underlying buffer.
	NBT(x *map[string]interface{})
}

IO is implemented by Writer and Reader.

type ListPalette

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

ListPalette is a palette backed by a list.

func NewListPalette

func NewListPalette(bitsPerEntry int32) *ListPalette

NewListPalette returns a new list palette.

func NewListPaletteFromReader

func NewListPaletteFromReader(bitsPerEntry int32, reader *Reader) *ListPalette

NewListPaletteFromReader returns a new list palette from the given reader.

func (*ListPalette) IDToState

func (p *ListPalette) IDToState(id int32) int32

IDToState converts the storage ID to a block state. If it is not mapped, then it will return false as it's second return value.

func (*ListPalette) Size

func (p *ListPalette) Size() int32

Size returns the known number of block states in the palette.

func (*ListPalette) StateToID

func (p *ListPalette) StateToID(state int32) (id int32)

StateToID converts the block state to a storage ID. If it is not mapped, then the palette will attempt to map it. If all else fails, it will return false as it's second return value.

type MapPalette

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

MapPalette is a palette backed by a map.

func NewMapPalette

func NewMapPalette(bitsPerEntry int32) *MapPalette

NewMapPalette returns a new map palette.

func NewMapPaletteFromReader

func NewMapPaletteFromReader(bitsPerEntry int32, reader *Reader) *MapPalette

NewMapPaletteFromReader returns a new map palette from the given reader.

func (*MapPalette) IDToState

func (p *MapPalette) IDToState(id int32) int32

IDToState converts the storage ID to a block state. If it is not mapped, then it will return false as it's second return value.

func (*MapPalette) Size

func (p *MapPalette) Size() int32

Size returns the known number of block states in the palette.

func (*MapPalette) StateToID

func (p *MapPalette) StateToID(state int32) int32

StateToID converts the block state to a storage ID. If it is not mapped, then the palette will attempt to map it. If all else fails, it will return false as it's second return value.

type Palette

type Palette interface {
	// Size returns the known number of block states in the palette.
	Size() int32
	// StateToID converts the block state to a storage ID. If it is not mapped, then the palette will attempt
	// to map it. If all else fails, it will return -1.
	StateToID(state int32) int32
	// IDToState converts the storage ID to a block state. If it is not mapped, then it will return -1.
	IDToState(id int32) int32
}

Palette is a palette implementation for mapping block states to storage IDs.

type Reader

type Reader struct {
	io.Reader
}

Reader is an instance of a protocol reader.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader initializes a new protocol reader using the buffer passed.

func (*Reader) Bool

func (r *Reader) Bool(x *bool)

Bool reads a bool from 0x00 or 0x01 from the underlying buffer.

func (*Reader) ByteSlice

func (r *Reader) ByteSlice(x *[]byte)

ByteSlice reads a byte slice from the underlying buffer, similarly to String.

func (*Reader) Bytes

func (r *Reader) Bytes(b *[]byte)

Bytes reads all remaining bytes in the reader.

func (*Reader) Chunk

func (r *Reader) Chunk(x *Chunk)

Chunk reads a chunk from the underlying buffer.

func (*Reader) Float32

func (r *Reader) Float32(x *float32)

Float32 reads a float32 from the underlying buffer.

func (*Reader) Float64

func (r *Reader) Float64(x *float64)

Float64 reads a float64 from the underlying buffer.

func (*Reader) Int16

func (r *Reader) Int16(x *int16)

Int16 reads an int16 from the underlying buffer.

func (*Reader) Int32

func (r *Reader) Int32(x *int32)

Int32 reads an int32 from the underlying buffer.

func (*Reader) Int64

func (r *Reader) Int64(x *int64)

Int64 reads an int64 from the underlying buffer.

func (*Reader) NBT

func (r *Reader) NBT(x *map[string]interface{})

NBT reads a map as a compound tag from the underlying buffer.

func (*Reader) String

func (r *Reader) String(x *string)

String reads a string, prefixed with a variable int32, from the underlying buffer.

func (*Reader) Text

func (r *Reader) Text(x *text.Text)

Text reads Minecraft-style text from the underlying buffer.

func (*Reader) UUID

func (r *Reader) UUID(x *uuid.UUID)

UUID reads a UUID from the underlying buffer.

func (*Reader) Uint8

func (r *Reader) Uint8(x *uint8)

Uint8 reads an uint8 from the underlying buffer.

func (*Reader) Varint32

func (r *Reader) Varint32(x *int32)

Varint32 reads a variable int32 from the underlying buffer.

func (*Reader) Varint64

func (r *Reader) Varint64(x *int64)

Varint64 reads a variable int64 from the underlying buffer.

type Writer

type Writer struct {
	io.Writer
}

Writer is an instance of a protocol writer.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter initializes a new protocol writer using the buffer passed.

func (*Writer) Bool

func (w *Writer) Bool(x *bool)

Bool writes a bool as either 0x00 or 0x01 to the underlying buffer.

func (*Writer) ByteSlice

func (w *Writer) ByteSlice(x *[]byte)

ByteSlice writes a []byte, prefixed with a variable int32, to the underlying buffer.

func (*Writer) Bytes

func (w *Writer) Bytes(x *[]byte)

Bytes appends a []byte to the underlying buffer.

func (*Writer) Chunk

func (w *Writer) Chunk(x *Chunk)

Chunk writes a chunk to the underlying buffer.

func (*Writer) Float32

func (w *Writer) Float32(x *float32)

Float32 writes a float32 to the underlying buffer.

func (*Writer) Float64

func (w *Writer) Float64(x *float64)

Float64 writes a float64 to the underlying buffer.

func (*Writer) Int16

func (w *Writer) Int16(x *int16)

Int16 writes an int16 to the underlying buffer.

func (*Writer) Int32

func (w *Writer) Int32(x *int32)

Int32 writes an int32 to the underlying buffer.

func (*Writer) Int64

func (w *Writer) Int64(x *int64)

Int64 writes an int64 to the underlying buffer.

func (*Writer) NBT

func (w *Writer) NBT(x *map[string]interface{})

NBT writes a map as a compound tag to the underlying buffer.

func (*Writer) String

func (w *Writer) String(x *string)

String writes a string, prefixed with a variable int32, to the underlying buffer.

func (*Writer) Text

func (w *Writer) Text(x *text.Text)

Text writes Minecraft-style text to the underlying buffer.

func (*Writer) UUID

func (w *Writer) UUID(x *uuid.UUID)

UUID writes a UUID to the underlying buffer.

func (*Writer) Uint8

func (w *Writer) Uint8(x *uint8)

Uint8 writes an uint8 to the underlying buffer.

func (*Writer) Varint32

func (w *Writer) Varint32(x *int32)

Varint32 writes a variable int32 to the underlying buffer.

func (*Writer) Varint64

func (w *Writer) Varint64(x *int64)

Varint64 writes a variable int64 to the underlying buffer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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