├── .github └── workflows │ ├── push.yml │ └── release.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── common ├── build.gradle └── src │ └── main │ ├── java │ └── link │ │ └── infra │ │ └── screenshotclipboard │ │ └── common │ │ ├── MacOSCompat.java │ │ ├── ScreenshotToClipboard.java │ │ └── mixin │ │ ├── AWTHackMixin.java │ │ └── NativeImagePointerAccessor.java │ └── resources │ ├── icon.png │ └── screenshotclipboard-common.mixins.json ├── fabric ├── build.gradle └── src │ └── main │ ├── java │ └── link │ │ └── infra │ │ └── screenshotclipboard │ │ ├── FabrishotCompat.java │ │ ├── ScreenshotToClipboardFabric.java │ │ └── mixin │ │ ├── ScreenshotMixinAWT.java │ │ └── ScreenshotMixinMacOS.java │ └── resources │ ├── fabric.mod.json │ └── screenshotclipboard-fabric.mixins.json ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── neoforge ├── build.gradle ├── gradle.properties └── src │ └── main │ ├── java │ └── link │ │ └── infra │ │ └── screenshotclipboard │ │ ├── ScreenshotToClipboardForgeClient.java │ │ └── mixin │ │ └── ScreenshotMixinMacOS.java │ └── resources │ ├── META-INF │ └── neoforge.mods.toml │ └── screenshotclipboard-neoforge.mixins.json └── settings.gradle /.github/workflows/push.yml: -------------------------------------------------------------------------------- 1 | name: Java CI with Gradle 2 | 3 | on: ["push", "pull_request"] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v4 11 | with: 12 | fetch-depth: 0 13 | - name: Set up JDK 21 14 | uses: actions/setup-java@v4 15 | with: 16 | java-version: '21' 17 | distribution: 'temurin' 18 | cache: gradle 19 | - name: Grant execute permission for gradlew 20 | run: chmod +x gradlew 21 | - name: Build with Gradle 22 | run: ./gradlew build 23 | - name: Cleanup Gradle Cache 24 | # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. 25 | # Restoring these files from a GitHub Actions cache might cause problems for future builds. 26 | run: | 27 | rm -f ~/.gradle/caches/modules-2/modules-2.lock 28 | rm -f ~/.gradle/caches/modules-2/gc.properties -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Java Gradle Release 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v4 13 | with: 14 | fetch-depth: 0 15 | - name: Set up JDK 21 16 | uses: actions/setup-java@v4 17 | with: 18 | java-version: '21' 19 | distribution: 'temurin' 20 | cache: gradle 21 | - name: Grant execute permission for gradlew 22 | run: chmod +x gradlew 23 | - name: Publish with Gradle 24 | run: ./gradlew publish 25 | env: 26 | GITHUB_TOKEN: ${{ Secrets.GITHUB_TOKEN }} 27 | CURSEFORGE_TOKEN: ${{ Secrets.CURSEFORGE_TOKEN }} 28 | MODRINTH_TOKEN: ${{ Secrets.MODRINTH_TOKEN }} 29 | - name: Cleanup Gradle Cache 30 | # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. 31 | # Restoring these files from a GitHub Actions cache might cause problems for future builds. 32 | run: | 33 | rm -f ~/.gradle/caches/modules-2/modules-2.lock 34 | rm -f ~/.gradle/caches/modules-2/gc.properties -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.ipr 3 | run/ 4 | *.iws 5 | out/ 6 | *.iml 7 | .gradle/ 8 | output/ 9 | bin/ 10 | libs/ 11 | 12 | .classpath 13 | .project 14 | .idea/ 15 | classes/ 16 | .metadata 17 | .vscode 18 | .settings 19 | *.launch 20 | 21 | logs/ 22 | .architectury-transformer/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 comp500 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Screenshot to Clipboard [![Screenshot to Clipboard CurseForge Badge](http://cf.way2muchnoise.eu/full_screenshot-to-clipboard-fabric_screenshots%20copied.svg)](https://www.curseforge.com/minecraft/mc-mods/screenshot-to-clipboard-fabric) 2 | 3 | Any time you take a screenshot in the game, the image data is copied to the clipboard. You can then paste this anywhere (e.g. Discord) to upload the image and share it with others. 4 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'dev.architectury.loom' version '1.6-SNAPSHOT' apply false 3 | id 'architectury-plugin' version '3.4-SNAPSHOT' 4 | id 'com.github.johnrengelman.shadow' version '8.1.1' apply false 5 | 6 | id "com.github.breadmoirai.github-release" version "2.5.2" 7 | id "org.ajoberstar.grgit" version "5.0.0-rc.3" 8 | id "maven-publish" 9 | } 10 | 11 | 12 | String getGitVersion(Project project) { 13 | if (grgit != null) { 14 | if (grgit.describe(tags: true) == "${project.mod_version}") { 15 | return "${project.mod_version}" 16 | } else { 17 | var dirty = grgit.status().clean ? "" : "dirty" 18 | return "${project.mod_version}-dev.${grgit.head().abbreviatedId}+${dirty}" 19 | } 20 | } else { 21 | return "${project.mod_version}-dev.unknown" 22 | } 23 | } 24 | 25 | String getChangelog(String githubUrl) { 26 | // Get changes since the last tag 27 | return grgit.log(includes: ["HEAD"], excludes: [ 28 | // Get the last tag, removing the number of commits since the tag and the current HEAD~ hash 29 | grgit.describe(commit: "HEAD~", tags: true).replaceAll("-\\d+-[a-z0-9]+\$", "") 30 | ]).collect { 31 | "- ${it.shortMessage} (${it.author.name})" 32 | }.join("\n") + (githubUrl == null ? "" : "\n\nSee the full changes on Github: ${githubUrl}commits/${grgit.describe(tags: true)}") 33 | } 34 | 35 | ext { 36 | changelog = getChangelog(rootProject.github_url) 37 | changelogGithub = getChangelog(null) 38 | } 39 | 40 | architectury { 41 | minecraft = project.minecraft_version 42 | } 43 | 44 | allprojects { 45 | group = rootProject.maven_group 46 | version = getGitVersion(rootProject) 47 | } 48 | 49 | subprojects { 50 | apply plugin: 'dev.architectury.loom' 51 | apply plugin: 'architectury-plugin' 52 | apply plugin: 'maven-publish' 53 | 54 | base { 55 | // Set up a suffixed format for the mod jar names, e.g. `example-fabric`. 56 | archivesName = "$rootProject.archives_name-$project.name" 57 | } 58 | 59 | repositories { 60 | // Add repositories to retrieve artifacts from in here. 61 | // You should only use this when depending on other mods because 62 | // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. 63 | // See https://docs.gradle.org/current/userguide/declaring_repositories.html 64 | // for more information about repositories. 65 | } 66 | 67 | dependencies { 68 | minecraft "net.minecraft:minecraft:$rootProject.minecraft_version" 69 | mappings loom.layered { 70 | it.mappings("net.fabricmc:yarn:$rootProject.yarn_mappings:v2") 71 | it.mappings("dev.architectury:yarn-mappings-patch-neoforge:$rootProject.yarn_mappings_patch_neoforge_version") 72 | } 73 | 74 | // This library loads in OSX, but not in Windows - I'm including it here so I can compile on Windows 75 | implementation "ca.weblite:java-objc-bridge:1.0.0" 76 | } 77 | 78 | java { 79 | // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task 80 | // if it is present. 81 | // If you remove this line, sources will not be generated. 82 | withSourcesJar() 83 | 84 | sourceCompatibility = JavaVersion.VERSION_21 85 | targetCompatibility = JavaVersion.VERSION_21 86 | } 87 | 88 | tasks.withType(JavaCompile).configureEach { 89 | it.options.release = 21 90 | } 91 | 92 | // Configure Maven publishing. 93 | publishing { 94 | publications { 95 | mavenJava(MavenPublication) { 96 | artifactId = base.archivesName.get() 97 | from components.java 98 | } 99 | } 100 | 101 | // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. 102 | repositories { 103 | // Add repositories to publish to here. 104 | // Notice: This block does NOT have the same function as the block in the top level. 105 | // The repositories here will be used for publishing your artifact, not for 106 | // retrieving dependencies. 107 | } 108 | } 109 | } 110 | 111 | configurations { 112 | githubReleaseJars { 113 | canBeConsumed = false 114 | canBeResolved = true 115 | } 116 | } 117 | 118 | dependencies { 119 | githubReleaseJars(project(path: ":fabric", configuration: "remapJarOutput")) 120 | githubReleaseJars(project(path: ":neoforge", configuration: "remapJarOutput")) 121 | } 122 | 123 | if (System.getenv("GITHUB_TOKEN")) { 124 | githubRelease { 125 | owner = rootProject.github_repo_user 126 | repo = rootProject.github_repo_name 127 | tagName = rootProject.mod_version 128 | releaseName = "Release ${rootProject.mod_version}" 129 | targetCommitish = "1.20-arch" // TODO: get from git? 130 | draft = false 131 | body = rootProject.ext.changelogGithub 132 | token System.getenv("GITHUB_TOKEN") 133 | releaseAssets.from(rootProject.configurations.githubReleaseJars) 134 | overwrite = true 135 | } 136 | 137 | publish.dependsOn(tasks.githubRelease) 138 | } -------------------------------------------------------------------------------- /common/build.gradle: -------------------------------------------------------------------------------- 1 | architectury { 2 | common rootProject.enabled_platforms.split(',') 3 | } 4 | 5 | dependencies { 6 | // We depend on Fabric Loader here to use the Fabric @Environment annotations, 7 | // which get remapped to the correct annotations on each platform. 8 | // Do NOT use other classes from Fabric Loader. 9 | modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version" 10 | } 11 | -------------------------------------------------------------------------------- /common/src/main/java/link/infra/screenshotclipboard/common/MacOSCompat.java: -------------------------------------------------------------------------------- 1 | package link.infra.screenshotclipboard.common; 2 | 3 | import ca.weblite.objc.Client; 4 | import ca.weblite.objc.Proxy; 5 | import net.minecraft.client.MinecraftClient; 6 | import org.apache.logging.log4j.LogManager; 7 | import org.apache.logging.log4j.Logger; 8 | 9 | public class MacOSCompat { 10 | private static final Logger LOGGER = LogManager.getFormatterLogger("ScreenshotToClipboard-MacOSCompat"); 11 | 12 | // macOS requires some ugly hacks to get it to work, because it doesn't allow GLFW and AWT to load at the same time 13 | // See: https://github.com/MinecraftForge/MinecraftForge/pull/5591#issuecomment-470805491 14 | // Thanks to @juliand665 for writing and testing most of this code, I don't have a Mac! 15 | 16 | public static void doCopyMacOS(String path) { 17 | if (!MinecraftClient.IS_SYSTEM_MAC) { 18 | return; 19 | } 20 | 21 | Client client = Client.getInstance(); 22 | Proxy url = client.sendProxy("NSURL", "fileURLWithPath:", path); 23 | 24 | Proxy image = client.sendProxy("NSImage", "alloc"); 25 | image.send("initWithContentsOfURL:", url); 26 | 27 | Proxy array = client.sendProxy("NSArray", "array"); 28 | array = array.sendProxy("arrayByAddingObject:", image); 29 | 30 | Proxy pasteboard = client.sendProxy("NSPasteboard", "generalPasteboard"); 31 | pasteboard.send("clearContents"); 32 | boolean wasSuccessful = pasteboard.sendBoolean("writeObjects:", array); 33 | if (!wasSuccessful) { 34 | LOGGER.error("Failed to write image to pasteboard!"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/src/main/java/link/infra/screenshotclipboard/common/ScreenshotToClipboard.java: -------------------------------------------------------------------------------- 1 | package link.infra.screenshotclipboard.common; 2 | 3 | import link.infra.screenshotclipboard.common.mixin.NativeImagePointerAccessor; 4 | import net.minecraft.client.MinecraftClient; 5 | import net.minecraft.client.texture.NativeImage; 6 | import org.apache.logging.log4j.LogManager; 7 | import org.apache.logging.log4j.Logger; 8 | import org.lwjgl.system.MemoryUtil; 9 | 10 | import java.awt.*; 11 | import java.awt.color.ColorSpace; 12 | import java.awt.datatransfer.Clipboard; 13 | import java.awt.datatransfer.DataFlavor; 14 | import java.awt.datatransfer.Transferable; 15 | import java.awt.datatransfer.UnsupportedFlavorException; 16 | import java.awt.image.*; 17 | import java.nio.ByteBuffer; 18 | 19 | public class ScreenshotToClipboard { 20 | public static final String MOD_ID = "screenshotclipboard"; 21 | private static final Logger LOGGER = LogManager.getFormatterLogger("ScreenshotToClipboard"); 22 | 23 | public static void init() { 24 | if (!MinecraftClient.IS_SYSTEM_MAC) { 25 | // Test that the mixin was run properly 26 | // Ensure AWT is loaded by forcing loadLibraries() to be called, will cause a HeadlessException if someone else already loaded AWT 27 | try { 28 | Toolkit.getDefaultToolkit().getSystemClipboard(); 29 | } catch (HeadlessException e) { 30 | LOGGER.warn("java.awt.headless property was not set properly!"); 31 | } 32 | } 33 | } 34 | 35 | public static void handleScreenshotAWT(NativeImage img) { 36 | if (MinecraftClient.IS_SYSTEM_MAC) { 37 | return; 38 | } 39 | 40 | // Only allow RGBA 41 | if (img.getFormat() != NativeImage.Format.RGBA) { 42 | LOGGER.warn("Failed to capture screenshot: wrong format"); 43 | return; 44 | } 45 | 46 | // IntellIJ doesn't like this 47 | //noinspection ConstantConditions 48 | long imagePointer = ((NativeImagePointerAccessor) (Object) img).getPointer(); 49 | ByteBuffer buf = MemoryUtil.memByteBufferSafe(imagePointer, img.getWidth() * img.getHeight() * 4); 50 | if (buf == null) { 51 | throw new RuntimeException("Invalid image"); 52 | } 53 | 54 | handleScreenshotAWT(buf, img.getWidth(), img.getHeight(), 4); 55 | } 56 | 57 | public static void handleScreenshotAWT(ByteBuffer byteBuffer, int width, int height, int components) { 58 | if (MinecraftClient.IS_SYSTEM_MAC) { 59 | return; 60 | } 61 | 62 | byte[] array; 63 | if (byteBuffer.hasArray()) { 64 | array = byteBuffer.array(); 65 | } else { 66 | // can't use .array() as the buffer is not array-backed 67 | array = new byte[height * width * components]; 68 | byteBuffer.get(array); 69 | } 70 | 71 | doCopy(array, width, height, components); 72 | } 73 | 74 | private static void doCopy(byte[] imageData, int width, int height, int components) { 75 | new Thread(() -> { 76 | DataBufferByte buf = new DataBufferByte(imageData, imageData.length); 77 | ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); 78 | // Ignore the alpha channel, due to JDK-8204187 79 | int[] nBits = {8, 8, 8}; 80 | int[] bOffs = {0, 1, 2}; // is this efficient, no transformation is being done? 81 | ColorModel cm = new ComponentColorModel(cs, nBits, false, false, 82 | Transparency.TRANSLUCENT, 83 | DataBuffer.TYPE_BYTE); 84 | BufferedImage bufImg = new BufferedImage(cm, Raster.createInterleavedRaster(buf, 85 | width, height, 86 | width * components, components, 87 | bOffs, null), false, null); 88 | 89 | Transferable trans = getTransferableImage(bufImg); 90 | Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); 91 | c.setContents(trans, null); 92 | }, "Screenshot to Clipboard Copy").start(); 93 | } 94 | 95 | private static Transferable getTransferableImage(final BufferedImage bufferedImage) { 96 | return new Transferable() { 97 | @Override 98 | public DataFlavor[] getTransferDataFlavors() { 99 | return new DataFlavor[]{DataFlavor.imageFlavor}; 100 | } 101 | 102 | @Override 103 | public boolean isDataFlavorSupported(DataFlavor flavor) { 104 | return DataFlavor.imageFlavor.equals(flavor); 105 | } 106 | 107 | @Override 108 | public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { 109 | if (DataFlavor.imageFlavor.equals(flavor)) { 110 | return bufferedImage; 111 | } 112 | throw new UnsupportedFlavorException(flavor); 113 | } 114 | }; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /common/src/main/java/link/infra/screenshotclipboard/common/mixin/AWTHackMixin.java: -------------------------------------------------------------------------------- 1 | package link.infra.screenshotclipboard.common.mixin; 2 | 3 | import net.minecraft.client.main.Main; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.injection.At; 6 | import org.spongepowered.asm.mixin.injection.Inject; 7 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 8 | 9 | import java.util.Locale; 10 | 11 | @Mixin(Main.class) 12 | public class AWTHackMixin { 13 | // Inject as early as possible (but after Main statics execute), and disable java.awt.headless on non-macOS systems 14 | @Inject(method = "main", at = @At("HEAD"), remap = false) 15 | private static void awtHack(CallbackInfo ci) { 16 | // A bit dangerous, but shouldn't technically cause any issues on most platforms - headless mode just disables the awt API 17 | // Minecraft usually has this enabled because it's using GLFW rather than AWT/Swing 18 | // Also causes problems on macOS, see: https://github.com/MinecraftForge/MinecraftForge/pull/5591#issuecomment-470805491 19 | 20 | // This uses a Mixin because this must be done as early as possible - before other mods load that use AWT 21 | // see https://github.com/BuiltBrokenModding/SBM-SheepMetal/issues/2 22 | if (!System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("mac")) { 23 | System.out.println("[Screenshot to Clipboard] Setting java.awt.headless to false"); 24 | System.setProperty("java.awt.headless", "false"); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /common/src/main/java/link/infra/screenshotclipboard/common/mixin/NativeImagePointerAccessor.java: -------------------------------------------------------------------------------- 1 | package link.infra.screenshotclipboard.common.mixin; 2 | 3 | import net.minecraft.client.texture.NativeImage; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | @Mixin(NativeImage.class) 8 | public interface NativeImagePointerAccessor { 9 | @Accessor("pointer") 10 | long getPointer(); 11 | } 12 | -------------------------------------------------------------------------------- /common/src/main/resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp500/ScreenshotToClipboard/8ea71318ef1ab4c225e63d359d22f538fa059b51/common/src/main/resources/icon.png -------------------------------------------------------------------------------- /common/src/main/resources/screenshotclipboard-common.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "link.infra.screenshotclipboard.common.mixin", 4 | "minVersion": "0.8", 5 | "compatibilityLevel": "JAVA_21", 6 | "mixins": [ 7 | ], 8 | "client": [ 9 | "AWTHackMixin", 10 | "NativeImagePointerAccessor" 11 | ], 12 | "injectors": { 13 | "defaultRequire": 1 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /fabric/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.github.johnrengelman.shadow' 3 | 4 | id "com.modrinth.minotaur" version "2.+" 5 | id "com.matthewprenger.cursegradle" version "1.4.0" 6 | } 7 | 8 | architectury { 9 | platformSetupLoomIde() 10 | fabric() 11 | } 12 | 13 | configurations { 14 | common { 15 | canBeResolved = true 16 | canBeConsumed = false 17 | } 18 | compileClasspath.extendsFrom common 19 | runtimeClasspath.extendsFrom common 20 | developmentFabric.extendsFrom common 21 | 22 | // Files in this configuration will be bundled into your mod using the Shadow plugin. 23 | // Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files. 24 | shadowBundle { 25 | canBeResolved = true 26 | canBeConsumed = false 27 | } 28 | } 29 | 30 | repositories { 31 | maven { 32 | url = "https://api.modrinth.com/maven" 33 | } 34 | } 35 | 36 | dependencies { 37 | modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version" 38 | 39 | modCompileOnly "maven.modrinth:fabrishot:${rootProject.fabrishot_version}" 40 | modCompileOnly fabricApi.module("fabric-api-base", rootProject.fabric_api_version) 41 | 42 | common(project(path: ':common', configuration: 'namedElements')) { transitive false } 43 | shadowBundle project(path: ':common', configuration: 'transformProductionFabric') 44 | } 45 | 46 | processResources { 47 | inputs.property 'version', project.version 48 | 49 | filesMatching('fabric.mod.json') { 50 | expand version: project.version 51 | } 52 | } 53 | 54 | shadowJar { 55 | configurations = [project.configurations.shadowBundle] 56 | archiveClassifier = 'dev-shadow' 57 | } 58 | 59 | remapJar { 60 | input.set shadowJar.archiveFile 61 | } 62 | 63 | // TODO: infer from fabric.mod.json?! 64 | def supportedVersions = ["1.20.6", "1.21"] 65 | def versionSupportName = "(Fabric/Quilt 1.20.6+)" 66 | 67 | if (System.getenv("MODRINTH_TOKEN")) { 68 | modrinth { 69 | token = System.getenv("MODRINTH_TOKEN") 70 | projectId = rootProject.modrinth_id 71 | versionNumber = rootProject.mod_version + "+fabric" 72 | uploadFile = remapJar 73 | gameVersions = supportedVersions 74 | loaders = ["fabric", "quilt"] 75 | detectLoaders = false 76 | versionName = rootProject.mod_version + " " + versionSupportName 77 | changelog = rootProject.ext.changelog 78 | } 79 | 80 | publish.dependsOn(tasks.named("modrinth")) 81 | } 82 | 83 | if (System.getenv("CURSEFORGE_TOKEN")) { 84 | curseforge { 85 | apiKey = System.getenv("CURSEFORGE_TOKEN") 86 | project { 87 | id = rootProject.curseforge_id_fabric 88 | releaseType = "release" 89 | 90 | mainArtifact(remapJar) { 91 | displayName = rootProject.mod_version + " " + versionSupportName 92 | } 93 | for (version in supportedVersions) { 94 | addGameVersion(version) 95 | } 96 | addGameVersion("Fabric") 97 | changelog = rootProject.ext.changelog 98 | changelogType = "markdown" 99 | } 100 | } 101 | 102 | publish.dependsOn(tasks.named("curseforge")) 103 | } 104 | 105 | configurations { 106 | remapJarOutput { 107 | canBeConsumed = true 108 | canBeResolved = false 109 | } 110 | } 111 | 112 | artifacts { 113 | remapJarOutput(remapJar) // For consumption by github release 114 | } -------------------------------------------------------------------------------- /fabric/src/main/java/link/infra/screenshotclipboard/FabrishotCompat.java: -------------------------------------------------------------------------------- 1 | package link.infra.screenshotclipboard; 2 | 3 | import link.infra.screenshotclipboard.common.MacOSCompat; 4 | import link.infra.screenshotclipboard.common.ScreenshotToClipboard; 5 | import me.ramidzkh.fabrishot.event.FramebufferCaptureCallback; 6 | import me.ramidzkh.fabrishot.event.ScreenshotSaveCallback; 7 | 8 | public class FabrishotCompat { 9 | public static void init() { 10 | FramebufferCaptureCallback.EVENT.register((dim, buffer) -> 11 | ScreenshotToClipboard.handleScreenshotAWT(buffer, dim.width(), dim.height(), 3)); 12 | 13 | ScreenshotSaveCallback.EVENT.register(file -> 14 | MacOSCompat.doCopyMacOS(file.toString())); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /fabric/src/main/java/link/infra/screenshotclipboard/ScreenshotToClipboardFabric.java: -------------------------------------------------------------------------------- 1 | package link.infra.screenshotclipboard; 2 | 3 | import link.infra.screenshotclipboard.common.ScreenshotToClipboard; 4 | import net.fabricmc.api.ClientModInitializer; 5 | import net.fabricmc.loader.api.FabricLoader; 6 | 7 | public class ScreenshotToClipboardFabric implements ClientModInitializer { 8 | @Override 9 | public void onInitializeClient() { 10 | ScreenshotToClipboard.init(); 11 | 12 | if (FabricLoader.getInstance().isModLoaded("fabrishot")) { 13 | FabrishotCompat.init(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /fabric/src/main/java/link/infra/screenshotclipboard/mixin/ScreenshotMixinAWT.java: -------------------------------------------------------------------------------- 1 | package link.infra.screenshotclipboard.mixin; 2 | 3 | import link.infra.screenshotclipboard.common.ScreenshotToClipboard; 4 | import net.minecraft.client.texture.NativeImage; 5 | import net.minecraft.client.util.ScreenshotRecorder; 6 | import net.minecraft.text.Text; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 11 | 12 | import java.io.File; 13 | import java.util.function.Consumer; 14 | 15 | @Mixin(ScreenshotRecorder.class) 16 | public class ScreenshotMixinAWT { 17 | // Lambda in method_1662 is called method_1661 18 | // Inject before it starts saving the file (HEAD is the safest place to do this) 19 | @Inject(at = @At(value = "HEAD"), method = "method_1661") 20 | private static void screenshotCaptured(NativeImage nativeImage_1, File file_1, Consumer consumer_1, CallbackInfo ci) { 21 | ScreenshotToClipboard.handleScreenshotAWT(nativeImage_1); 22 | } 23 | } -------------------------------------------------------------------------------- /fabric/src/main/java/link/infra/screenshotclipboard/mixin/ScreenshotMixinMacOS.java: -------------------------------------------------------------------------------- 1 | package link.infra.screenshotclipboard.mixin; 2 | 3 | import link.infra.screenshotclipboard.common.MacOSCompat; 4 | import net.minecraft.client.texture.NativeImage; 5 | import net.minecraft.client.util.ScreenshotRecorder; 6 | import net.minecraft.text.Text; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 11 | 12 | import java.io.File; 13 | import java.util.function.Consumer; 14 | 15 | @Mixin(ScreenshotRecorder.class) 16 | public class ScreenshotMixinMacOS { 17 | // Inject after saving the image 18 | @Inject(at = @At("TAIL"), method = "method_1661") 19 | private static void screenshotCapturedMac(NativeImage nativeImage, File file, Consumer consumer, CallbackInfo ci) { 20 | MacOSCompat.doCopyMacOS(file.getAbsolutePath()); 21 | } 22 | } -------------------------------------------------------------------------------- /fabric/src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "screenshotclipboard", 4 | "version": "${version}", 5 | 6 | "name": "Screenshot to Clipboard", 7 | "description": "Any time you take a screenshot in the game, the image data is copied to the clipboard. You can then paste this anywhere (e.g. Discord) to upload the image and share it with others.", 8 | "authors": [ 9 | "comp500" 10 | ], 11 | "contact": { 12 | "homepage": "https://www.curseforge.com/minecraft/mc-mods/screenshot-to-clipboard-fabric", 13 | "sources": "https://github.com/comp500/ScreenshotToClipboard/", 14 | "issues": "https://github.com/comp500/ScreenshotToClipboard/issues" 15 | }, 16 | 17 | "license": "MIT", 18 | "icon": "icon.png", 19 | 20 | "environment": "client", 21 | "entrypoints": { 22 | "client": [ 23 | "link.infra.screenshotclipboard.ScreenshotToClipboardFabric" 24 | ] 25 | }, 26 | "mixins": [ 27 | "screenshotclipboard-fabric.mixins.json", 28 | "screenshotclipboard-common.mixins.json" 29 | ], 30 | 31 | "depends": { 32 | "fabricloader": ">=0.16.0", 33 | "minecraft": ">=1.20.6" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /fabric/src/main/resources/screenshotclipboard-fabric.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "link.infra.screenshotclipboard.mixin", 4 | "minVersion": "0.8", 5 | "compatibilityLevel": "JAVA_21", 6 | "mixins": [ 7 | ], 8 | "client": [ 9 | "ScreenshotMixinAWT", 10 | "ScreenshotMixinMacOS" 11 | ], 12 | "injectors": { 13 | "defaultRequire": 1 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Done to increase the memory available to Gradle. 2 | org.gradle.jvmargs=-Xmx2G 3 | org.gradle.parallel=true 4 | 5 | # Mod properties 6 | mod_version = 1.0.10 7 | maven_group = link.infra.screenshotclipboard 8 | archives_name = screenshot-to-clipboard 9 | enabled_platforms = fabric,neoforge 10 | 11 | # Minecraft properties 12 | minecraft_version = 1.20.6 13 | yarn_mappings = 1.20.6+build.1 14 | 15 | # Dependencies 16 | fabric_loader_version = 0.16.0 17 | fabric_api_version = 0.100.4+1.20.6 18 | fabrishot_version=1.13.1 19 | neoforge_version = 20.6.119 20 | yarn_mappings_patch_neoforge_version = 1.20.6+build.4 21 | 22 | modrinth_id=1KiJRrTg 23 | curseforge_id_forge=326950 24 | curseforge_id_fabric=327154 25 | github_url=https://github.com/comp500/ScreenshotToClipboard/ 26 | github_repo_user=comp500 27 | github_repo_name=ScreenshotToClipboard -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp500/ScreenshotToClipboard/8ea71318ef1ab4c225e63d359d22f538fa059b51/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /neoforge/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.github.johnrengelman.shadow' 3 | 4 | id "com.modrinth.minotaur" version "2.+" 5 | id "com.matthewprenger.cursegradle" version "1.4.0" 6 | } 7 | 8 | architectury { 9 | platformSetupLoomIde() 10 | neoForge() 11 | } 12 | 13 | configurations { 14 | common { 15 | canBeResolved = true 16 | canBeConsumed = false 17 | } 18 | compileClasspath.extendsFrom common 19 | runtimeClasspath.extendsFrom common 20 | developmentNeoForge.extendsFrom common 21 | 22 | // Files in this configuration will be bundled into your mod using the Shadow plugin. 23 | // Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files. 24 | shadowBundle { 25 | canBeResolved = true 26 | canBeConsumed = false 27 | } 28 | } 29 | 30 | repositories { 31 | maven { 32 | name = 'NeoForged' 33 | url = 'https://maven.neoforged.net/releases' 34 | } 35 | } 36 | 37 | dependencies { 38 | neoForge "net.neoforged:neoforge:$rootProject.neoforge_version" 39 | 40 | common(project(path: ':common', configuration: 'namedElements')) { transitive false } 41 | shadowBundle project(path: ':common', configuration: 'transformProductionNeoForge') 42 | } 43 | 44 | processResources { 45 | inputs.property 'version', project.version 46 | 47 | filesMatching('META-INF/neoforge.mods.toml') { 48 | expand version: project.version 49 | } 50 | } 51 | 52 | shadowJar { 53 | configurations = [project.configurations.shadowBundle] 54 | archiveClassifier = 'dev-shadow' 55 | } 56 | 57 | remapJar { 58 | input.set shadowJar.archiveFile 59 | } 60 | 61 | // TODO: infer from neoforge.mods.toml?! 62 | def supportedVersions = ["1.20.6", "1.21"] 63 | def versionSupportName = "(NeoForge 1.20.6+)" 64 | 65 | if (System.getenv("MODRINTH_TOKEN")) { 66 | modrinth { 67 | token = System.getenv("MODRINTH_TOKEN") 68 | projectId = rootProject.modrinth_id 69 | versionNumber = rootProject.mod_version + "+neoforge" 70 | uploadFile = remapJar 71 | gameVersions = supportedVersions 72 | loaders = ["neoforge"] 73 | detectLoaders = false 74 | versionName = rootProject.mod_version + " " + versionSupportName 75 | changelog = rootProject.ext.changelog 76 | } 77 | 78 | publish.dependsOn(tasks.named("modrinth")) 79 | } 80 | 81 | if (System.getenv("CURSEFORGE_TOKEN")) { 82 | curseforge { 83 | apiKey = System.getenv("CURSEFORGE_TOKEN") 84 | project { 85 | id = rootProject.curseforge_id_forge 86 | releaseType = "release" 87 | 88 | mainArtifact(remapJar) { 89 | displayName = rootProject.mod_version + " " + versionSupportName 90 | } 91 | for (version in supportedVersions) { 92 | addGameVersion(version) 93 | } 94 | addGameVersion("NeoForge") 95 | changelog = rootProject.ext.changelog 96 | changelogType = "markdown" 97 | } 98 | } 99 | 100 | publish.dependsOn(tasks.named("curseforge")) 101 | } 102 | 103 | configurations { 104 | remapJarOutput { 105 | canBeConsumed = true 106 | canBeResolved = false 107 | } 108 | } 109 | 110 | artifacts { 111 | remapJarOutput(remapJar) // For consumption by github release 112 | } 113 | -------------------------------------------------------------------------------- /neoforge/gradle.properties: -------------------------------------------------------------------------------- 1 | loom.platform = neoforge 2 | -------------------------------------------------------------------------------- /neoforge/src/main/java/link/infra/screenshotclipboard/ScreenshotToClipboardForgeClient.java: -------------------------------------------------------------------------------- 1 | package link.infra.screenshotclipboard; 2 | 3 | import link.infra.screenshotclipboard.common.ScreenshotToClipboard; 4 | import net.neoforged.api.distmarker.Dist; 5 | import net.neoforged.bus.api.IEventBus; 6 | import net.neoforged.fml.common.Mod; 7 | import net.neoforged.neoforge.client.event.ScreenshotEvent; 8 | import net.neoforged.neoforge.common.NeoForge; 9 | 10 | @Mod(value = ScreenshotToClipboard.MOD_ID, dist = Dist.CLIENT) 11 | public class ScreenshotToClipboardForgeClient { 12 | public ScreenshotToClipboardForgeClient(IEventBus modBus) { 13 | NeoForge.EVENT_BUS.addListener(ScreenshotToClipboardForgeClient::handleScreenshot); 14 | ScreenshotToClipboard.init(); 15 | } 16 | 17 | public static void handleScreenshot(ScreenshotEvent event) { 18 | ScreenshotToClipboard.handleScreenshotAWT(event.getImage()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /neoforge/src/main/java/link/infra/screenshotclipboard/mixin/ScreenshotMixinMacOS.java: -------------------------------------------------------------------------------- 1 | package link.infra.screenshotclipboard.mixin; 2 | 3 | import link.infra.screenshotclipboard.common.MacOSCompat; 4 | import net.minecraft.client.texture.NativeImage; 5 | import net.minecraft.client.util.ScreenshotRecorder; 6 | import net.minecraft.text.Text; 7 | import net.neoforged.neoforge.client.event.ScreenshotEvent; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 12 | 13 | import java.io.File; 14 | import java.util.function.Consumer; 15 | 16 | @Mixin(ScreenshotRecorder.class) 17 | public class ScreenshotMixinMacOS { 18 | // Inject after saving the image 19 | @Inject(at = @At("TAIL"), method = { 20 | "method_1661(Lnet/minecraft/client/texture/NativeImage;Ljava/io/File;Lnet/neoforged/neoforge/client/event/ScreenshotEvent;Ljava/util/function/Consumer;)V", 21 | // Remapping lambda methods in Forge/Architectury is pain :( 22 | "lambda$_grab$2(Lnet/minecraft/client/texture/NativeImage;Ljava/io/File;Lnet/neoforged/neoforge/client/event/ScreenshotEvent;Ljava/util/function/Consumer;)V" 23 | }) 24 | private static void screenshotCapturedMac(NativeImage nativeImage, File file1, ScreenshotEvent event, Consumer consumer, CallbackInfo ci) { 25 | MacOSCompat.doCopyMacOS(event.getScreenshotFile().getAbsolutePath()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /neoforge/src/main/resources/META-INF/neoforge.mods.toml: -------------------------------------------------------------------------------- 1 | modLoader="javafml" 2 | loaderVersion="[2,)" 3 | 4 | issueTrackerURL="https://github.com/comp500/ScreenshotToClipboard/issues" 5 | license="MIT" 6 | 7 | [[mods]] 8 | modId="screenshotclipboard" 9 | version="${version}" 10 | displayName="Screenshot to Clipboard" 11 | displayURL="https://github.com/comp500/ScreenshotToClipboard" 12 | logoFile="icon.png" 13 | authors="comp500" 14 | description=''' 15 | Any time you take a screenshot in the game, the image data is copied to the clipboard. You can then paste this anywhere (e.g. Discord) to upload the image and share it with others. 16 | ''' 17 | 18 | [[dependencies.screenshotclipboard]] 19 | modId = "neoforge" 20 | type = "required" 21 | versionRange = "[20.6,)" 22 | ordering = "NONE" 23 | side = "BOTH" 24 | 25 | [[dependencies.screenshotclipboard]] 26 | modId = "minecraft" 27 | type = "required" 28 | versionRange = "[1.20.6,)" 29 | ordering = "NONE" 30 | side = "BOTH" 31 | 32 | [[mixins]] 33 | config = "screenshotclipboard-common.mixins.json" 34 | 35 | [[mixins]] 36 | config = "screenshotclipboard-neoforge.mixins.json" -------------------------------------------------------------------------------- /neoforge/src/main/resources/screenshotclipboard-neoforge.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "link.infra.screenshotclipboard.mixin", 4 | "minVersion": "0.8", 5 | "compatibilityLevel": "JAVA_21", 6 | "mixins": [ 7 | ], 8 | "client": [ 9 | "ScreenshotMixinMacOS" 10 | ], 11 | "injectors": { 12 | "defaultRequire": 1 13 | } 14 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven { url "https://maven.fabricmc.net/" } 4 | maven { url "https://maven.architectury.dev/" } 5 | maven { url "https://files.minecraftforge.net/maven/" } 6 | gradlePluginPortal() 7 | } 8 | } 9 | 10 | rootProject.name = 'screenshot-to-clipboard' 11 | 12 | include 'common' 13 | include 'fabric' 14 | include 'neoforge' 15 | --------------------------------------------------------------------------------