Automatically switch Touch Bar to function keys for Minecraft only Under System Preferences → Keyboard → Shortcuts → Function Keys, you can register apps to always show the function keys on the Touch Bar. I want to add Minecraft. However, Minecraft has an unusual structure where the app is actually just a launcher, then you hit a button and it opens the game in a Java window. That means the function keys then show up in the launcher, but not the game proper.
I’ve tried adding the “java” executable to the function keys list by right clicking it while running, selecting Options → Show in Finder, then both dragging and dropping that file into the window and navigating to it from the Function Keys window, but in both cases the GUI didn’t accept the file to be added to Function Keys list.
macOS version: 11.3.1
Minecraft version: 1.16.5
Open Terminal and run the following commands from ravbug.com/tutorials/mc-touchbar:
defaults write com.apple.touchbar.agent PresentationModePerApp -dict-add net.java.openjdk.cmd functionKeys
sudo killall TouchBarServer NowPlayingTouchUI ControlStrip

You will probably need to enter your password.
The first line edits the necessary config file manually, bypassing System Preferences, and the second causes the Touch Bar to reload its configuration.
After doing this, editing the function keys list using System Preferences will (a) fail to show java in the list, even though it’s there, and (b) delete java from the list if you make any changes. In that case you can repeat the above process to re-add it.

Workaround 1: Go to System Preferences → Keyboard → Keyboard and change the “Touch Bar shows” value manually when switching to and from the game.
Workaround 2: Go to System Preferences → Keyboard → Keyboard and change “Touch Bar shows” to always show the function keys. Since you’ll lose shortcuts to adjust brightness and volume, you probably want to then click on the control center icon in the menu bar and drag commonly used controls into the menu bar.