bot is nolonger a submodule

This commit is contained in:
JunDao
2019-05-01 16:09:36 +08:00
parent 6055f2ca7b
commit 45820c10f5
12 changed files with 1447 additions and 1 deletions

157
bot/world/chunk.go Normal file
View File

@ -0,0 +1,157 @@
package gomcbot
// import (
// "bytes"
// "fmt"
// pk "github.com/Tnze/gomcbot/network/packet"
// "io"
// )
// func unpackChunkDataPacket(p *pk.Packet, hasSkyLight bool) (c *Chunk, x, y int, err error) {
// reader := bytes.NewReader(p.Data)
// //区块坐标
// X, err := pk.UnpackInt32(reader)
// if err != nil {
// return nil, 0, 0, err
// }
// Y, err := pk.UnpackInt32(reader)
// if err != nil {
// return nil, 0, 0, err
// }
// // fmt.Println("Chunk: (", X, ", ", Y, ")") //Debug: Show Chunk loc
// fc, err := reader.ReadByte()
// if err != nil {
// return nil, 0, 0, err
// }
// FullChunk := fc != 0x00
// //主掩码
// PrimaryBitMask, err := pk.UnpackVarInt(reader)
// if err != nil {
// return nil, 0, 0, err
// }
// //区块数据
// Size, err := pk.UnpackVarInt(reader)
// if err != nil {
// return nil, 0, 0, err
// }
// Data := make([]byte, Size)
// _, err = io.ReadAtLeast(reader, Data, int(Size))
// if err != nil {
// return nil, 0, 0, err
// }
// //实体信息
// // NumberofBlockEntities, len := pk.UnpackVarInt(p.Data[index:])
// // index += len
// //解析区块数据
// cc, err := readChunkColumn(FullChunk, PrimaryBitMask, bytes.NewReader(Data), hasSkyLight)
// if err != nil {
// panic(err)
// }
// return cc, int(X), int(Y), err
// }
// func readChunkColumn(isFull bool, mask int32, data *bytes.Reader, hasSkyLight bool) (*Chunk, error) {
// var c Chunk
// for sectionY := 0; sectionY < 16; sectionY++ {
// if (mask & (1 << uint(sectionY))) != 0 { // Is the given bit set in the mask?
// BitsPerBlock, err := data.ReadByte()
// if err != nil {
// return nil, fmt.Errorf("read BitsPerBlock fail: %v", err)
// }
// //读调色板
// var palette []uint
// if BitsPerBlock < 9 {
// length, err := pk.UnpackVarInt(data)
// if err != nil {
// return nil, fmt.Errorf("read palette (id len) fail: %v", err)
// }
// palette = make([]uint, length)
// for id := uint(0); id < uint(length); id++ {
// stateID, err := pk.UnpackVarInt(data)
// if err != nil {
// return nil, fmt.Errorf("read palette (id) fail: %v", err)
// }
// palette[id] = uint(stateID)
// }
// }
// //Section数据
// DataArrayLength, err := pk.UnpackVarInt(data)
// if err != nil {
// return nil, fmt.Errorf("read DataArrayLength fail: %v", err)
// }
// DataArray := make([]int64, DataArrayLength)
// for i := 0; i < int(DataArrayLength); i++ {
// DataArray[i], err = pk.UnpackInt64(data)
// if err != nil {
// return nil, fmt.Errorf("read DataArray fail: %v", err)
// }
// }
// //用数据填充区块
// fillSection(&c.sections[sectionY], perBits(BitsPerBlock), DataArray, palette)
// //throw BlockLight data
// _, err = pk.ReadNBytes(data, 2048)
// if err != nil {
// return nil, fmt.Errorf("read BlockLight fail: %v", err)
// }
// if hasSkyLight {
// //throw SkyLight data
// _, err = pk.ReadNBytes(data, 2048)
// if err != nil {
// return nil, fmt.Errorf("read SkyLight fail: %v", err)
// }
// }
// }
// }
// 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
// }
// const defaultBitsPerBlock = 14
// func perBits(BitsPerBlock byte) uint {
// switch {
// case BitsPerBlock <= 4:
// return 4
// case BitsPerBlock < 9:
// return uint(BitsPerBlock)
// default:
// return defaultBitsPerBlock
// }
// }
// func fillSection(s *Section, bpb uint, DataArray []int64, palette []uint) {
// mask := uint(1<<bpb - 1)
// for n := 0; n < 16*16*16; n++ {
// offset := uint(n * int(bpb))
// data := uint(DataArray[offset/64])
// data >>= offset % 64
// if offset%64 > 64-bpb {
// l := bpb + offset%64 - 64
// data &= uint(DataArray[offset/64+1] << l)
// }
// data &= mask
// if bpb < 9 {
// s.blocks[n%16][n/(16*16)][n%(16*16)/16].id = palette[data]
// } else {
// s.blocks[n%16][n/(16*16)][n%(16*16)/16].id = data
// }
// }
// }

