Skip to content

Commit

Permalink
UDOC-0 - Change names; Allow rotating isometric screenshot; Save isom…
Browse files Browse the repository at this point in the history
…etric screenshot to screenshots folder
  • Loading branch information
telvarost committed Mar 3, 2024
1 parent 1a4aecb commit 0b35e8f
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 69 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Special thanks to Birevan and Exalm for the original version of the mod!
* Ability to change photo key bindings using controls menu in options.
* ISOMETRIC_PHOTO_KEYBIND (default F7) — isometric screenshot (PNG)
* Change the scale for isometric screenshots (default 16) with GlassConfigAPI.
* HUGE_PHOTO_KEYBIND (default F6) — huge screenshot (PNG)
* Left/Right Ctrl/⌘ + HUGE_PHOTO_KEYBINDhuge screenshot (TGA)
* Change the resolution for huge screenshots (default 7680×2240) with GlassConfigAPI.
* CUSTOM_RESOLUTION_PHOTO_KEYBIND (default F6) — custom resolution screenshot (PNG)
* Left/Right Ctrl/⌘ + CUSTOM_RESOLUTION_PHOTO_KEYBINDcustom resolution screenshot (TGA)
* Change the resolution for custom screenshots (default 7680×2240) with GlassConfigAPI.

## Installation using Prism Launcher

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ yarn_mappings=b1.7.3-build.2
loader_version=0.14.24-babric.1

