The Formation of Habitable Planets