The impact of mechanical AGN feedback on the formation of massive early-type galaxies