How to target a specific event registration form in an extension
Digging into the hook reference documentation at https://docs.civicrm.org/dev/en/master/hooks/hook_civicrm_buildForm/ I can see that the correct approach is

if ($form-&gt;_eventId == 1) {