Minecraftforge: JavaDocs for ScreenshotEvent is erroneous

Created on 23 Jul 2020  ·  3Comments  ·  Source: MinecraftForge/MinecraftForge


Minecraft Version: 1.9 - 1.16+

Ever since the event was introduced in Forge for 1.9 (#2828) it has contained the following line:

This event is fired before and after a screenshot is taken

Lex saw no reason for the Pre/Post event of that so it was changed to only contain one event call:

And again, i'm still not even convinced that there needs to be a pre/post event to this. Not EVERY event needs a pre/post.

Yet the docs weren't updated by the guy to reflect the change, whether the latest 1.16.x branch or 1.9 since merge.

The doc line should be removed as misleading from all these branches:

This event is fired before the screenshot file was written (and therefore before a chat message appears) but after the screen buffer has been captured, so the event processors do receive the BufferedImage.


I thought I'd write up an issue instead of spamming 8 PRs for each branch (& a CLA uh-oh).

1.15 1.16 Cleanup

Most helpful comment

Not your fault here, Lex, the guy forgot to fix the javadoc after implementing your request :)

I will consider to join you guys on Discord to contribute.


Now that @LotuxPunk came up with that again, I will comment on the problems with the event and code surrounding it. First, the flow:

  1. MC listens in some loop for F2 key press
  2. MC calls a take screen func that returns the TextComponent that's put into chat (from the loop above)
  3. take screen calls capture buffer
    a. If event is not cancelled, TextComponent is returned and file saved
    b. If event is cancelled, the buffer has already been captured, file not saved. Yet since that function returns a TextC - the best you can do is to return an empty text, empty line will appear in chat*

My idea was to re-schedule the screenshot, so it would capture less/more debug info rendered by my mod (chunk/region outlines etc.) It works. Yet due to the empty line appearing on the following screenshot I had to remove it manually from chat. Since MC's removeLine ( id ) doesn't just remove one line at key id (at least in my ver, don't roll your eyes) I had to manually grab a ref to the chat history + recent messages Lists to remove them properly.

Regardless of how I do it and what for:

  • You cannot cancel the capture of the current screen buffer (a "pre" hook at Step 1 above)
  • If you cancel the event (current "post" hook), you still get a chat line

    • if you overwrite the msg to be empty: confusion and empty line in both chat and log

    • if you want to do it proper like I did, you are onto more digging into MC GUI internals

Idk what the guidance with Forge events is, but I think there should be actually 3 events/states:

  • Early hook: after F2 registered, but before take screen called (to prevent the chat message or buffer capture on cancellation)
  • Current hook: with filled screen buffer (buffer/chat msg modification or general event listeners)
  • Late hook: image encoded and file written (for post-actions on file)

@LotuxPunk with the current event hook: the idea is you modify the captured screen buffer as part of the event, not wait until its written to file.

All 3 comments

So there won't be a second event when the file is created? I just needed it! 😅

I wanted to convert the image directly at the source 😅

There are quite a few javadocs issues, I have always stated that I am crap with documentation.
I would suggest that if you care about javadocs, it may be worth getting a couple people together and doing a big sweep of cleaning/adding javadocs.
It may be the next omnibus branch?

Not your fault here, Lex, the guy forgot to fix the javadoc after implementing your request :)

I will consider to join you guys on Discord to contribute.


Now that @LotuxPunk came up with that again, I will comment on the problems with the event and code surrounding it. First, the flow:

  1. MC listens in some loop for F2 key press
  2. MC calls a take screen func that returns the TextComponent that's put into chat (from the loop above)
  3. take screen calls capture buffer
    a. If event is not cancelled, TextComponent is returned and file saved
    b. If event is cancelled, the buffer has already been captured, file not saved. Yet since that function returns a TextC - the best you can do is to return an empty text, empty line will appear in chat*

My idea was to re-schedule the screenshot, so it would capture less/more debug info rendered by my mod (chunk/region outlines etc.) It works. Yet due to the empty line appearing on the following screenshot I had to remove it manually from chat. Since MC's removeLine ( id ) doesn't just remove one line at key id (at least in my ver, don't roll your eyes) I had to manually grab a ref to the chat history + recent messages Lists to remove them properly.

Regardless of how I do it and what for:

  • You cannot cancel the capture of the current screen buffer (a "pre" hook at Step 1 above)
  • If you cancel the event (current "post" hook), you still get a chat line

    • if you overwrite the msg to be empty: confusion and empty line in both chat and log

    • if you want to do it proper like I did, you are onto more digging into MC GUI internals

Idk what the guidance with Forge events is, but I think there should be actually 3 events/states:

  • Early hook: after F2 registered, but before take screen called (to prevent the chat message or buffer capture on cancellation)
  • Current hook: with filled screen buffer (buffer/chat msg modification or general event listeners)
  • Late hook: image encoded and file written (for post-actions on file)

@LotuxPunk with the current event hook: the idea is you modify the captured screen buffer as part of the event, not wait until its written to file.

Was this page helpful?
0 / 5 - 0 ratings