本文整理匯總了Golang中chunkymonkey/gamerules.IPlayerClient.NotifyChunkLoad方法的典型用法代碼示例。如果您正苦於以下問題:Golang IPlayerClient.NotifyChunkLoad方法的具體用法?Golang IPlayerClient.NotifyChunkLoad怎麽用?Golang IPlayerClient.NotifyChunkLoad使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類chunkymonkey/gamerules.IPlayerClient
的用法示例。
在下文中一共展示了IPlayerClient.NotifyChunkLoad方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: reqSubscribeChunk
func (chunk *Chunk) reqSubscribeChunk(entityId EntityId, player gamerules.IPlayerClient, notify bool) {
if _, ok := chunk.subscribers[entityId]; ok {
// Already subscribed.
return
}
chunk.subscribers[entityId] = player
// Transmit the chunk data to the new player.
buf := new(bytes.Buffer)
// chunk.shard.pktSerial.WritePacketsBuffer(buf, &proto.PacketPreChunk{ //@TODO 1.5.1
// ChunkLoc: chunk.loc,
// Mode: ChunkInit,
// })
player.TransmitPacket(buf.Bytes())
player.TransmitPacket(chunk.chunkPacket())
if notify {
player.NotifyChunkLoad()
}
// Send spawn packets for all entities in the chunk to the player.
if len(chunk.entities) > 0 {
buf := new(bytes.Buffer)
for _, entity := range chunk.entities {
pkts := entity.SpawnPackets(nil)
chunk.shard.pktSerial.WritePacketsBuffer(buf, pkts...)
}
player.TransmitPacket(buf.Bytes())
}
// Spawn existing players for new player.
if len(chunk.playersData) > 0 {
buf := new(bytes.Buffer)
for _, existing := range chunk.playersData {
if existing.entityId != entityId {
pkts := existing.SpawnPackets(nil)
chunk.shard.pktSerial.WritePacketsBuffer(buf, pkts...)
}
}
player.TransmitPacket(buf.Bytes())
}
}
示例2: reqSubscribeChunk
func (chunk *Chunk) reqSubscribeChunk(entityId EntityId, player gamerules.IPlayerClient, notify bool) {
if _, ok := chunk.subscribers[entityId]; ok {
// Already subscribed.
return
}
chunk.subscribers[entityId] = player
buf := new(bytes.Buffer)
proto.WritePreChunk(buf, &chunk.loc, ChunkInit)
player.TransmitPacket(buf.Bytes())
player.TransmitPacket(chunk.chunkPacket())
if notify {
player.NotifyChunkLoad()
}
// Send spawns packets for all entities in the chunk.
if len(chunk.entities) > 0 {
buf := new(bytes.Buffer)
for _, e := range chunk.entities {
e.SendSpawn(buf)
}
player.TransmitPacket(buf.Bytes())
}
// Spawn existing players for new player.
if len(chunk.playersData) > 0 {
playersPacket := new(bytes.Buffer)
for _, existing := range chunk.playersData {
if existing.entityId != entityId {
existing.sendSpawn(playersPacket)
}
}
player.TransmitPacket(playersPacket.Bytes())
}
}