Add ScreenshotEvent (#2828)

Add ScreenshotEvent
This commit is contained in:
Shadowfacts authored and LexManos committed 2016-05-09 14:51:30 -07:00
1 parent aaa146c10d
commit 58d26618f6
3 files changed
+94

No files matched your search

@@ -6,6 +6,8 @@ import static net.minecraftforge.common.ForgeVersion.Status.BETA_OUTDATED;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL20.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Collections;
@@ -77,6 +79,7 @@ import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.ScreenshotEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
import net.minecraftforge.client.model.IPerspectiveAwareModel;
@@ -705,4 +708,12 @@ public class ForgeHooksClient
{
MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.Post(new RenderGameOverlayEvent(Animation.getPartialTickTime(), res), BOSSINFO));
}
public static ScreenshotEvent onScreenshot(BufferedImage image, File screenshotFile)
{
ScreenshotEvent event = new ScreenshotEvent(image, screenshotFile);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
}
@@ -0,0 +1,67 @@
package net.minecraftforge.client.event;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import java.awt.image.BufferedImage;
import java.io.File;
/**
* This event is fired before and after a screenshot is taken
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}
* This event is {@link Cancelable}
*
* {@link #screenshotFile} contains the file the screenshot will be/was saved to
* {@link #image} contains the {@link BufferedImage} that will be saved
* {@link #resultMessage} contains the {@link ITextComponent} to be returned. If {@code null}, the default vanilla message will be used instead
*/
@Cancelable
public class ScreenshotEvent extends Event
{
public static final ITextComponent DEFAULT_CANCEL_REASON = new TextComponentString("Screenshot canceled");
private BufferedImage image;
private File screenshotFile;
private ITextComponent resultMessage = null;
public ScreenshotEvent(BufferedImage image, File screenshotFile)
{
this.image = image;
this.screenshotFile = screenshotFile;
}
public BufferedImage getImage()
{
return image;
}
public File getScreenshotFile()
{
return screenshotFile;
}
public void setScreenshotFile(File screenshotFile)
{
this.screenshotFile = screenshotFile;
}
public ITextComponent getResultMessage()
{
return resultMessage;
}
public void setResultMessage(ITextComponent resultMessage)
{
this.resultMessage = resultMessage;
}
public ITextComponent getCancelMessage()
{
return getResultMessage() != null ? getResultMessage() : DEFAULT_CANCEL_REASON;
}
}