diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-16 12:28:37 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-16 12:28:37 +0200 |
commit | 024ba52fb69b6cd44b4e31542867f802de656f15 (patch) | |
tree | 86368585de8bf41f3f0f2bd9c8c66dae113190a4 /src/main/java/at/hannibal2/skyhanni/utils | |
parent | 26c9ff13df1a7e0a6508d11c98ff994cdc1d8902 (diff) | |
download | skyhanni-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/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 26 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt | 11 |
2 files changed, 33 insertions, 4 deletions
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 |