aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/ClipboardUtils.kt28
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/MC.kt1
2 files changed, 29 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/ClipboardUtils.kt b/src/main/kotlin/moe/nea/firmament/util/ClipboardUtils.kt
new file mode 100644
index 0000000..d761a5a
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/util/ClipboardUtils.kt
@@ -0,0 +1,28 @@
+/*
+ * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.util
+
+import moe.nea.firmament.Firmament
+
+object ClipboardUtils {
+ fun setTextContent(string: String) {
+ try {
+ MC.keyboard.clipboard = string.ifEmpty { " " }
+ } catch (e: Exception) {
+ Firmament.logger.error("Could not write clipboard", e)
+ }
+ }
+
+ fun getTextContents(): String {
+ try {
+ return MC.keyboard.clipboard ?: ""
+ } catch (e: Exception) {
+ Firmament.logger.error("Could not read clipboard", e)
+ return ""
+ }
+ }
+}
diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt
index 602d85a..78f2eec 100644
--- a/src/main/kotlin/moe/nea/firmament/util/MC.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/MC.kt
@@ -16,6 +16,7 @@ object MC {
player?.networkHandler?.sendCommand(command)
}
+ inline val keyboard get() = MinecraftClient.getInstance().keyboard
inline val textureManager get() = MinecraftClient.getInstance().textureManager
inline val inGameHud get() = MinecraftClient.getInstance().inGameHud
inline val font get() = MinecraftClient.getInstance().textRenderer