當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Player.Id方法代碼示例

本文整理匯總了Golang中github.com/minero/minero/server/player.Player.Id方法的典型用法代碼示例。如果您正苦於以下問題:Golang Player.Id方法的具體用法?Golang Player.Id怎麽用?Golang Player.Id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/minero/minero/server/player.Player的用法示例。


在下文中一共展示了Player.Id方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Handle0A

// Handle0A handles incoming requests of packet 0x0A: Player
func Handle0A(server *Server, sender *player.Player) {
	pkt := new(packet.Player)
	pkt.ReadFrom(sender.Conn)

	resp := &packet.Entity{sender.Id()}
	server.BroadcastPacket(resp)
}
開發者ID:KellyLSB,項目名稱:minero-go,代碼行數:8,代碼來源:handle_0a.go

示例2: HandleLogin

func (s *Server) HandleLogin(sender *player.Player) {
	var r packet.Packet

	r = &packet.LoginInfo{
		Entity:     33,
		LevelType:  "default",
		GameMode:   1,
		Dimension:  0,
		Difficulty: 2,
		MaxPlayers: 32,
	}
	r.WriteTo(sender.Conn)

	// BUG(toqueteos): Load nearby chunks
	for z := int32(-1); z < 2; z++ {
		for x := int32(-1); x < 2; x++ {
			VirtualChunks(x, z, 64).WriteTo(sender.Conn)
		}
	}

	const (
		startX = 8.0
		startY = 65.0
		startZ = 8.0
	)

	// Client's spawn position
	r = &packet.SpawnPosition{X: int32(startX), Y: int32(startY), Z: int32(startZ)}
	r.WriteTo(sender.Conn)

	// Client Pos & Look
	r = &packet.PlayerPosLook{
		startX, startY, startZ, // X, Y, Z
		startY + 1.6, // Stance
		0.0, 0.0,     // Yaw + Pitch
		true, // OnGround
	}
	r.WriteTo(sender.Conn)

	// Send nearby clients new client's info
	r = &packet.EntityNamedSpawn{
		Entity: sender.Id(),
		Name:   sender.Name,
		X:      startX, Y: startY, Z: startZ,
		Yaw:      0.0,
		Pitch:    0.0,
		Item:     0,
		Metadata: player.JustLoginMetadata(sender.Name),
	}
	s.BroadcastPacket(r)

	// Instantiate all other users on new client
	s.BroadcastLogin(sender)

	// Save player to server list
	s.AddPlayer(sender)
}
開發者ID:KellyLSB,項目名稱:minero-go,代碼行數:57,代碼來源:login.go

示例3: Handle0C

// Handle0C handles incoming requests of packet 0x0C: PlayerLook
func Handle0C(server *Server, sender *player.Player) {
	pkt := new(packet.PlayerLook)
	pkt.ReadFrom(sender.Conn)

	resp := &packet.EntityLook{
		Entity: sender.Id(),
		Yaw:    pkt.Yaw,
		Pitch:  pkt.Pitch,
	}
	server.BroadcastPacket(resp)
}
開發者ID:KellyLSB,項目名稱:minero-go,代碼行數:12,代碼來源:handle_0c.go

示例4: Handle0D

// Handle0D handles incoming requests of packet 0x0D: PlayerPosLook
func Handle0D(server *Server, sender *player.Player) {
	pkt := new(packet.PlayerPosLook)
	pkt.ReadFrom(sender.Conn)

	if pkt.Y > pkt.Stance {
		r := &packet.Disconnect{"Weird packet 0x0D. Server didn't switch Y with Stance."}
		r.WriteTo(sender.Conn)
		return
	}

	// Player is ready for broadcasts
	sender.SetReady()
	// Save position
	sender.SetPos(pkt.X, pkt.Y, pkt.Z)
	sender.SetLook(pkt.Pitch, pkt.Yaw)

	var p packet.Packet

	// BUG(toqueteos): NMS handle relative movements with other packet
	// `packet.EntityRelMove` right now we just teleport to the destination.
	p = &packet.EntityTeleport{
		Entity: sender.Id(),
		X:      pkt.X,
		Y:      pkt.Y,
		Z:      pkt.Z,
		Yaw:    pkt.Yaw,
		Pitch:  pkt.Pitch,
	}
	server.BroadcastPacket(p)

	p = &packet.EntityHeadLook{
		Entity:  sender.Id(),
		HeadYaw: pkt.Yaw,
	}
	server.BroadcastPacket(p)
}
開發者ID:KellyLSB,項目名稱:minero-go,代碼行數:37,代碼來源:handle_0d.go


注:本文中的github.com/minero/minero/server/player.Player.Id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。