Skip to content

Commit b706e79

Browse files
committed
Changed mouse events and fixed clickfriend
1 parent 888abde commit b706e79

File tree

5 files changed

+54
-40
lines changed

5 files changed

+54
-40
lines changed

common/src/main/kotlin/com/lambda/event/events/KeyboardEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ sealed class KeyboardEvent {
5656

5757
val hasShift = modifiers and GLFW_MOD_SHIFT != 0
5858
val hasControl = modifiers and GLFW_MOD_CONTROL != 0
59-
val hasClt = modifiers and GLFW_MOD_ALT != 0
59+
val hasAlt = modifiers and GLFW_MOD_ALT != 0
6060
val hasSuper = modifiers and GLFW_MOD_SUPER != 0
6161
val hasCapsLock = modifiers and GLFW_MOD_CAPS_LOCK != 0
6262
val hasNumLock = modifiers and GLFW_MOD_NUM_LOCK != 0

common/src/main/kotlin/com/lambda/event/events/MouseEvent.kt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ import com.lambda.event.callback.Cancellable
2121
import com.lambda.event.callback.ICancellable
2222
import com.lambda.util.Mouse
2323
import com.lambda.util.math.Vec2d
24+
import org.lwjgl.glfw.GLFW.GLFW_MOD_ALT
25+
import org.lwjgl.glfw.GLFW.GLFW_MOD_CAPS_LOCK
26+
import org.lwjgl.glfw.GLFW.GLFW_MOD_CONTROL
27+
import org.lwjgl.glfw.GLFW.GLFW_MOD_NUM_LOCK
28+
import org.lwjgl.glfw.GLFW.GLFW_MOD_SHIFT
29+
import org.lwjgl.glfw.GLFW.GLFW_MOD_SUPER
2430

2531
sealed class MouseEvent {
2632
/**
@@ -32,17 +38,32 @@ sealed class MouseEvent {
3238
* @property position The x and y position of the mouse on the screen
3339
*/
3440
data class Click(
35-
val button: Mouse.Button,
36-
val action: Mouse.Action,
41+
val button: Int,
42+
val action: Int,
3743
val modifiers: Int,
3844
val position: Vec2d,
3945
) : ICancellable by Cancellable() {
40-
constructor(button: Int, action: Int, modifiers: Int, position: Vec2d) : this(
41-
Mouse.Button.fromMouseCode(button),
42-
Mouse.Action.fromActionCode(action),
46+
constructor(button: Mouse.Button, action: Mouse.Action, modifiers: Int, position: Vec2d) : this(
47+
button.ordinal,
48+
action.ordinal,
4349
modifiers,
4450
position
4551
)
52+
53+
val isMainButton = button <= 2
54+
val isSideButton = button > 2
55+
val isLeftButton = button == 0
56+
val isRightButton = button == 1
57+
val isMiddleButton = button == 2
58+
59+
val hasShift = hasModifier(GLFW_MOD_SHIFT)
60+
val hasControl = hasModifier(GLFW_MOD_CONTROL)
61+
val hasAlt = hasModifier(GLFW_MOD_ALT)
62+
val hasSuper = hasModifier(GLFW_MOD_SUPER)
63+
val hasCapsLock = hasModifier(GLFW_MOD_CAPS_LOCK)
64+
val hasNumLock = hasModifier(GLFW_MOD_NUM_LOCK)
65+
66+
fun hasModifier(mod: Int) = modifiers and mod == mod
4667
}
4768

4869
/**

common/src/main/kotlin/com/lambda/friend/FriendManager.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ object FriendManager : Configurable(FriendConfig), Loadable {
5656
fun OtherClientPlayerEntity.befriend() = befriend(gameProfile)
5757
fun OtherClientPlayerEntity.unfriend() = unfriend(gameProfile)
5858

59-
override fun load(): String {
60-
// TODO: Because the settings are loaded after the property and the loadables, the friend list is empty at that point
61-
return "Loaded ${friends.size} friends"
62-
}
59+
override fun load() = "Loaded ${friends.size} friends"
6360

6461
fun befriendedText(name: String): Text = befriendedText(Text.of(name))
6562
fun befriendedText(name: Text) = buildText {

common/src/main/kotlin/com/lambda/module/modules/player/ClickFriend.kt

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import com.lambda.util.Mouse
3030
import com.lambda.util.world.raycast.RayCastUtils.entityResult
3131
import net.minecraft.client.network.OtherClientPlayerEntity
3232
import org.lwjgl.glfw.GLFW.GLFW_MOD_ALT
33+
import org.lwjgl.glfw.GLFW.GLFW_MOD_CAPS_LOCK
3334
import org.lwjgl.glfw.GLFW.GLFW_MOD_CONTROL
35+
import org.lwjgl.glfw.GLFW.GLFW_MOD_NUM_LOCK
3436
import org.lwjgl.glfw.GLFW.GLFW_MOD_SHIFT
3537
import org.lwjgl.glfw.GLFW.GLFW_MOD_SUPER
3638

@@ -46,24 +48,17 @@ object ClickFriend : Module(
4648

4749
init {
4850
listen<MouseEvent.Click> {
49-
if (it.button != friendButton ||
50-
it.action != friendAction ||
51-
mc.currentScreen != null
52-
) return@listen
51+
if (mc.currentScreen != null) return@listen
52+
if (it.button != friendButton.ordinal || it.action != friendAction.ordinal) return@listen
5353

5454
val target = mc.crosshairTarget?.entityResult?.entity as? OtherClientPlayerEntity
5555
?: return@listen
5656

57-
if (modUnfriend.flagsPresent(it.modifiers) || !comboUnfriend) {
58-
when {
59-
target.isFriend && target.unfriend() -> {
60-
this@ClickFriend.info(FriendManager.unfriendedText(target.name))
61-
}
57+
if (!it.hasModifier(modUnfriend.modifiers) && comboUnfriend && target.isFriend) return@listen
6258

63-
!target.isFriend && target.befriend() -> {
64-
this@ClickFriend.info(FriendManager.befriendedText(target.name))
65-
}
66-
}
59+
when {
60+
target.isFriend && target.unfriend() -> info(FriendManager.unfriendedText(target.name))
61+
!target.isFriend && target.befriend() -> info(FriendManager.befriendedText(target.name))
6762
}
6863
}
6964
}
@@ -72,8 +67,8 @@ object ClickFriend : Module(
7267
Shift(GLFW_MOD_SHIFT),
7368
Control(GLFW_MOD_CONTROL),
7469
Alt(GLFW_MOD_ALT),
75-
Super(GLFW_MOD_SUPER);
76-
77-
fun flagsPresent(flags: Int) = flags and modifiers == modifiers
70+
Super(GLFW_MOD_SUPER),
71+
Caps(GLFW_MOD_CAPS_LOCK),
72+
NumLock(GLFW_MOD_NUM_LOCK);
7873
}
7974
}

common/src/main/kotlin/com/lambda/util/Mouse.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.mojang.blaze3d.systems.RenderSystem
2222
import org.lwjgl.glfw.GLFW
2323
import org.lwjgl.glfw.GLFW.GLFW_ARROW_CURSOR
2424
import org.lwjgl.glfw.GLFW.GLFW_POINTING_HAND_CURSOR
25+
import org.lwjgl.glfw.GLFW.GLFW_RELEASE
2526
import org.lwjgl.glfw.GLFW.GLFW_RESIZE_EW_CURSOR
2627
import org.lwjgl.glfw.GLFW.GLFW_RESIZE_NS_CURSOR
2728
import org.lwjgl.glfw.GLFW.GLFW_RESIZE_NWSE_CURSOR
@@ -30,20 +31,20 @@ import org.lwjgl.glfw.GLFW.glfwSetCursor
3031
import kotlin.jvm.Throws
3132

3233
class Mouse {
33-
enum class Button(val key: Int) {
34-
Left(GLFW.GLFW_MOUSE_BUTTON_LEFT),
35-
Right(GLFW.GLFW_MOUSE_BUTTON_RIGHT),
36-
Middle(GLFW.GLFW_MOUSE_BUTTON_MIDDLE),
37-
Button4(GLFW.GLFW_MOUSE_BUTTON_4),
38-
Button5(GLFW.GLFW_MOUSE_BUTTON_5),
39-
Button6(GLFW.GLFW_MOUSE_BUTTON_6),
40-
Button7(GLFW.GLFW_MOUSE_BUTTON_7),
41-
Button8(GLFW.GLFW_MOUSE_BUTTON_8);
42-
43-
val isMainButton get() = key == GLFW.GLFW_MOUSE_BUTTON_LEFT || key == GLFW.GLFW_MOUSE_BUTTON_RIGHT
34+
enum class Button {
35+
Left,
36+
Right,
37+
Middle,
38+
Button4,
39+
Button5,
40+
Button6,
41+
Button7,
42+
Button8;
43+
44+
val isMainButton get() = ordinal == GLFW.GLFW_MOUSE_BUTTON_LEFT || ordinal == GLFW.GLFW_MOUSE_BUTTON_RIGHT
4445

4546
companion object {
46-
private val mouseCodeMap = entries.associateBy { it.key }
47+
private val mouseCodeMap = entries.associateBy { it.ordinal }
4748
private val nameMap = entries.associateBy { it.name.lowercase() }
4849

4950
@Throws(IllegalArgumentException::class)
@@ -57,8 +58,8 @@ class Mouse {
5758
}
5859

5960
enum class Action {
60-
Click,
61-
Release;
61+
Release,
62+
Click;
6263

6364
companion object {
6465
private val mouseActionMap = entries.associateBy { it.ordinal }

0 commit comments

Comments
 (0)