From 444229216a786c4372fe7895f8ca914df0e810b3 Mon Sep 17 00:00:00 2001 From: genanik Date: Wed, 1 Jul 2020 11:32:58 +0800 Subject: [PATCH] Basic support for 1.16.1 --- bot/client.go | 13 ++++++++----- bot/event.go | 2 +- bot/ingame.go | 28 ++++++++++++++++++++-------- bot/mcbot.go | 2 +- cmd/daze/daze.go | 2 +- data/packetIDs.go | 8 ++++---- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/bot/client.go b/bot/client.go index fe052ba..1a28952 100644 --- a/bot/client.go +++ b/bot/client.go @@ -49,13 +49,16 @@ func NewClient() (c *Client) { //PlayInfo content player info in server. type PlayInfo struct { - Gamemode int //游戏模式 - Hardcore bool //是否是极限模式 - Dimension int //维度 - Difficulty int //难度 - LevelType string //地图类型 + Gamemode int //游戏模式 + Hardcore bool //是否是极限模式 + Dimension int //维度 + Difficulty int //难度 + // LevelType string //地图类型 1.16删了 ViewDistance int //视距 ReducedDebugInfo bool //减少调试信息 + WorldName string //当前世界的名字 + IsDebug bool //调试 + IsFlat bool //超平坦世界 // SpawnPosition Position //主世界出生点 } diff --git a/bot/event.go b/bot/event.go index d121c05..d3ba7dc 100644 --- a/bot/event.go +++ b/bot/event.go @@ -9,7 +9,7 @@ import ( type eventBroker struct { GameStart func() error - ChatMsg func(msg chat.Message, pos byte) error + ChatMsg func(msg chat.Message, pos byte, sender string) error Disconnect func(reason chat.Message) error HealthChange func() error Die func() error diff --git a/bot/ingame.go b/bot/ingame.go index 5b35398..39b44c9 100644 --- a/bot/ingame.go +++ b/bot/ingame.go @@ -279,13 +279,13 @@ func handleChatMessagePacket(c *Client, p pk.Packet) (err error) { sender pk.UUID ) - err = p.Scan(&s, &pos) + err = p.Scan(&s, &pos, &sender) if err != nil { return err } if c.Events.ChatMsg != nil { - err = c.Events.ChatMsg(s, byte(pos)) + err = c.Events.ChatMsg(s, byte(pos), string(sender.Encode())) } return err @@ -327,17 +327,25 @@ func handleUpdateHealthPacket(c *Client, p pk.Packet) (err error) { func handleJoinGamePacket(c *Client, p pk.Packet) error { var ( - eid pk.Int - gamemode pk.UnsignedByte + eid pk.Int + gamemode pk.UnsignedByte + previousGm pk.UnsignedByte + worldCount pk.VarInt + worldNames pk.Identifier + _ pk.NBT + //dimensionCodec pk.NBT dimension pk.Int + worldName pk.Identifier hashedSeed pk.Long maxPlayers pk.UnsignedByte - levelType pk.String viewDistance pk.VarInt rdi pk.Boolean // Reduced Debug Info ers pk.Boolean // Enable respawn screen + isDebug pk.Boolean + isFlat pk.Boolean ) - err := p.Scan(&eid, &gamemode, &dimension, &hashedSeed, &maxPlayers, &levelType, &rdi, &ers) + err := p.Scan(&eid, &gamemode, &previousGm, &worldCount, &worldNames, &dimension, &worldName, + &hashedSeed, &maxPlayers, &rdi, &ers, &isDebug, &isFlat) if err != nil { return err } @@ -346,9 +354,12 @@ func handleJoinGamePacket(c *Client, p pk.Packet) error { c.Gamemode = int(gamemode & 0x7) c.Hardcore = gamemode&0x8 != 0 c.Dimension = int(dimension) - c.LevelType = string(levelType) + c.WorldName = string(worldName) c.ViewDistance = int(viewDistance) c.ReducedDebugInfo = bool(rdi) + c.IsDebug = bool(isDebug) + c.IsFlat = bool(isFlat) + return nil } @@ -442,13 +453,14 @@ func handleChunkDataPacket(c *Client, p pk.Packet) error { var ( X, Z pk.Int FullChunk pk.Boolean + IgnoreOldData pk.Boolean PrimaryBitMask pk.VarInt Heightmaps struct{} Biomes = biomesData{fullChunk: (*bool)(&FullChunk)} Data chunkData BlockEntities blockEntities ) - if err := p.Scan(&X, &Z, &FullChunk, &PrimaryBitMask, pk.NBT{V: &Heightmaps}, &Biomes, &Data, &BlockEntities); err != nil { + if err := p.Scan(&X, &Z, &FullChunk, &IgnoreOldData, &PrimaryBitMask, pk.NBT{V: &Heightmaps}, &Biomes, &Data, &BlockEntities); err != nil { return err } chunk, err := world.DecodeChunkColumn(int32(PrimaryBitMask), Data) diff --git a/bot/mcbot.go b/bot/mcbot.go index cdf7f47..16dadc6 100644 --- a/bot/mcbot.go +++ b/bot/mcbot.go @@ -13,7 +13,7 @@ import ( ) // ProtocolVersion , the protocol version number of minecraft net protocol -const ProtocolVersion = 578 +const ProtocolVersion = 736 // JoinServer connect a Minecraft server for playing the game. func (c *Client) JoinServer(addr string, port int) (err error) { diff --git a/cmd/daze/daze.go b/cmd/daze/daze.go index 69d6e89..acdd252 100644 --- a/cmd/daze/daze.go +++ b/cmd/daze/daze.go @@ -38,7 +38,7 @@ func onGameStart() error { return nil //if err isn't nil, HandleGame() will return it. } -func onChatMsg(c chat.Message, pos byte) error { +func onChatMsg(c chat.Message, pos byte, uuid string) error { log.Println("Chat:", c.ClearString()) // output chat message without any format code (like color or bold) return nil } diff --git a/data/packetIDs.go b/data/packetIDs.go index 7e3493e..18b4690 100644 --- a/data/packetIDs.go +++ b/data/packetIDs.go @@ -37,11 +37,11 @@ const ( OpenHorseWindow KeepAliveClientbound //0x20 - ChunkData // TODO Pre + ChunkData Effect Particle UpdateLight - JoinGame // TODO Pre + JoinGame MapData TradeList EntityRelativeMove @@ -97,8 +97,8 @@ const ( Advancements EntityProperties EntityEffect - DeclareRecipes // TODO Pre - Tags //0x5B + DeclareRecipes + Tags //0x5B ) // Serverbound packet IDs