Created
March 3, 2024 08:16
-
-
Save Densamisten/c004dff140818c86730ad6f747c1b7a0 to your computer and use it in GitHub Desktop.
Copies the clipboard contents onto the clipboard in MinecraftForge! Usage: /clipboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package net.kaupenjoe.mccourse.command; | |
| import com.mojang.blaze3d.platform.ClipboardManager; | |
| import com.mojang.brigadier.CommandDispatcher; | |
| import com.mojang.brigadier.arguments.StringArgumentType; | |
| import net.minecraft.client.Minecraft; | |
| import net.minecraft.commands.CommandSourceStack; | |
| import net.minecraft.commands.Commands; | |
| import net.minecraft.network.chat.Component; | |
| public class ClipboardCommand { | |
| public ClipboardCommand(CommandDispatcher<CommandSourceStack> dispatcher) { | |
| dispatcher.register(Commands.literal("clipboard") | |
| .then(Commands.argument("text", StringArgumentType.string()) | |
| .executes(context -> copyToClipboard(context.getSource(), StringArgumentType.getString(context, "text"))) | |
| ) | |
| ); | |
| } | |
| private static int copyToClipboard(CommandSourceStack source, String text) { | |
| // Create an instance of ClipboardManager | |
| ClipboardManager clipboard = new ClipboardManager(); | |
| // Get the GLFW window handle (assuming it's available) | |
| long windowHandle = Minecraft.getInstance().getWindow().getWindow(); | |
| // Set the clipboard content | |
| clipboard.setClipboard(windowHandle, text); | |
| source.sendSuccess(() -> Component.literal("Text copied to clipboard: " + text), true); | |
| return 1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment