Skip to content

Commit a321f12

Browse files
committed
Merge remote-tracking branch 'origin/master' into feature/pathfinder
2 parents 1777e33 + b5bec2d commit a321f12

39 files changed

+674
-1860
lines changed

.coderabbit.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/BUG_REPORT.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Bug Report
22
description: File a bug report.
3-
title: "[Version] Bug: "
4-
assignees:
5-
- Edouard127
3+
title: "Bug: "
64
body:
75
- type: markdown
86
attributes:

.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Feature
22
description: Request or implement a feature.
3-
title: "[Version] Feat: "
4-
assignees:
5-
- Edouard127
3+
title: "Feat: "
64
body:
75
- type: markdown
86
attributes:

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
### This is a template, modify before submitting your PR
44

5-
Please ensure that your PR title follows this format:
6-
- `[Minecraft Version] <Mod loader> Feat, Fix, Ref, Docs, ..., : Description`
5+
Ensure that your title is concise and has all the necessary information
76

87
**Examples:**
9-
- `[1.20.4] Feat: Add new block types`
10-
- `[1.21.4] [All] Fix: Crash on startup`
11-
- `[1.21.3] [Forge] Fix: GUI does not render`
12-
- `[1.20.1] Ref: Optimize rendering engine`
8+
- `Feat: Add new block types`
9+
- `Fix: Crash on startup`
10+
- `Fix: GUI does not render`
11+
- `Ref: Optimize rendering engine`
12+
- `New pre-processor for pathfinding`
13+
- `Fix inconsistency with the structure`
1314

1415
### Issue Link
1516
If your PR addresses one or more issues, be sure to link them. Use appropriate keywords like `closes`, `fixes`, or `resolves` to automatically close the linked issues when the PR is merged.

common/src/main/kotlin/com/lambda/command/commands/FriendCommand.kt

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ import com.lambda.brigadier.required
3030
import com.lambda.command.LambdaCommand
3131
import com.lambda.config.configurations.FriendConfig
3232
import com.lambda.friend.FriendManager
33+
import com.lambda.network.mojang.getProfile
3334
import com.lambda.util.Communication.info
3435
import com.lambda.util.extension.CommandBuilder
3536
import com.lambda.util.text.ClickEvents
3637
import com.lambda.util.text.buildText
3738
import com.lambda.util.text.literal
3839
import com.lambda.util.text.styled
40+
import kotlinx.coroutines.runBlocking
3941
import java.awt.Color
4042