# Mod Properties
mod_version=1.1.0
mod_version=1.2.0
maven_group=com.github.telvarost
archives_base_name=BetterScreenshots

Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/github/telvarost/betterscreenshots/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ public static class ConfigFields {
@ConfigName("Isometric Screenshot Resolution")
@MaxLength(255)
@Comment("Default Value: 16")
public static Integer isomScale = 16;
public static Integer isometricPhotoScale = 16;

@ConfigName("Panorama Image Width In Pixels")
@ConfigName("Isometric Screenshot Rotation")
@MaxLength(3)
@Comment("0=0deg, 1=90deg, 2=180deg, 3=270deg")
public static Integer isometricPhotoRotation = 0;

@ConfigName("Custom Image Width In Pixels")
@MaxLength(36863)
@Comment("Default Value: 7680")
public static Integer hugeWidth = 7680;
public static Integer customResolutionPhotoWidth = 7680;

@ConfigName("Panorama Image Height In Pixels")
@ConfigName("Custom Image Height In Pixels")
@MaxLength(36863)
@Comment("Default Value: 2240")
public static Integer hugeHeight = 2240;
public static Integer customResolutionPhotoHeight = 2240;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.text.DecimalFormat;
import java.util.Date;

import javax.imageio.ImageIO;

Expand Down Expand Up @@ -36,8 +37,10 @@ public class IsometricScreenshotRenderer {
private float maxCloudHeight = 108.0F;
private ByteBuffer byteBuffer;
private FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(16);
private File gameDirectory;

public IsometricScreenshotRenderer(Minecraft minecraft) {
public IsometricScreenshotRenderer(Minecraft minecraft, File _gameDirectory) {
this.gameDirectory = _gameDirectory;
this.progressUpdate = minecraft.progressListener;
this.mc = minecraft;
this.worldObj = this.mc.level;
Expand All @@ -52,11 +55,16 @@ public IsometricScreenshotRenderer(Minecraft minecraft) {

private File getOutputFile() {
File file = null;
int scrNumber = 0;
int scrNumber = 1;

do {
File home = new File(System.getProperty("user.home", "."));
file = new File(home, "mc_map_" + this.decimalFormat.format(scrNumber++) + ".png");
File outputFilePath = new File(this.gameDirectory, "screenshots");
outputFilePath.mkdir();
if (1 == scrNumber) {
file = new File(outputFilePath, "isometric_" + ModHelper.dateFormat.format(new Date()) + ".png");
} else {
file = new File(outputFilePath, "isometric_" + ModHelper.dateFormat.format(new Date()) + "_" + scrNumber + ".png");
}
} while(file.exists());

return file.getAbsoluteFile();
Expand Down Expand Up @@ -90,8 +98,8 @@ public void doRender() {
System.out.println(posX + " " + posZ);

try {
int i1 = (this.width * Config.ConfigFields.isomScale) + (this.length * Config.ConfigFields.isomScale);
int i3 = (this.height * Config.ConfigFields.isomScale) + i1 / 2;
int i1 = (this.width * Config.ConfigFields.isometricPhotoScale) + (this.length * Config.ConfigFields.isometricPhotoScale);
int i3 = (this.height * Config.ConfigFields.isometricPhotoScale) + i1 / 2;
BufferedImage image = new BufferedImage(i1, i3, 1);
Graphics graphics = image.getGraphics();
int dWidth = this.mc.actualWidth;
Expand Down Expand Up @@ -120,15 +128,15 @@ public void doRender() {
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glTranslatef((float)-i10, (float)-i12, -5000.0F);
GL11.glScalef((float)Config.ConfigFields.isomScale, (float)-Config.ConfigFields.isomScale, (float)-Config.ConfigFields.isomScale);
GL11.glScalef((float)Config.ConfigFields.isometricPhotoScale, (float)-Config.ConfigFields.isometricPhotoScale, (float)-Config.ConfigFields.isometricPhotoScale);
this.floatBuffer.clear();
this.floatBuffer.put(1.0F).put(-0.5F).put(0.0F).put(0.0F);
this.floatBuffer.put(0.0F).put(1.0F).put(-1.0F).put(0.0F);
this.floatBuffer.put(1.0F).put(0.5F).put(0.0F).put(0.0F);
this.floatBuffer.put(0.0F).put(0.0F).put(0.0F).put(1.0F);
this.floatBuffer.flip();
GL11.glMultMatrix(this.floatBuffer);
GL11.glRotatef(0.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(Config.ConfigFields.isometricPhotoRotation * 90.0F, 0.0F, 1.0F, 0.0F);
GL11.glTranslated(posX, 0, posZ);
GL11.glTranslated(-this.mc.viewEntity.prevRenderX, (double)-this.height / 2.0D, -this.mc.viewEntity.prevRenderZ);
class_573 frustrum = new FrustrumIsom();
Expand Down Expand Up @@ -189,7 +197,7 @@ public void doRender() {
}

graphics.dispose();
this.progressUpdate.method_1796("Saving as " + outputFile.toString());
this.progressUpdate.method_1796("Saving screenshot as " + outputFile.getName().toString());
this.progressUpdate.progressStagePercentage(100);
FileOutputStream stream = new FileOutputStream(outputFile);
ImageIO.write(image, "png", stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import org.lwjgl.input.Keyboard;

public class KeyBindingListener {
public static KeyBinding takeHugeScreenshot;
public static KeyBinding takeCustomResolutionScreenshot;
public static KeyBinding takeIsometricScreenshot;

@EventListener
public void registerKeyBindings(KeyBindingRegisterEvent event) {
event.keyBindings.add(takeHugeScreenshot = new KeyBinding("Huge Photo", Keyboard.KEY_F6));
event.keyBindings.add(takeCustomResolutionScreenshot = new KeyBinding("Custom Photo", Keyboard.KEY_F6));
event.keyBindings.add(takeIsometricScreenshot = new KeyBinding("Isometric Photo", Keyboard.KEY_F7));
}
}
88 changes: 44 additions & 44 deletions src/main/java/com/github/telvarost/betterscreenshots/ModHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public String format(String string) {
}
}

private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
private int hugeLineHeight;
private DataOutputStream hugeStream;
private byte[] hugeData;
private int[] hugeImageData;
private File hugeFile;
private BufferedImage hugeImage;
public static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
private int customResolutionPhotoLineHeight;
private DataOutputStream customResolutionPhotoStream;
private byte[] customResolutionPhotoData;
private int[] customResolutionPhotoImageData;
private File customResolutionPhotoFile;
private BufferedImage customResolutionPhotoImage;
private boolean useTarga;

public ModHelper(File file1, int i2, int i3, int i4, boolean z5) throws IOException {
Expand All @@ -52,25 +52,25 @@ public ModHelper(File file1, int i2, int i3, int i4, boolean z5) throws IOExcept

public ModHelper(File file1, String string10, int i2, int i3, int i4, boolean z5) throws IOException {
if(!z5) {
this.hugeImage = new BufferedImage(i2, i3, 1);
this.customResolutionPhotoImage = new BufferedImage(i2, i3, 1);
}

this.useTarga = z5;
Config.ConfigFields.hugeWidth = i2;
Config.ConfigFields.hugeHeight = i3;
this.hugeLineHeight = i4;
Config.ConfigFields.customResolutionPhotoWidth = i2;
Config.ConfigFields.customResolutionPhotoHeight = i3;
this.customResolutionPhotoLineHeight = i4;
File file6 = new File(file1, "screenshots");
file6.mkdir();
String string7 = "huge_" + dateFormat.format(new Date());
String string7 = "custom_" + dateFormat.format(new Date());
if(string10 == null) {
for(int i8 = 1; (this.hugeFile = new File(file6, string7 + (i8 == 1 ? "" : "_" + i8) + (z5 ? ".tga" : ".png"))).exists(); ++i8) {
for(int i8 = 1; (this.customResolutionPhotoFile = new File(file6, string7 + (i8 == 1 ? "" : "_" + i8) + (z5 ? ".tga" : ".png"))).exists(); ++i8) {
}
} else {
this.hugeFile = new File(file6, string10);
this.customResolutionPhotoFile = new File(file6, string10);
}

this.hugeData = new byte[i2 * i4 * 3];
this.hugeStream = new DataOutputStream(new FileOutputStream(this.hugeFile));
this.customResolutionPhotoData = new byte[i2 * i4 * 3];
this.customResolutionPhotoStream = new DataOutputStream(new FileOutputStream(this.customResolutionPhotoFile));
if(z5) {
byte[] b9 = new byte[18];
b9[2] = 2;
Expand All @@ -79,62 +79,62 @@ public ModHelper(File file1, String string10, int i2, int i3, int i4, boolean z5
b9[14] = (byte)(i3 % 256);
b9[15] = (byte)(i3 / 256);
b9[16] = 24;
this.hugeStream.write(b9);
this.customResolutionPhotoStream.write(b9);
} else {
this.hugeImageData = new int[i2 * i3];
this.customResolutionPhotoImageData = new int[i2 * i3];
}

}

public void saveHugePart(ByteBuffer byteBuffer1, int i2, int i3, int i4, int i5) throws IOException {
public void saveCustomResolutionPhotoPart(ByteBuffer byteBuffer1, int i2, int i3, int i4, int i5) throws IOException {
int i6 = i4;
int i7 = i5;
if(i4 > Config.ConfigFields.hugeWidth - i2) {
i6 = Config.ConfigFields.hugeWidth - i2;
if(i4 > Config.ConfigFields.customResolutionPhotoWidth - i2) {
i6 = Config.ConfigFields.customResolutionPhotoWidth - i2;
}

if(i5 > Config.ConfigFields.hugeHeight - i3) {
i7 = Config.ConfigFields.hugeHeight - i3;
if(i5 > Config.ConfigFields.customResolutionPhotoHeight - i3) {
i7 = Config.ConfigFields.customResolutionPhotoHeight - i3;
}

this.hugeLineHeight = i7;
this.customResolutionPhotoLineHeight = i7;
for(int i8 = 0; i8 < i7; ++i8) {
byteBuffer1.position((i5 - i7) * i4 * 3 + i8 * i4 * 3);
int i9 = (i2 + i8 * Config.ConfigFields.hugeWidth) * 3;
byteBuffer1.get(this.hugeData, i9, i6 * 3);
int i9 = (i2 + i8 * Config.ConfigFields.customResolutionPhotoWidth) * 3;
byteBuffer1.get(this.customResolutionPhotoData, i9, i6 * 3);
}

}

public void saveHugeLine(int i1) throws IOException {
public void saveCustomResolutionPhotoLine(int i1) throws IOException {
if(this.useTarga) {
this.hugeStream.write(this.hugeData, 0, Config.ConfigFields.hugeWidth * 3 * this.hugeLineHeight);
this.customResolutionPhotoStream.write(this.customResolutionPhotoData, 0, Config.ConfigFields.customResolutionPhotoWidth * 3 * this.customResolutionPhotoLineHeight);
} else {
for(int i2 = 0; i2 < Config.ConfigFields.hugeWidth; ++i2) {
for(int i3 = 0; i3 < this.hugeLineHeight; ++i3) {
int i4 = i2 + (this.hugeLineHeight - i3 - 1) * Config.ConfigFields.hugeWidth;
int i5 = this.hugeData[i4 * 3 + 0] & 255;
int i6 = this.hugeData[i4 * 3 + 1] & 255;
int i7 = this.hugeData[i4 * 3 + 2] & 255;
for(int i2 = 0; i2 < Config.ConfigFields.customResolutionPhotoWidth; ++i2) {
for(int i3 = 0; i3 < this.customResolutionPhotoLineHeight; ++i3) {
int i4 = i2 + (this.customResolutionPhotoLineHeight - i3 - 1) * Config.ConfigFields.customResolutionPhotoWidth;
int i5 = this.customResolutionPhotoData[i4 * 3 + 0] & 255;
int i6 = this.customResolutionPhotoData[i4 * 3 + 1] & 255;
int i7 = this.customResolutionPhotoData[i4 * 3 + 2] & 255;
int i8 = 0xFF000000 | i5 << 16 | i6 << 8 | i7;
this.hugeImageData[i2 + (i1 + i3) * Config.ConfigFields.hugeWidth] = i8;
this.customResolutionPhotoImageData[i2 + (i1 + i3) * Config.ConfigFields.customResolutionPhotoWidth] = i8;
}
}
}

}

public String saveHugeScreenshot() throws IOException {
public String saveCustomResolutionPhotoScreenshot() throws IOException {
if(!this.useTarga) {
this.hugeImage.setRGB(0, 0, Config.ConfigFields.hugeWidth, Config.ConfigFields.hugeHeight, this.hugeImageData, 0, Config.ConfigFields.hugeWidth);
ImageIO.write(this.hugeImage, "png", this.hugeStream);
this.customResolutionPhotoImage.setRGB(0, 0, Config.ConfigFields.customResolutionPhotoWidth, Config.ConfigFields.customResolutionPhotoHeight, this.customResolutionPhotoImageData, 0, Config.ConfigFields.customResolutionPhotoWidth);
ImageIO.write(this.customResolutionPhotoImage, "png", this.customResolutionPhotoStream);
}

this.hugeStream.close();
return "Saved screenshot as " + this.hugeFile.getName();
this.customResolutionPhotoStream.close();
return "Saved screenshot as " + this.customResolutionPhotoFile.getName();
}

public static String mainSaveHugeScreenshot(Minecraft instance, File file1, int i2, int i3, int i4, int i5, boolean z6) {
public static String mainSaveCustomResolutionPhotoScreenshot(Minecraft instance, File file1, int i2, int i3, int i4, int i5, boolean z6) {
try {
ByteBuffer byteBuffer6 = BufferUtils.createByteBuffer(i2 * i3 * 3);
ModHelper screenShotHelper7 = new ModHelper(file1, i4, i5, i3, z6);
Expand Down Expand Up @@ -169,13 +169,13 @@ public static String mainSaveHugeScreenshot(Minecraft instance, File file1, int
GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glReadPixels(0, 0, i2, i3, z6 ? GL12.GL_BGR : GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, byteBuffer6);
screenShotHelper7.saveHugePart(byteBuffer6, i15, i14, i2, i3);
screenShotHelper7.saveCustomResolutionPhotoPart(byteBuffer6, i15, i14, i2, i3);
}

screenShotHelper7.saveHugeLine(i14);
screenShotHelper7.saveCustomResolutionPhotoLine(i14);
}

return screenShotHelper7.saveHugeScreenshot();
return screenShotHelper7.saveCustomResolutionPhotoScreenshot();
} catch (OutOfMemoryError e) {
return "Failed to save: " + "Out of memory";
} catch (Exception exception24) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void betterScreenShots_openScreen(InGame instance) {
)
)
private void checkTakingScreenshot(Minecraft instance, boolean value) {
if (!Keyboard.isKeyDown(KeyBindingListener.takeHugeScreenshot.key)) {
if (!Keyboard.isKeyDown(KeyBindingListener.takeCustomResolutionScreenshot.key)) {
this.isTakingScreenshot = false;
}
}
Expand Down Expand Up @@ -195,11 +195,11 @@ public void betterScreenshots_tickOverlayRunTick(InGame instance) {
public int betterScreenshots_tickGetEventKey() {
int eventKey = Keyboard.getEventKey();

/** - Check for HUGE_PHOTO keybinding pressed */
if(Keyboard.isKeyDown(KeyBindingListener.takeHugeScreenshot.key)) {
/** - Check for CUSTOM_RESOLUTION_PHOTO keybinding pressed */
if(Keyboard.isKeyDown(KeyBindingListener.takeCustomResolutionScreenshot.key)) {
if(this.level != null) {
this.isTakingScreenshot = true;
this.overlay.addChatMessage(ModHelper.mainSaveHugeScreenshot((Minecraft) (Object)this, this.gameDirectory, this.actualWidth, this.actualHeight, Config.ConfigFields.hugeWidth, Config.ConfigFields.hugeHeight, (System.getProperty("os.name").toLowerCase().contains("mac")) ? Keyboard.isKeyDown(Keyboard.KEY_LMETA) || Keyboard.isKeyDown(Keyboard.KEY_RMETA) : Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)));
this.overlay.addChatMessage(ModHelper.mainSaveCustomResolutionPhotoScreenshot((Minecraft) (Object)this, this.gameDirectory, this.actualWidth, this.actualHeight, Config.ConfigFields.customResolutionPhotoWidth, Config.ConfigFields.customResolutionPhotoHeight, (System.getProperty("os.name").toLowerCase().contains("mac")) ? Keyboard.isKeyDown(Keyboard.KEY_LMETA) || Keyboard.isKeyDown(Keyboard.KEY_RMETA) : Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)));
}
} else {
if (!Keyboard.isKeyDown(60)) {
Expand All @@ -209,7 +209,7 @@ public int betterScreenshots_tickGetEventKey() {

/** - Check for ISOMETRIC_PHOTO keybinding pressed */
if(this.level != null && eventKey == KeyBindingListener.takeIsometricScreenshot.key) {
IsometricScreenshotRenderer isoRenderer = (new IsometricScreenshotRenderer((Minecraft) (Object)this));
IsometricScreenshotRenderer isoRenderer = (new IsometricScreenshotRenderer((Minecraft) (Object)this, this.gameDirectory));
isoRenderer.doRender();
}

Expand Down

0 comments on commit 0b35e8f

Please sign in to comment.