update to 1.18.2 & fix bug in snbt encoding

This commit is contained in:
Tnze
2022-03-10 12:29:03 +08:00
parent 0bbd279dd1
commit 46b021e1ef
18 changed files with 70 additions and 2147 deletions

View File

@ -10,11 +10,8 @@ import (
// WorldInfo content player info in server.
type WorldInfo struct {
DimensionCodec struct {
DimensionType interface{} `nbt:"minecraft:dimension_type"`
WorldgenBiome interface{} `nbt:"minecraft:worldgen/biome"`
}
Dimension interface{}
DimensionCodec nbt.StringifiedMessage
Dimension nbt.StringifiedMessage
WorldNames []string // Identifiers for all worlds on the server.
WorldName string // Name of the world being spawned into.
HashedSeed int64 // First 8 bytes of the SHA-256 hash of the world's seed. Used client side for biome noise
@ -49,8 +46,8 @@ func (p *Player) handleLoginPacket(packet pk.Packet) error {
(*pk.Byte)(&p.PrevGamemode),
&WorldCount,
pk.Ary{Len: &WorldCount, Ary: &WorldNames},
pk.NBT(new(nbt.RawMessage)),
pk.NBT(new(nbt.RawMessage)),
pk.NBT(&p.WorldInfo.DimensionCodec),
pk.NBT(&p.WorldInfo.Dimension),
(*pk.Identifier)(&p.WorldName),
(*pk.Long)(&p.HashedSeed),
(*pk.VarInt)(&p.MaxPlayers),

View File

@ -6,6 +6,7 @@ package bot
import (
"context"
"errors"
"net"
"strconv"
@ -16,7 +17,7 @@ import (
)
// ProtocolVersion is the protocol version number of minecraft net protocol
const ProtocolVersion = 757
const ProtocolVersion = 758
const DefaultPort = mcnet.DefaultPort
// JoinServer connect a Minecraft server for playing the game.
@ -27,20 +28,31 @@ func (c *Client) JoinServer(addr string) (err error) {
// JoinServerWithDialer is similar to JoinServer but using a Dialer.
func (c *Client) JoinServerWithDialer(d *net.Dialer, addr string) (err error) {
return c.join(context.Background(), &mcnet.Dialer{Dialer: d}, addr)
var dialer *mcnet.Dialer
if d != nil {
dialer = &mcnet.Dialer{Dialer: *d}
}
return c.join(context.Background(), dialer, addr)
}
func (c *Client) join(ctx context.Context, d *mcnet.Dialer, addr string) error {
const Handshake = 0x00
// Split Host and Port
host, portStr, err := net.SplitHostPort(addr)
var port uint64
if err != nil {
return LoginErr{"split address", err}
}
port, err := strconv.ParseUint(portStr, 0, 16)
if err != nil {
return LoginErr{"parse port", err}
var addrErr *net.AddrError
const missingPort = "missing port in address"
if errors.As(err, &addrErr) && addrErr.Err == missingPort {
port = 25565
} else {
return LoginErr{"split address", err}
}
} else {
port, err = strconv.ParseUint(portStr, 0, 16)
if err != nil {
return LoginErr{"parse port", err}
}
}
// Dial connection