Add ScreenshotEvent (#2828)

Add ScreenshotEvent
This commit is contained in:
Shadowfacts 2016-05-09 17:51:30 -04:00 committed by LexManos
parent aaa146c10d
commit 58d26618f6
3 changed files with 94 additions and 0 deletions

View file

@ -0,0 +1,16 @@
--- ../src-base/minecraft/net/minecraft/util/ScreenShotHelper.java
+++ ../src-work/minecraft/net/minecraft/util/ScreenShotHelper.java
@@ -52,10 +52,13 @@
file2 = new File(file1, p_148259_1_);
}
+ net.minecraftforge.client.event.ScreenshotEvent event = net.minecraftforge.client.ForgeHooksClient.onScreenshot(bufferedimage, file2);
+ if (event.isCanceled()) return event.getCancelMessage(); else file2 = event.getScreenshotFile();
ImageIO.write(bufferedimage, "png", (File)file2);
ITextComponent itextcomponent = new TextComponentString(file2.getName());
itextcomponent.func_150256_b().func_150241_a(new ClickEvent(ClickEvent.Action.OPEN_FILE, file2.getAbsolutePath()));
itextcomponent.func_150256_b().func_150228_d(Boolean.valueOf(true));
+ if (event.getResultMessage() != null) return event.getResultMessage();
return new TextComponentTranslation("screenshot.success", new Object[] {itextcomponent});
}
catch (Exception exception)

View file

@ -6,6 +6,8 @@ import static net.minecraftforge.common.ForgeVersion.Status.BETA_OUTDATED;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL20.*; import static org.lwjgl.opengl.GL20.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.util.Collections; 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.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.ScreenshotEvent;
import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.event.sound.PlaySoundEvent; import net.minecraftforge.client.event.sound.PlaySoundEvent;
import net.minecraftforge.client.model.IPerspectiveAwareModel; 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)); 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;
}
} }

View file

@ -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;
}
}