diff --git a/src/main/java/dev/deftu/screencapper/mixins/ScreenshotRecorderMixin.java b/src/main/java/dev/deftu/screencapper/mixins/ScreenshotRecorderMixin.java index ac644b8..9ded92e 100644 --- a/src/main/java/dev/deftu/screencapper/mixins/ScreenshotRecorderMixin.java +++ b/src/main/java/dev/deftu/screencapper/mixins/ScreenshotRecorderMixin.java @@ -15,18 +15,15 @@ @Mixin({ScreenshotRecorder.class}) public class ScreenshotRecorderMixin { + @Inject(method = "method_1661", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/texture/NativeImage;writeTo(Ljava/io/File;)V", shift = At.Shift.AFTER)) private static void onFileWrite(NativeImage nativeImage, File file, Consumer consumer, CallbackInfo ci) { - try { - byte[] bytes = nativeImage.getBytes(); - ScreenshotHandler.INSTANCE.handle(nativeImage, bytes, file); - } catch (Exception e) { - throw new RuntimeException("Couldn't read from screenshot.", e); - } + ScreenshotHandler.INSTANCE.capture(nativeImage, file); } @ModifyArg(method = "method_1661", at = @At(value = "INVOKE", target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V")) private static Object acceptText(Object original) { return ScreenshotHandler.INSTANCE.createText((Text) original); } + } diff --git a/src/main/kotlin/dev/deftu/screencapper/ScreenshotHandler.kt b/src/main/kotlin/dev/deftu/screencapper/ScreenshotHandler.kt index 34c5922..2b35ac3 100644 --- a/src/main/kotlin/dev/deftu/screencapper/ScreenshotHandler.kt +++ b/src/main/kotlin/dev/deftu/screencapper/ScreenshotHandler.kt @@ -28,6 +28,15 @@ import javax.imageio.ImageIO object ScreenshotHandler { private var screenshot: Screenshot? = null + fun capture(image: NativeImage, file: File) { + try { + val bytes = image.bytes + handle(image, bytes, file) + } catch (t: Throwable) { + t.printStackTrace() + } + } + fun upload(): URL = upload(screenshot!!) fun upload(screenshot: Screenshot): URL { var screenshot = screenshot @@ -39,15 +48,6 @@ object ScreenshotHandler { return screenshot.url!! } - fun handle(image: NativeImage, bytes: ByteArray, file: File) { - if (!ScreencapperConfig.toggle) return - var screenshot = Screenshot(image, bytes, file) - this.screenshot = screenshot - ScreenshotPreview.append(screenshot) - if (ScreencapperConfig.autoCopy) copy() - if (ScreencapperConfig.uploadToggle) UDesktop.setClipboardString(upload(screenshot).toString()) - } - fun createText(original: Text): Text { if (!ScreencapperConfig.toggle || screenshot == null) return original @@ -91,6 +91,15 @@ object ScreenshotHandler { } } + private fun handle(image: NativeImage, bytes: ByteArray, file: File) { + if (!ScreencapperConfig.toggle) return + var screenshot = Screenshot(image, bytes, file) + this.screenshot = screenshot + ScreenshotPreview.append(screenshot) + if (ScreencapperConfig.autoCopy) copy() + if (ScreencapperConfig.uploadToggle) UDesktop.setClipboardString(upload(screenshot).toString()) + } + internal fun delete() { if (screenshot?.file?.delete() == true) { Screencapper.sendMessage(TextHelper.createTranslatableText("${Screencapper.ID}.text.chat.delete.success")