Opening System Preferences and navigating to Keyboard > Shortcuts > Function Keys does not allow you to add the Java executable so that you can use the numbered function keys on the Touch Bar while playing Minecraft Java Edition. Fortunately, you can work around this limitation with a simple terminal command.
  1. Open Terminal
    There are a few ways to do this. You can open /Applications/Utilities in the Finder and double-click Terminal, or you can search for Terminal in spotlight.
  2. Paste the following command into Terminal and press return:
    Java 14 or older
    defaults write com.apple.touchbar.agent PresentationModePerApp -dict-add net.java.openjdk.cmd functionKeys
    Java 16 or newer
    defaults write com.apple.touchbar.agent PresentationModePerApp -dict-add net.java.openjdk.java functionKeys

    This will add Java to the list of programs set to display the numbered function row keys. It will not be visible in the System Preferences window.
  3. Open Activity Monitor.
    You can open this program with spotlight or by navigating to /Applications/Utilities in Finder like you did to open Terminal.
  4. Search for touch and select all listed TouchBar processes. There may be more than just TouchBarServer listed. Select them in the list, press the gray x button in the toolbar, then press Quit on the dropdown.

    The TouchBar should go blank and then re-appear.
  5. Open Minecraft. The TouchBar should show the numbered function row keys instead of the Control Strip and a large blank space.
Once you have followed these steps, you can use the function row keys to easily bring up the debug screen, switch cameras, and take screenshots without needing to press FN.

Shortcut commands for power users 🔗

Enable (Java 8-14): defaults write com.apple.touchbar.agent PresentationModePerApp -dict-add net.java.openjdk.cmd functionKeys && sudo killall TouchBarServer NowPlayingTouchUI ControlStrip
Enable (Java 16): defaults write com.apple.touchbar.agent PresentationModePerApp -dict-add net.java.openjdk.java functionKeys && sudo killall TouchBarServer NowPlayingTouchUI ControlStrip