diff options
Diffstat (limited to 'src')
5 files changed, 55 insertions, 8 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 diff --git a/src/main/resources/mixins.skyhanni.json b/src/main/resources/mixins.skyhanni.json index 3982dd3c8..69b41eb4b 100644 --- a/src/main/resources/mixins.skyhanni.json +++ b/src/main/resources/mixins.skyhanni.json @@ -12,8 +12,8 @@ "MixinItemStack", "MixinNetHandlerPlayClient", "MixinNetworkManager", - "MixinRenderGlobal", "MixinRendererLivingEntity", + "MixinRenderGlobal", "MixinRenderItem", "MixinRenderManager", "gui.AccessorGuiContainer", @@ -21,6 +21,7 @@ "renderer.MixinRendererLivingEntity" ], "client": [ + "AccessorGuiEditSign", "AccessorKeyBinding", "CustomRenderGlobal", "MixinEntityRenderer", |