aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-16 12:28:37 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-16 12:28:37 +0200
commit024ba52fb69b6cd44b4e31542867f802de656f15 (patch)
tree86368585de8bf41f3f0f2bd9c8c66dae113190a4 /src/main/java/at/hannibal2
parent26c9ff13df1a7e0a6508d11c98ff994cdc1d8902 (diff)
downloadskyhanni-024ba52fb69b6cd44b4e31542867f802de656f15.tar.gz
skyhanni-024ba52fb69b6cd44b4e31542867f802de656f15.tar.bz2
skyhanni-024ba52fb69b6cd44b4e31542867f802de656f15.zip
Fixed that Paste Into Sign feature only pastes into the first line.
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/AccessorGuiEditSign.java15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt26
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt11
4 files changed, 53 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt
index bdddcc3a7..98a16eb4c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt
@@ -6,21 +6,23 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
import kotlinx.coroutines.launch
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import org.lwjgl.input.Keyboard
class PasteIntoSigns {
+ private var lastClicked = false
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!LorenzUtils.onHypixel) return
if (!SkyHanniMod.feature.misc.pasteIntoSigns) return
- if (LorenzUtils.isControlKeyDown() && OSUtils.isKeyHeld(Keyboard.KEY_V)) {
+ val currentlyClicked = LorenzUtils.isPastingKeysDown()
+ if (!lastClicked && currentlyClicked) {
SkyHanniMod.coroutineScope.launch {
OSUtils.readFromClipboard()?.let {
- LorenzUtils.setTextIntoSign(it.take(15))
+ LorenzUtils.addTextIntoSign(it.take(15))
}
}
}
+ lastClicked = currentlyClicked
}
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/AccessorGuiEditSign.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/AccessorGuiEditSign.java
new file mode 100644
index 000000000..8132a710c
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/AccessorGuiEditSign.java
@@ -0,0 +1,15 @@
+package at.hannibal2.skyhanni.mixins.transformers;
+
+import net.minecraft.client.gui.inventory.GuiEditSign;
+import net.minecraft.tileentity.TileEntitySign;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(GuiEditSign.class)
+public interface AccessorGuiEditSign {
+ @Accessor("tileSign")
+ TileEntitySign getTileSign();
+
+ @Accessor("editLine")
+ int getEditLine();
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 9a4348d39..9085b96e8 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -5,14 +5,15 @@ import at.hannibal2.skyhanni.data.HypixelData
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.MayorElection
import at.hannibal2.skyhanni.features.dungeon.DungeonData
+import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiEditSign
import at.hannibal2.skyhanni.test.TestBingo
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
+import at.hannibal2.skyhanni.utils.StringUtils.capAtMinecraftLength
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.StringUtils.toDashlessUUID
import at.hannibal2.skyhanni.utils.renderables.Renderable
import io.github.moulberry.moulconfig.observer.Observer
import io.github.moulberry.moulconfig.observer.Property
-import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign
import io.github.moulberry.notenoughupdates.util.SkyBlockTime
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiEditSign
@@ -21,6 +22,7 @@ import net.minecraft.entity.SharedMonsterAttributes
import net.minecraft.event.ClickEvent
import net.minecraft.event.HoverEvent
import net.minecraft.util.ChatComponentText
+import org.apache.commons.lang3.SystemUtils
import org.lwjgl.input.Keyboard
import java.awt.Color
import java.lang.reflect.Field
@@ -230,11 +232,19 @@ object LorenzUtils {
fun setTextIntoSign(text: String) {
val gui = Minecraft.getMinecraft().currentScreen
- if (gui !is GuiEditSign) return
- gui as AccessorGuiEditSign
+ if (gui !is AccessorGuiEditSign) return
gui.tileSign.signText[0] = ChatComponentText(text)
}
+ fun addTextIntoSign(addedText: String) {
+ val gui = Minecraft.getMinecraft().currentScreen
+ if (gui !is AccessorGuiEditSign) return
+ val lines = gui.tileSign.signText
+ val index = gui.editLine
+ val text = lines[index].unformattedText + addedText
+ lines[index] = ChatComponentText(text.capAtMinecraftLength(90))
+ }
+
fun clickableChat(message: String, command: String) {
val text = ChatComponentText(message)
val fullCommand = "/" + command.removePrefix("/")
@@ -284,6 +294,9 @@ object LorenzUtils {
fun isControlKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LCONTROL) || OSUtils.isKeyHeld(Keyboard.KEY_RCONTROL)
+ // A mac-only key, represents Windows key on windows (but different key code)
+ fun isCommandKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LMETA) || OSUtils.isKeyHeld(Keyboard.KEY_LMETA)
+
// MoulConfig is in Java, I don't want to downgrade this logic
fun <T> onChange(vararg properties: Property<out T>, observer: Observer<T>) {
for (property in properties) {
@@ -512,4 +525,9 @@ object LorenzUtils {
}
}, duration.inWholeMilliseconds)
}
-} \ No newline at end of file
+
+ fun isPastingKeysDown(): Boolean {
+ val modifierHeld = if (SystemUtils.IS_OS_MAC) isCommandKeyDown() else isControlKeyDown()
+ return modifierHeld && OSUtils.isKeyHeld(Keyboard.KEY_V)
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index d42b597e6..8150bce4f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -152,4 +152,15 @@ object StringUtils {
builder.append(end)
return builder.toString()
}
+
+ fun String.capAtMinecraftLength(limit: Int) =
+ capAtLength(limit) { Minecraft.getMinecraft().fontRendererObj.getCharWidth(it) }
+
+ private fun String.capAtLength(limit: Int, lengthJudger: (Char) -> Int): String {
+ var i = 0
+ return takeWhile {
+ i += lengthJudger(it)
+ i < limit
+ }
+ }
} \ No newline at end of file