From 4dd188d721d927ab75349e77c938a0213bc3539e Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Thu, 5 Feb 2026 21:04:28 +0100 Subject: [PATCH] Try porting to 1.21.11 Signed-off-by: Username404-59 --- .../fr/username404/snowygui/ClickGui.kt | 25 ++++++++++--------- .../snowygui/gui/elements/ClickBox.kt | 2 +- .../snowygui/gui/feature/ButtonImpl.kt | 7 +++--- .../username404/snowygui/gui/feature/Macro.kt | 3 ++- .../username404/snowygui/misc/AddKeyMaps.kt | 5 +++- .../src/main/resources/snowygui.accessWidener | 4 ++- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt index da9780e..e4e3f55 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt @@ -4,6 +4,7 @@ import fr.username404.snowygui.gui.ColoredElement import fr.username404.snowygui.gui.Element import fr.username404.snowygui.gui.SnowyScreen import fr.username404.snowygui.gui.elements.ClickBox +import net.minecraft.client.input.MouseButtonEvent import org.lwjgl.glfw.GLFW object ClickGui: SnowyScreen() { @@ -19,26 +20,26 @@ object ClickGui: SnowyScreen() { private inline fun currentBoxContext(args: ClickBox.() -> Unit): Unit? = draggingBox?.run { boxContext { if (name.string == draggingBox) args() } } private var offsetX: Double = 0.0; private var offsetY: Double = 0.0; - override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { - if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) { - clickBoxes.find { it.isWithinBounds(d, e) }?.let { draggingBox = it.name.string } + override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean { + if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) { + clickBoxes.find { it.isWithinBounds(event.x, event.y) }?.let { draggingBox = it.name.string } currentBoxContext { - offsetX = d - (x + width) - offsetY = e - (y + height) + offsetX = event.x - (x + width) + offsetY = event.y - (y + height) } } - buttonsContext { this.mouseClicked(d, e, i) }; return super.mouseClicked(d, e, i); + buttonsContext { this.mouseClicked(event, isDoubleClick) }; return super.mouseClicked(event, isDoubleClick); } - override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { draggingBox = null; buttonsContext { this.mouseReleased(d, e, i) }; return false } + override fun mouseReleased(event: MouseButtonEvent): Boolean { draggingBox = null; buttonsContext { this.mouseReleased(event) }; return false } override fun mouseScrolled(d: Double, e: Double, f: Double, scrollY: Double): Boolean { boxContext { scroll(d, e, scrollY) }; return false } - override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean { - if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) { + override fun mouseDragged(event: MouseButtonEvent, mouseX: Double, mouseY: Double): Boolean { + if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) { currentBoxContext { - x = (d + offsetX).coerceIn(0.0..this@ClickGui.width - width.toDouble()) - y = (e + offsetY).coerceIn(0.0..this@ClickGui.height - height.toDouble()) + x = (event.x + offsetX).coerceIn(0.0..this@ClickGui.width - width.toDouble()) + y = (event.y + offsetY).coerceIn(0.0..this@ClickGui.height - height.toDouble()) } } - return super.mouseDragged(d, e, i, f, g) + return super.mouseDragged(event, mouseX, mouseY) } } \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index f91fa74..420cf6f 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -96,7 +96,7 @@ class ClickBox( addVertex(x, y + height, 0.0F).colorEnd() } - renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_LINE_STRIP) { + renderBufferWithPipeline(renderPipeline = RenderPipelines.LINES_TRANSLUCENT) { colorShader() addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue) addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt index e4d4e84..e0554b4 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt @@ -10,6 +10,7 @@ import fr.username404.snowygui.utils.RenderingUtil.colorShader import fr.username404.snowygui.utils.RenderingUtil.endDraw import fr.username404.snowygui.utils.RenderingUtil.prepareDraw import net.minecraft.client.gui.GuiGraphics +import net.minecraft.client.input.MouseButtonEvent import kotlin.reflect.full.findAnnotation sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { @@ -68,8 +69,8 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { } private fun lightUp() { opacity += ButtonInfo.lightningFactor } private fun lightDown() { opacity -= ButtonInfo.lightningFactor } - final override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { - wasWithinBounds = isWithinBounds(d, e).also { + final override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean { + wasWithinBounds = isWithinBounds(event.x, event.y).also { if (it) { if (info.kind == Type.TOGGLE) { toggled = !toggled @@ -79,7 +80,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { return false } - final override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { + final override fun mouseReleased(event: MouseButtonEvent): Boolean { if (wasWithinBounds && (info.kind == Type.CLICK)) { execAction() lightDown() diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt index 2be5877..57a53ea 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt @@ -3,6 +3,7 @@ package fr.username404.snowygui.gui.feature import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type import kotlinx.serialization.Serializable import net.minecraft.client.Minecraft +import net.minecraft.server.permissions.Permissions /** * @property command The command to execute @@ -17,7 +18,7 @@ data class Macro( override fun execAction(): Unit = with(Minecraft.getInstance().player!!) { connection.run { command.let { - if (it.startsWith("say") && !hasPermissions(2)) { + if (it.startsWith("say") && !this@with.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER)) { sendChat(it.drop(4)) } else sendCommand(it) } diff --git a/common/src/main/kotlin/fr/username404/snowygui/misc/AddKeyMaps.kt b/common/src/main/kotlin/fr/username404/snowygui/misc/AddKeyMaps.kt index 850de13..84edf2e 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/misc/AddKeyMaps.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/misc/AddKeyMaps.kt @@ -12,6 +12,7 @@ import org.lwjgl.glfw.GLFW.GLFW_KEY_Y private typealias privateLambda = (() -> Unit)? object AddKeyMaps { private const val prefix = "snowy" + var category: KeyMapping.Category? = null; private set @JvmOverloads internal fun mkMap( translationSuffix: String, @@ -19,7 +20,9 @@ object AddKeyMaps { lambda: privateLambda = null ): Pair = KeyMapping( "key.$prefix.$translationSuffix", InputConstants.Type.KEYSYM, - key, "category.$prefix.$category" + key, this.category ?: run { + this.category = KeyMapping.Category.register("category.$prefix.$category"); this.category + }!! ) to lambda val list: MutableMap = with(Minecraft.getInstance()) { mutableMapOf( diff --git a/common/src/main/resources/snowygui.accessWidener b/common/src/main/resources/snowygui.accessWidener index 6180282..d6779b8 100644 --- a/common/src/main/resources/snowygui.accessWidener +++ b/common/src/main/resources/snowygui.accessWidener @@ -4,4 +4,6 @@ accessible field net/minecraft/client/OptionInstance value Ljava/lang/Object; mutable field net/minecraft/client/OptionInstance value Ljava/lang/Object; accessible field com/mojang/blaze3d/opengl/GlCommandEncoder inRenderPass Z -mutable field com/mojang/blaze3d/opengl/GlCommandEncoder inRenderPass Z \ No newline at end of file +mutable field com/mojang/blaze3d/opengl/GlCommandEncoder inRenderPass Z + +accessible method net/minecraft/client/KeyMapping$Category register (Ljava/lang/String;)Lnet/minecraft/client/KeyMapping$Category; \ No newline at end of file