In a medium bowl, whisk together egg yolks and sugar until the mixture is pale yellow and slightly thickened, about 1 minute.
Whisk in cornstarch until completely smooth with no lumps.
In a heavy-bottomed saucepan, heat half of the milk over medium-low heat until small bubbles appear at the edges (do not boil).
Slowly pour the hot milk into the egg yolk mixture while whisking constantly to temper it—this prevents scrambling.
Pour everything back into the saucepan and cook over medium heat, whisking almost continuously for 3-5 minutes until the mixture thickens enough to coat the back of a spoon (about 170°F).
Remove from heat and stir in butter and vanilla extract until fully melted and combined.
Press plastic wrap directly onto the surface of the pastry cream to prevent a skin from forming, then refrigerate for at least 2 hours before using.