go fmt
This commit is contained in:
@ -30,7 +30,7 @@ const (
|
||||
Hat
|
||||
)
|
||||
|
||||
//DefaultSettings are the default settings of client
|
||||
// DefaultSettings are the default settings of client
|
||||
var DefaultSettings = Settings{
|
||||
Locale: "zh_CN", // ^_^
|
||||
ViewDistance: 15,
|
||||
|
@ -37,7 +37,7 @@ func NewClient() *Client {
|
||||
}
|
||||
}
|
||||
|
||||
//Position is a 3D vector.
|
||||
// Position is a 3D vector.
|
||||
type Position struct {
|
||||
X, Y, Z int
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func (m Message) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
}
|
||||
|
||||
//UnmarshalJSON decode json to Message
|
||||
// UnmarshalJSON decode json to Message
|
||||
func (m *Message) UnmarshalJSON(raw []byte) (err error) {
|
||||
if len(raw) == 0 {
|
||||
return io.EOF
|
||||
|
@ -15,6 +15,7 @@ type Block interface {
|
||||
}
|
||||
|
||||
// This file stores all possible block states into a TAG_List with gzip compressed.
|
||||
//
|
||||
//go:embed block_states.nbt
|
||||
var blockStates []byte
|
||||
|
||||
|
@ -39,7 +39,6 @@ func NewEncoder(w io.Writer) *Encoder {
|
||||
// expect `[]int8`, `[]int32`, `[]int64`, `[]uint8`, `[]uint32` and `[]uint64`,
|
||||
// which TagByteArray, TagIntArray and TagLongArray.
|
||||
// To force encode them as TagList, add a struct field tag.
|
||||
//
|
||||
func (e *Encoder) Encode(v interface{}, tagName string) error {
|
||||
t, val := getTagType(reflect.ValueOf(v))
|
||||
return e.marshal(val, t, tagName)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
//Tag type IDs
|
||||
// Tag type IDs
|
||||
const (
|
||||
TagEnd byte = iota
|
||||
TagByte
|
||||
|
@ -18,7 +18,7 @@ const DefaultPort = 25565
|
||||
// A Listener is a minecraft Listener
|
||||
type Listener struct{ net.Listener }
|
||||
|
||||
//ListenMC listen as TCP but Accept a mc Conn
|
||||
// ListenMC listen as TCP but Accept a mc Conn
|
||||
func ListenMC(addr string) (*Listener, error) {
|
||||
l, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
@ -27,7 +27,7 @@ func ListenMC(addr string) (*Listener, error) {
|
||||
return &Listener{l}, nil
|
||||
}
|
||||
|
||||
//Accept a minecraft Conn
|
||||
// Accept a minecraft Conn
|
||||
func (l Listener) Accept() (Conn, error) {
|
||||
conn, err := l.Listener.Accept()
|
||||
return Conn{
|
||||
@ -38,7 +38,7 @@ func (l Listener) Accept() (Conn, error) {
|
||||
}, err
|
||||
}
|
||||
|
||||
//Conn is a minecraft Connection
|
||||
// Conn is a minecraft Connection
|
||||
type Conn struct {
|
||||
Socket net.Conn
|
||||
io.Reader
|
||||
@ -136,6 +136,7 @@ func (d *Dialer) DialMCContext(ctx context.Context, addr string) (*Conn, error)
|
||||
// - now+Timeout
|
||||
// - d.Deadline
|
||||
// - the context's deadline
|
||||
//
|
||||
// Or zero, if none of Timeout, Deadline, or context's deadline is set.
|
||||
//
|
||||
// Copied from net/dial.go
|
||||
@ -197,7 +198,7 @@ func WrapConn(conn net.Conn) *Conn {
|
||||
}
|
||||
}
|
||||
|
||||
//Close the connection
|
||||
// Close the connection
|
||||
func (c *Conn) Close() error { return c.Socket.Close() }
|
||||
|
||||
// ReadPacket read a Packet from Conn.
|
||||
|
@ -16,7 +16,7 @@ type Packet struct {
|
||||
Data []byte
|
||||
}
|
||||
|
||||
//Marshal generate Packet with the ID and Fields
|
||||
// Marshal generate Packet with the ID and Fields
|
||||
func Marshal(id int32, fields ...FieldEncoder) (pk Packet) {
|
||||
var pb Builder
|
||||
for _, v := range fields {
|
||||
@ -25,7 +25,7 @@ func Marshal(id int32, fields ...FieldEncoder) (pk Packet) {
|
||||
return pb.Packet(id)
|
||||
}
|
||||
|
||||
//Scan decode the packet and fill data into fields
|
||||
// Scan decode the packet and fill data into fields
|
||||
func (p Packet) Scan(fields ...FieldDecoder) error {
|
||||
r := bytes.NewReader(p.Data)
|
||||
for _, v := range fields {
|
||||
|
@ -404,7 +404,7 @@ func (d *Double) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
//NBT encode a value as Named Binary Tag
|
||||
// NBT encode a value as Named Binary Tag
|
||||
func NBT(v interface{}, optionalTagName ...string) Field {
|
||||
if len(optionalTagName) > 0 {
|
||||
return nbtField{V: v, FieldName: optionalTagName[0]}
|
||||
|
@ -9,6 +9,7 @@ func (r *Realms) Available() (ok bool, err error) {
|
||||
}
|
||||
|
||||
// Compatible returns whether the clients version is up to date with Realms.
|
||||
//
|
||||
// if the client is outdated, it returns OUTDATED,
|
||||
// if the client is running a snapshot, it returns OTHER,
|
||||
// else it returns COMPATIBLE.
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@ -27,7 +26,7 @@ import (
|
||||
|
||||
const verifyTokenLen = 16
|
||||
|
||||
//Encrypt a connection, with authentication
|
||||
// Encrypt a connection, with authentication
|
||||
func Encrypt(conn *net.Conn, name string, profilePubKey *rsa.PublicKey) (*Resp, error) {
|
||||
//generate keys
|
||||
key, err := rsa.GenerateKey(rand.Reader, 1024)
|
||||
@ -153,7 +152,7 @@ func authentication(name, hash string) (*Resp, error) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -205,7 +204,7 @@ func twosComplement(p []byte) []byte {
|
||||
return p
|
||||
}
|
||||
|
||||
//Resp is the response of authentication
|
||||
// Resp is the response of authentication
|
||||
type Resp struct {
|
||||
Name string
|
||||
ID uuid.UUID
|
||||
@ -229,7 +228,7 @@ func (p Property) WriteTo(w io.Writer) (n int64, err error) {
|
||||
}.WriteTo(w)
|
||||
}
|
||||
|
||||
//Texture includes player's skin and cape
|
||||
// Texture includes player's skin and cape
|
||||
type Texture struct {
|
||||
TimeStamp int64 `json:"timestamp"`
|
||||
ID uuid.UUID `json:"profileId"`
|
||||
@ -241,7 +240,7 @@ type Texture struct {
|
||||
} `json:"textures"`
|
||||
}
|
||||
|
||||
//Texture unmarshal the base64 encoded texture of Resp
|
||||
// Texture unmarshal the base64 encoded texture of Resp
|
||||
func (r *Resp) Texture() (t Texture, err error) {
|
||||
var texture []byte
|
||||
texture, err = base64.StdEncoding.DecodeString(r.Properties[0].Value)
|
||||
|
Reference in New Issue
Block a user