Example #1
0
func (p *Position) ToMessage() *message.Position {
	x := round(p.X) % message.BlockLen
	y := round(p.Y) % message.BlockLen
	bx := round((p.X - float64(x)) / message.BlockLen)
	by := round((p.Y - float64(y)) / message.BlockLen)

	return &message.Position{
		BX: message.BlockCoord(bx),
		BY: message.BlockCoord(by),
		X:  message.PointCoord(x),
		Y:  message.PointCoord(y),
	}
}
Example #2
0
		if code != message.LoginResponseCodes["ok"] {
			return nil
		}

		conn.State = message.LoggedIn

		// Get entity
		session := ctx.Auth.GetSession(conn.Id)
		if session == nil {
			return errors.New("Cannot get newly logged in user's session")
		}

		// Send initial terrain
		log.Println("Sending initial terrain")
		pos := session.Entity.Position
		radius := message.BlockCoord(8)
		blks := []*message.Block{}
		for i := pos.BX - radius; i <= pos.BX+radius; i++ {
			for j := pos.BY - radius; j <= pos.BY+radius; j++ {
				blk, err := ctx.Terrain.GetBlockAt(i, j)
				if err != nil {
					log.Println("Cannot send initial terrain to client", err)
					continue
				}

				blks = append(blks, blk)
			}
		}
		err = conn.Write(func(w io.Writer) error {
			return builder.SendChunksUpdate(w, ctx.Clock.GetRelativeTick(), blks)
		})