This is PS 101 but worth understanding...
The iconic 3 terminal regulators are hard to kill with all kinds of built in protection. The thermal shut down is one of those protections, back in the day before they got smart they would just melt and release their magic smoke, but back in the day we didn't have 3 terminal regulators at all.
In an ideal world for semiconductors, cooler is always better for longer life and reliability, so beyond just not thermalling, it would be better to run it even cooler.
In practice 3 terminal regulators want a few volts across them to regulate with so 24V output wants 27+ input voltage. Then add some extra for ripple, since that voltage headroom needs to be from the lowest ripple voltage.
Peter described the math for power dissipation in a pass element (voltage dropped across the device times current).
There are several ways to drop the unregulated voltage.... with a constant current draw of 0.35A every 1 ohm in series will drop .35V, so 20 ohms in series would drop roughly 7V and get the unreg down to a happier 29V unreg..... BUT now that resistor is dissipating power itself, (P=I^2xR) so around 2.5W (not a tiny resistor. )
Some less obvious tricks are using a smaller reservoir cap, so the higher ripple voltage would result in less average unregulated voltage. Another circuit trick is to change to half-wave rectified (if you aren't already) The unregulated voltage will be lower again. Finally a trick I have used to scrape off some unregulated voltage is to add a series resistor before the diode charging the reservoir cap, this will drop more voltage when the cap is charging and drawing high current, for less wasted power as heat. But I can't give you an easy answer for how much resistor, just a lot less than 20 ohms.
Good luck... It is not uncommon to use heatsinks for regulators, I've even seen them bolted to metal chassis, but look out for ground loops when you do that.
JR