Documentation ¶
Index ¶
- Constants
- type Angle
- type Ary
- type Boolean
- type Builder
- type Byte
- type ByteArray
- type Chat
- type Double
- type Field
- type FieldDecoder
- type FieldEncoder
- type Float
- type Identifier
- type Int
- type Long
- type Opt
- type Packet
- type Position
- type Short
- type String
- type Tuple
- type UUID
- type UnsignedByte
- type UnsignedShort
- type VarInt
- type VarLong
Examples ¶
Constants ¶
const MaxVarIntLen = 5
const MaxVarLongLen = 10
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ary ¶
type Ary struct { Len Field // Pointer of VarInt, VarLong, Int or Long Ary interface{} // Slice of FieldEncoder, FieldDecoder or both (Field) }
type Boolean ¶
type Boolean bool
Boolean of True is encoded as 0x01, false as 0x00.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func (*Builder) WriteField ¶
func (p *Builder) WriteField(fields ...FieldEncoder)
type ByteArray ¶
type ByteArray []byte
ByteArray is []byte with prefix VarInt as length
type Chat ¶
type Chat = String
Chat is encoded as a String with max length of 32767. Deprecated: Use chat.Message
type Double ¶
type Double float64
A Double is a double-precision 64-bit IEEE 754 floating point number
type Field ¶
type Field interface { FieldEncoder FieldDecoder }
A Field is both FieldEncoder and FieldDecoder
type FieldDecoder ¶
type FieldDecoder io.ReaderFrom
A FieldDecoder can Decode from minecraft protocol
type FieldEncoder ¶
A FieldEncoder can be encode as minecraft protocol used.
type Identifier ¶
type Identifier = String
Identifier is encoded as a String with max length of 32767.
type Opt ¶
type Opt struct { Has *Boolean Field interface{} // FieldEncoder, FieldDecoder or both (Field) }
type Packet ¶
Packet define a net data package
func Marshal ¶
func Marshal(id int32, fields ...FieldEncoder) (pk Packet)
Marshal generate Packet with the ID and Fields
func (Packet) Scan ¶
func (p Packet) Scan(fields ...FieldDecoder) error
Scan decode the packet and fill data into fields
Example (JoinGame) ¶
package main import ( "fmt" _ "embed" pk "github.com/ArkPixel/go-mc/net/packet" ) //go:embed joingame_test.bin var testJoinGameData []byte func main() { p := pk.Packet{ID: 0x24, Data: testJoinGameData} var ( EID pk.Int Hardcore pk.Boolean Gamemode pk.UnsignedByte PreGamemode pk.Byte WorldCount pk.VarInt WorldNames = make([]pk.Identifier, 0) // This cannot replace with "var WorldNames []pk.Identifier" because "nil" has no type information DimensionCodec struct { DimensionType interface{} `nbt:"minecraft:dimension_type"` WorldgenBiome interface{} `nbt:"minecraft:worldgen/biome"` } Dimension interface{} WorldName pk.Identifier HashedSeed pk.Long MaxPlayers pk.VarInt ViewDistance pk.VarInt RDI, ERS, IsDebug, IsFlat pk.Boolean ) err := p.Scan( &EID, &Hardcore, &Gamemode, &PreGamemode, &WorldCount, pk.Ary{ Len: &WorldCount, Ary: &WorldNames, }, pk.NBT(&DimensionCodec), pk.NBT(&Dimension), &WorldName, &HashedSeed, &MaxPlayers, &ViewDistance, &RDI, &ERS, &IsDebug, &IsFlat, ) fmt.Print(err) }
Output: <nil>
type Position ¶
type Position struct {
X, Y, Z int
}
Position x as a 26-bit integer, followed by y as a 12-bit integer, followed by z as a 26-bit integer (all signed, two's complement)
type String ¶
type String string
String is sequence of Unicode scalar values
type Tuple ¶
type Tuple []interface{} // FieldEncoder, FieldDecoder or both (Field)
type UnsignedByte ¶
type UnsignedByte uint8
UnsignedByte is unsigned 8-bit integer
type UnsignedShort ¶
type UnsignedShort uint16
UnsignedShort is unsigned 16-bit integer
type VarInt ¶
type VarInt int32
VarInt is variable-length data encoding a two's complement signed 32-bit integer