4143
object FriendCommand : LambdaCommand(
@@ -82,19 +84,24 @@ object FriendCommand : LambdaCommand(
8284
}
8385

8486
executeWithResult {
85-
val name = player().value()
86-
val id = mc.networkHandler
87-
?.playerList
88-
?.firstOrNull {
89-
it.profile.name == name &&
90-
it.profile != mc.gameProfile
91-
} ?: return@executeWithResult failure("Could not find the player on the server")
92-
93-
return@executeWithResult if (FriendManager.befriend(id.profile)) {
94-
this@FriendCommand.info(FriendManager.befriendedText(id.profile.name))
95-
success()
96-
} else {
97-
failure("This player is already in your friend list")
87+
runBlocking {
88+
val name = player().value()
89+
90+
if (mc.gameProfile.name == name) return@runBlocking failure("You can't befriend yourself")
91+
92+
val profile = mc.networkHandler
93+
?.playerList
94+
?.map { it.profile }
95+
?.firstOrNull { it.name == name }
96+
?: getProfile(name)
97+
.getOrElse { return@runBlocking failure("Could not find the player") }
98+
99+
return@runBlocking if (FriendManager.befriend(profile)) {
100+
info(FriendManager.befriendedText(profile.name))
101+
success()
102+
} else {
103+
failure("This player is already in your friend list")
104+
}
98105
}
99106
}
100107
}
@@ -111,18 +118,24 @@ object FriendCommand : LambdaCommand(
111118
}
112119

113120
executeWithResult {
114-
val uuid = player().value()
115-
val id = mc.networkHandler
116-
?.playerList
117-
?.firstOrNull {
118-
it.profile.id == uuid && it.profile != mc.gameProfile
119-
} ?: return@executeWithResult failure("Could not find the player on the server")
120-
121-
return@executeWithResult if (FriendManager.befriend(id.profile)) {
122-
this@FriendCommand.info(FriendManager.befriendedText(id.profile.name))
123-
success()
124-
} else {
125-
failure("This player is already in your friend list")
121+
runBlocking {
122+
val uuid = player().value()
123+
124+
if (mc.gameProfile.id == uuid) return@runBlocking failure("You can't befriend yourself")
125+
126+
val profile = mc.networkHandler
127+
?.playerList
128+
?.map { it.profile }
129+
?.firstOrNull { it.id == uuid }
130+
?: getProfile(uuid)
131+
.getOrElse { return@runBlocking failure("Could not find the player") }
132+
133+
return@runBlocking if (FriendManager.befriend(profile)) {
134+
this@FriendCommand.info(FriendManager.befriendedText(profile.name))
135+
success()
136+
} else {
137+
failure("This player is already in your friend list")
138+
}
126139
}
127140
}
128141
}

common/src/main/kotlin/com/lambda/config/Configuration.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ abstract class Configuration : Jsonable {
6262
get() = File("${primary.parent}/${primary.nameWithoutExtension}-backup.${primary.extension}")
6363

6464
init {
65+
// We need to implement a dependency graph of loadables and add functions to run before
66+
// and/or after a given Loadable children class is initialized
67+
//
68+
// class Load1(
69+
// override val priority = 1000,
70+
// override val before = Load2,
71+
// ) : Loadable {}
72+
//
73+
// class Load2(
74+
// override val priority = 1000,
75+
// ) : Loadable {}
76+
//
77+
// class Load3(
78+
// override val priority = 1000,
79+
// override val after = Load2,
80+
// ) : Loadable {}
81+
//
82+
// clientLifecycle<Load2>(shift = Pre) { event -> } // Will run before Load2
83+
// clientLifecycle<Load2>(shift = Post) { event -> } // Will run after Load2
6584
listenUnsafe<ClientEvent.Startup> { tryLoad() }
6685
listenUnsafe<ClientEvent.Shutdown>(Int.MIN_VALUE) { trySave() }
6786

@@ -96,11 +115,11 @@ abstract class Configuration : Jsonable {
96115
}
97116

98117
fun save() = runCatching {
99-
primary.createIfNotExists {
100-
it.parentFile.mkdirs()
101-
it.writeText(gson.toJson(toJson()))
102-
it.copyTo(backup, true)
103-
}
118+
primary.createIfNotExists()
119+
.let {
120+
it.writeText(gson.toJson(toJson()))
121+
it.copyTo(backup, true)
122+
}
104123
}
105124

106125
/**

common/src/main/kotlin/com/lambda/config/groups/Targeting.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.lambda.interaction.request.rotation.Rotation.Companion.dist
2424
import com.lambda.interaction.request.rotation.Rotation.Companion.rotation
2525
import com.lambda.interaction.request.rotation.Rotation.Companion.rotationTo
2626
import com.lambda.threading.runSafe
27+
import com.lambda.util.extension.fullHealth
2728
import com.lambda.util.math.distSq
2829
import com.lambda.util.world.fastEntitySearch
2930
import net.minecraft.client.network.ClientPlayerEntity
@@ -201,7 +202,7 @@ abstract class Targeting(
201202
/**
202203
* Prioritizes entities based on their health.
203204
*/
204-
HEALTH({ it.health.toDouble() }),
205+
HEALTH({ it.fullHealth }),
205206

206207
/**
207208
* Prioritizes entities based on their angle relative to the player's field of view.

common/src/main/kotlin/com/lambda/event/Subscriber.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ class Subscriber : ConcurrentHashMap<KClass<out Event>, ConcurrentSkipListSet<Li
3939
inline fun <reified T : Event> subscribe(listener: Listener<T>) =
4040
getOrPut(T::class) { defaultListenerSet }.add(listener)
4141

42+
/**
43+
* Allows a [Listener] to start receiving a specific type of [Event]'s [KClass implementation](KC).
44+
*
45+
* This should only be used in cases where the type of the event is erased.
46+
*/
47+
fun <T : Event> subscribe(kClass: KClass<out T>, listener: Listener<T>) =
48+
getOrPut(kClass) { defaultListenerSet }.add(listener)
49+
4250
/** Allows a [Subscriber] to start receiving all [Event]s of another [Subscriber]. */
4351
infix fun subscribe(subscriber: Subscriber) {
4452
subscriber.forEach { (eventType, listeners) ->
@@ -56,6 +64,7 @@ class Subscriber : ConcurrentHashMap<KClass<out Event>, ConcurrentSkipListSet<Li
5664

5765
/**
5866
* Unsubscribes all listeners associated with the current instance (the caller object).
67+
*
5968
* This method iterates over all values in the `Subscriber`'s map and removes listeners
6069
* whose `owner` property matches the caller object.
6170
*

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
/**

0 commit comments

Comments
 (0)