diff --git a/bot/ingame.go b/bot/ingame.go index 1f7acd2..bdf8ea6 100644 --- a/bot/ingame.go +++ b/bot/ingame.go @@ -442,14 +442,14 @@ func handleChunkDataPacket(c *Client, p pk.Packet) error { FullChunk pk.Boolean PrimaryBitMask pk.VarInt Heightmaps struct{} + Biomes = biomesData{fullChunk: (*bool)(&FullChunk)} Data chunkData BlockEntities blockEntities ) - // TODO: Biomes data in this packet - if err := p.Scan(&X, &Z, &FullChunk, &PrimaryBitMask, pk.NBT{V: &Heightmaps}, &Data, &BlockEntities); err != nil { + if err := p.Scan(&X, &Z, &FullChunk, &PrimaryBitMask, pk.NBT{V: &Heightmaps}, &Biomes, &Data, &BlockEntities); err != nil { return err } - chunk, err := world.DecodeChunkColumn(bool(FullChunk), int32(PrimaryBitMask), Data) + chunk, err := world.DecodeChunkColumn(int32(PrimaryBitMask), Data) if err != nil { return fmt.Errorf("decode chunk column fail: %v", err) } @@ -459,6 +459,24 @@ func handleChunkDataPacket(c *Client, p pk.Packet) error { return err } +type biomesData struct { + fullChunk *bool + data [1024]int32 +} + +func (b *biomesData) Decode(r pk.DecodeReader) error { + if b.fullChunk == nil || *b.fullChunk { + return nil + } + for i := range b.data { + err := (*pk.Int)(&b.data[i]).Decode(r) + if err != nil { + return err + } + } + return nil +} + type chunkData []byte type blockEntities []blockEntitie type blockEntitie struct { diff --git a/bot/world/chunk.go b/bot/world/chunk.go index 69216a3..572d94f 100644 --- a/bot/world/chunk.go +++ b/bot/world/chunk.go @@ -9,7 +9,7 @@ import ( ) //DecodeChunkColumn decode the chunk data structure -func DecodeChunkColumn(isFull bool, mask int32, data []byte) (*Chunk, error) { +func DecodeChunkColumn(mask int32, data []byte) (*Chunk, error) { var c Chunk r := bytes.NewReader(data) for sectionY := 0; sectionY < 16; sectionY++ { @@ -60,14 +60,7 @@ func DecodeChunkColumn(isFull bool, mask int32, data []byte) (*Chunk, error) { //用数据填充区块 fillSection(&c.sections[sectionY], perBits(byte(BitsPerBlock)), DataArray, palette) } - // if isFull { //need recive Biomes datas - // _, err := pk.ReadNBytes(data, 256*4) - // if err != nil { - // return nil, fmt.Errorf("read Biomes fail: %v", err) - // } - // } - // fmt.Println(c) return &c, nil }