Try porting to 1.21.11
Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
fb83b10894
commit
4dd188d721
@ -4,6 +4,7 @@ import fr.username404.snowygui.gui.ColoredElement
|
|||||||
import fr.username404.snowygui.gui.Element
|
import fr.username404.snowygui.gui.Element
|
||||||
import fr.username404.snowygui.gui.SnowyScreen
|
import fr.username404.snowygui.gui.SnowyScreen
|
||||||
import fr.username404.snowygui.gui.elements.ClickBox
|
import fr.username404.snowygui.gui.elements.ClickBox
|
||||||
|
import net.minecraft.client.input.MouseButtonEvent
|
||||||
import org.lwjgl.glfw.GLFW
|
import org.lwjgl.glfw.GLFW
|
||||||
|
|
||||||
object ClickGui: SnowyScreen() {
|
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 inline fun currentBoxContext(args: ClickBox.() -> Unit): Unit? = draggingBox?.run { boxContext { if (name.string == draggingBox) args() } }
|
||||||
private var offsetX: Double = 0.0;
|
private var offsetX: Double = 0.0;
|
||||||
private var offsetY: Double = 0.0;
|
private var offsetY: Double = 0.0;
|
||||||
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
|
override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean {
|
||||||
if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
clickBoxes.find { it.isWithinBounds(d, e) }?.let { draggingBox = it.name.string }
|
clickBoxes.find { it.isWithinBounds(event.x, event.y) }?.let { draggingBox = it.name.string }
|
||||||
currentBoxContext {
|
currentBoxContext {
|
||||||
offsetX = d - (x + width)
|
offsetX = event.x - (x + width)
|
||||||
offsetY = e - (y + height)
|
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 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 {
|
override fun mouseDragged(event: MouseButtonEvent, mouseX: Double, mouseY: Double): Boolean {
|
||||||
if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
currentBoxContext {
|
currentBoxContext {
|
||||||
x = (d + offsetX).coerceIn(0.0..this@ClickGui.width - width.toDouble())
|
x = (event.x + offsetX).coerceIn(0.0..this@ClickGui.width - width.toDouble())
|
||||||
y = (e + offsetY).coerceIn(0.0..this@ClickGui.height - height.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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ class ClickBox(
|
|||||||
addVertex(x, y + height, 0.0F).colorEnd()
|
addVertex(x, y + height, 0.0F).colorEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_LINE_STRIP) {
|
renderBufferWithPipeline(renderPipeline = RenderPipelines.LINES_TRANSLUCENT) {
|
||||||
colorShader()
|
colorShader()
|
||||||
addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
|
addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
|
||||||
addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
|
addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import fr.username404.snowygui.utils.RenderingUtil.colorShader
|
|||||||
import fr.username404.snowygui.utils.RenderingUtil.endDraw
|
import fr.username404.snowygui.utils.RenderingUtil.endDraw
|
||||||
import fr.username404.snowygui.utils.RenderingUtil.prepareDraw
|
import fr.username404.snowygui.utils.RenderingUtil.prepareDraw
|
||||||
import net.minecraft.client.gui.GuiGraphics
|
import net.minecraft.client.gui.GuiGraphics
|
||||||
|
import net.minecraft.client.input.MouseButtonEvent
|
||||||
import kotlin.reflect.full.findAnnotation
|
import kotlin.reflect.full.findAnnotation
|
||||||
|
|
||||||
sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
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 lightUp() { opacity += ButtonInfo.lightningFactor }
|
||||||
private fun lightDown() { opacity -= ButtonInfo.lightningFactor }
|
private fun lightDown() { opacity -= ButtonInfo.lightningFactor }
|
||||||
final override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
|
final override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean {
|
||||||
wasWithinBounds = isWithinBounds(d, e).also {
|
wasWithinBounds = isWithinBounds(event.x, event.y).also {
|
||||||
if (it) {
|
if (it) {
|
||||||
if (info.kind == Type.TOGGLE) {
|
if (info.kind == Type.TOGGLE) {
|
||||||
toggled = !toggled
|
toggled = !toggled
|
||||||
@ -79,7 +80,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
|||||||
return false
|
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)) {
|
if (wasWithinBounds && (info.kind == Type.CLICK)) {
|
||||||
execAction()
|
execAction()
|
||||||
lightDown()
|
lightDown()
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package fr.username404.snowygui.gui.feature
|
|||||||
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
|
import net.minecraft.server.permissions.Permissions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property command The command to execute
|
* @property command The command to execute
|
||||||
@ -17,7 +18,7 @@ data class Macro(
|
|||||||
override fun execAction(): Unit = with(Minecraft.getInstance().player!!) {
|
override fun execAction(): Unit = with(Minecraft.getInstance().player!!) {
|
||||||
connection.run {
|
connection.run {
|
||||||
command.let {
|
command.let {
|
||||||
if (it.startsWith("say") && !hasPermissions(2)) {
|
if (it.startsWith("say") && !this@with.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER)) {
|
||||||
sendChat(it.drop(4))
|
sendChat(it.drop(4))
|
||||||
} else sendCommand(it)
|
} else sendCommand(it)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import org.lwjgl.glfw.GLFW.GLFW_KEY_Y
|
|||||||
private typealias privateLambda = (() -> Unit)?
|
private typealias privateLambda = (() -> Unit)?
|
||||||
object AddKeyMaps {
|
object AddKeyMaps {
|
||||||
private const val prefix = "snowy"
|
private const val prefix = "snowy"
|
||||||
|
var category: KeyMapping.Category? = null; private set
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
internal fun mkMap(
|
internal fun mkMap(
|
||||||
translationSuffix: String,
|
translationSuffix: String,
|
||||||
@ -19,7 +20,9 @@ object AddKeyMaps {
|
|||||||
lambda: privateLambda = null
|
lambda: privateLambda = null
|
||||||
): Pair<KeyMapping, privateLambda> = KeyMapping(
|
): Pair<KeyMapping, privateLambda> = KeyMapping(
|
||||||
"key.$prefix.$translationSuffix", InputConstants.Type.KEYSYM,
|
"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
|
) to lambda
|
||||||
val list: MutableMap<KeyMapping, privateLambda> = with(Minecraft.getInstance()) {
|
val list: MutableMap<KeyMapping, privateLambda> = with(Minecraft.getInstance()) {
|
||||||
mutableMapOf(
|
mutableMapOf(
|
||||||
|
|||||||
@ -5,3 +5,5 @@ mutable field net/minecraft/client/OptionInstance value Ljava/lang/Object;
|
|||||||
|
|
||||||
accessible field com/mojang/blaze3d/opengl/GlCommandEncoder inRenderPass Z
|
accessible field com/mojang/blaze3d/opengl/GlCommandEncoder inRenderPass Z
|
||||||
mutable field com/mojang/blaze3d/opengl/GlCommandEncoder inRenderPass Z
|
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;
|
||||||
Loading…
Reference in New Issue
Block a user