package net eahraeh Screener import cpw mods fml common gameevent Tick

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package net.eahraeh.Screener;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.IntBuffer;
import net.minecraft.client.Minecraft;
import net.minecraft.util.MathHelper;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;
public class Events
{
private static IntBuffer intBuf;
public static float renderTickTime;
public Events() {}
static BufferedImage getScreenshot()
{
Minecraft mc = Minecraft.func_71410_x();
int width = field_71443_c;
int height = field_71440_d;
GL11.glPixelStorei(3333, 1);
GL11.glPixelStorei(3317, 1);
int intCount = width * height;
if ((intBuf == null) || (intBuf.capacity() < intCount)) {
intBuf = org.lwjgl.BufferUtils.createIntBuffer(intCount);
}
intBuf.clear();
GL11.glReadPixels(0, 0, width, height, 32993, 33639, intBuf);
GL30.glBindFramebuffer(36160, 0);
BufferedImage img = new BufferedImage(width, height, 1);
int[] imgData = ((DataBufferInt)img.getWritableTile(0, 0).getDataBuffer()).getData();
int row = height;
while (row > 0) {
row--;
intBuf.get(imgData, row * width, width);
}
return img;
}
@cpw.mods.fml.common.eventhandler.SubscribeEvent
public void onRenderTickEvent(TickEvent.RenderTickEvent event) {
renderTickTime = renderTickTime;
if (phase == TickEvent.Phase.END) {
if (Message_Screenshot_Request.doingScreenshot == 2) {
Message_Screenshot_Request.doingScreenshot = 1;
} else if (Message_Screenshot_Request.doingScreenshot == 1) {
try {
BufferedImage screenshot = getScreenshot();
ByteBuf buf = Unpooled.buffer();
javax.imageio.ImageIO.write(screenshot, "PNG", new io.netty.buffer.ByteBufOutputStream(buf));
int numParts = MathHelper.func_76123_f(buf.readableBytes() / 32763.0F);
for (int i = 0; i < numParts; i++) {
int bufIdx = i * 32763;
int thisLen = Math.min(buf.readableBytes() - bufIdx, 32763);
ByteBuf sliced = buf.slice(bufIdx, thisLen);
Screener.mainNetworkChannel.sendToServer(new Message_Screenshot_Response(numParts, i, sliced));
}
} catch (IOException var12) {
System.out.println("Ошибка в получении скриншота");
} finally {
Message_Screenshot_Request.doingScreenshot = 0;
}
}
}
}
}