net.minecraft.util.ScreenShotHelper Java Examples

The following examples show how to use net.minecraft.util.ScreenShotHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MixinMinecraft.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(
    method = "dispatchKeypresses",
    at = @At(
        value = "INVOKE",
        shift = At.Shift.BEFORE,
        target = "Lnet/minecraft/client/gui/GuiNewChat;printChatMessage(Lnet/minecraft/util/IChatComponent;)V",
        ordinal = 1
    ),
    cancellable = true
)
private void dispatchKeypresses(CallbackInfo ci) {
    IChatComponent chatComponent = ScreenShotHelper.saveScreenshot(mcDataDir, displayWidth, displayHeight, framebufferMc);
    new TextComponent(chatComponent).chat();
    ci.cancel();
}
 
Example #2
Source File: GuiSchematicManager.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void createAndSetPreviewImage()
{
    LitematicaSchematic schematic = LitematicaSchematic.createFromFile(this.dir, this.fileName);

    if (schematic != null)
    {
        try
        {
            Minecraft mc = Minecraft.getMinecraft();
            BufferedImage screenshot = ScreenShotHelper.createScreenshot(mc.displayWidth, mc.displayHeight, mc.getFramebuffer());

            int x = screenshot.getWidth() >= screenshot.getHeight() ? (screenshot.getWidth() - screenshot.getHeight()) / 2 : 0;
            int y = screenshot.getHeight() >= screenshot.getWidth() ? (screenshot.getHeight() - screenshot.getWidth()) / 2 : 0;
            int longerSide = Math.min(screenshot.getWidth(), screenshot.getHeight());
            //System.out.printf("w: %d, h: %d, x: %d, y: %d\n", screenshot.getWidth(), screenshot.getHeight(), x, y);

            int previewDimensions = 140;
            double scaleFactor = (double) previewDimensions / longerSide;
            BufferedImage scaled = new BufferedImage(previewDimensions, previewDimensions, BufferedImage.TYPE_INT_ARGB);
            AffineTransform at = new AffineTransform();
            at.scale(scaleFactor, scaleFactor);
            AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);

            Graphics2D graphics = scaled.createGraphics();
            graphics.drawImage(screenshot.getSubimage(x, y, longerSide, longerSide), scaleOp, 0, 0);

            int[] pixels = scaled.getRGB(0, 0, previewDimensions, previewDimensions, null, 0, scaled.getWidth());

            schematic.getMetadata().setPreviewImagePixelData(pixels);
            schematic.getMetadata().setTimeModifiedToNow();

            schematic.writeToFile(this.dir, this.fileName, true);

            InfoUtils.showGuiOrInGameMessage(MessageType.SUCCESS, "litematica.info.schematic_manager.preview.success");
        }
        catch (Exception e)
        {
            Litematica.logger.warn("Exception while creating preview image", e);
        }
    }
    else
    {
        InfoUtils.showGuiOrInGameMessage(MessageType.ERROR, "litematica.error.schematic_rename.read_failed");
    }
}