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()) } }