View File

@ -0,0 +1,9 @@
package entity
//Entity is the entity of minecraft
type Entity struct {
EntityID int //实体ID
}
type Solt struct {
}

View File

@ -0,0 +1,20 @@
package player
import "github.com/Tnze/go-mc/bot/world/entity"
// Player includes the player's status.
type Player struct {
entity.Entity
UUID [2]int64 //128bit UUID
X, Y, Z float64
Yaw, Pitch float32
OnGround bool
HeldItem int //拿着的物品栏位
Inventory []entity.Solt
Health float32 //血量
Food int32 //饱食度
FoodSaturation float32 //食物饱和度
}

78
bot/world/motion.go Normal file
View File

@ -0,0 +1,78 @@
package gomcbot
// import (
// "math"
// "time"
// )
// // SetPosition method move your character around.
// // Server will ignore this if changes too much.
// func (g *Client) SetPosition(x, y, z float64, onGround bool) {
// g.motion <- func() {
// g.player.X, g.player.Y, g.player.Z = x, y, z
// g.player.OnGround = onGround
// sendPlayerPositionPacket(g) //向服务器更新位置
// }
// }
// // LookAt method turn player's hand and make it look at a point.
// func (g *Client) LookAt(x, y, z float64) {
// x0, y0, z0 := g.player.X, g.player.Y, g.player.Z
// x, y, z = x-x0, y-y0, z-z0
// r := math.Sqrt(x*x + y*y + z*z)
// yaw := -math.Atan2(x, z) / math.Pi * 180
// for yaw < 0 {
// yaw = 360 + yaw
// }
// pitch := -math.Asin(y/r) / math.Pi * 180
// g.LookYawPitch(float32(yaw), float32(pitch))
// }
// // LookYawPitch set player's hand to the direct by yaw and pitch.
// // yaw can be [0, 360) and pitch can be (-180, 180).
// // if |pitch|>90 the player's hand will be very strange.
// func (g *Client) LookYawPitch(yaw, pitch float32) {
// g.motion <- func() {
// g.player.Yaw, g.player.Pitch = yaw, pitch
// sendPlayerLookPacket(g) //向服务器更新朝向
// }
// }
// // SwingHand sent when the player's arm swings.
// // if hand is true, swing the main hand
// func (g *Client) SwingHand(hand bool) {
// if hand {
// sendAnimationPacket(g, 0)
// } else {
// sendAnimationPacket(g, 1)
// }
// }
// // Dig a block in the position and wait for it's breaked
// func (g *Client) Dig(x, y, z int) error {
// b := g.GetBlock(x, y, z).id
// sendPlayerDiggingPacket(g, 0, x, y, z, Top) //start
// sendPlayerDiggingPacket(g, 2, x, y, z, Top) //end
// for {
// time.Sleep(time.Millisecond * 50)
// if g.GetBlock(x, y, z).id != b {
// break
// }
// g.SwingHand(true)
// }
// return nil
// }
// // UseItem use the item in hand.
// // if hand is true, swing the main hand
// func (g *Client) UseItem(hand bool) {
// if hand {
// sendUseItemPacket(g, 0)
// } else {
// sendUseItemPacket(g, 1)
// }
// }

68
bot/world/world.go Normal file
View File

@ -0,0 +1,68 @@
package gomcbot
// //World record all of the things in the world where player at
// type world struct {
// Entities map[int32]Entity
// chunks map[chunkLoc]*Chunk
// }
// //Chunk store a 256*16*16 clolumn blocks
// type Chunk struct {
// sections [16]Section
// }
// //Section store a 16*16*16 cube blocks
// type Section struct {
// blocks [16][16][16]Block
// }
// //Block is the base of world
// type Block struct {
// id uint
// }
// type chunkLoc struct {
// X, Y int
// }
// //Entity 表示一个实体
// type Entity interface {
// EntityID() int32
// }
// //Face is a face of a block
// type Face byte
// // All six faces in a block
// const (
// Bottom Face = iota
// Top
// North
// South
// West
// East
// )
// // getBlock return the block in the position (x, y, z)
// func (w *world) getBlock(x, y, z int) Block {
// c := w.chunks[chunkLoc{x >> 4, z >> 4}]
// if c != nil {
// cx, cy, cz := x&15, y&15, z&15
// /*
// n = n&(16-1)
// is equal to
// n %= 16
// if n < 0 { n += 16 }
// */
// return c.sections[y/16].blocks[cx][cy][cz]
// }
// return Block{id: 0}
// }
// func (b Block) String() string {
// return blockNameByID[b.id]
// }

9
bot/world/world_test.go Normal file
View File

@ -0,0 +1,9 @@
package gomcbot
// import "testing"
// func TestBlockString(t *testing.T) {
// for i := uint(0); i < 8598+1; i++ {
// t.Log(Block{id: i})
// }
// }