-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ScreenshotEvent #2602
Add ScreenshotEvent #2602
Conversation
Maybe provide the BufferedImage if people want to change/use that for whatever reason? |
} | ||
|
||
+ net.minecraftforge.client.event.ScreenshotEvent.Pre preEvent = net.minecraftforge.client.ForgeHooksClient.onScreenshotPre(file2); | ||
+ if (preEvent.isCanceled()) return preEvent.getCancelReason(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can make this 2 lines, and so much cleaner by moving code to the forge class.
@LexManos I don't see how it would be possible to move all that code into
There's no way to return all three things from |
The indentation is weird throughout this PR |
Fixed the indentation issues and a couple incorrect braces that I missed before. |
Humm, im not quite sure why you need to return a completely new buffered image from the event. Something along the lines of: Not quite sure why it needs a text return but meh. |
|
Also, yes it could be simplified to one line but this: net.minecraftforge.client.event.ScreenshotEvent.Pre preEvent = net.minecraftforge.client.ForgeHooksClient.onScreenshotPre(bufferedimage, file2); if (preEvent.isCanceled()) return preEvent.getCancelReason(); is very messy and difficult to read. |
I've removed |
@Cancelable | ||
public static class Pre extends ScreenshotEvent | ||
{ | ||
private BufferedImage image; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be final now that the setter is gone.
@kashike |
Github killed my newline, the if was supposed to be on a separate one. 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. |
@LexManos The reason I made it this way is my ShadowTweaks mod adds a couple of things pertaining to screenshots:
If you have a way to make both these work, I would gladly use that, but this is the only solution I've been able to come up with. |
Fire one event. |
I rewrote it to only use one event which reduced the path to 2 lines. This code was used to test it: import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.client.event.ScreenshotEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.io.File;
/**
* @author shadowfacts
*/
@Mod(modid = "ScreenshotEventTest")
public class ScreenshotTest
{
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onScreenshotPre(ScreenshotEvent event) {
// event.setScreenshotFile(new File(event.getScreenshotFile().getParentFile(), "Screenshot_test2.png"));
event.setCancelReason(new TextComponentString("Testerino"));
event.setCanceled(true);
}
} |
Why is it specifically a "CancelReason" and not just a "ResultMessage" or something that gets returned in place of the actual message as long as its not null? I can see myself needing that if I were to implement TwelveIterationMods/EiraIRC#343 ([Upload & Share] Link in Screenshot Message) without hacks. ... of course I could just cancel it and then perform the ImageIO save-to-file myself, but I feel it'd be cleaner to just widen cancelReason to a general result chat component. |
Added |
Anything else? |
Replaced by #2828. |
Adds
ScreenshotEvent.Pre
andScreenshotEvent.Post
which are fired respectively before and after screenshots are taken.Pre
can be used to change the screenshot file and cancel the event.Post
can be used to perform actions on the screenshot after it has been saved.This was tested successfully using: