Skip to content

Commit b7c1510

Browse files
committed
Fix some code
Add setting to send packet sneak false
1 parent d20c1dd commit b7c1510

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

src/main/kotlin/com/lambda/module/modules/movement/AutoMount.kt

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
package com.lambda.module.modules.movement
1919

2020
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
21+
import com.lambda.config.applyEdits
22+
import com.lambda.context.AutomatedSafeContext
2123
import com.lambda.context.SafeContext
2224
import com.lambda.event.events.TickEvent
2325
import com.lambda.event.listener.SafeListener.Companion.listen
2426
import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest
25-
import com.lambda.interaction.managers.rotating.visibilty.VisibilityChecker
2627
import com.lambda.interaction.managers.rotating.visibilty.VisibilityChecker.findRotation
2728
import com.lambda.interaction.managers.rotating.visibilty.lookAtEntity
29+
import com.lambda.interaction.managers.rotating.visibilty.lookAtHit
2830
import com.lambda.module.Module
2931
import com.lambda.module.tag.ModuleTag
3032
import com.lambda.threading.runSafeAutomated
@@ -52,13 +54,19 @@ class AutoMount : Module(
5254
var interval by setting("Interval", 50, 1..200, 1, unit = "ms", description = "Interact interval")
5355
var range by setting("Range", 4.0, 1.0..20.0, 0.1, description = "Mount range")
5456
var rotate by setting("Rotate", false, description = "Rotate to the entity when mounting")
57+
var packetUnCrouch by setting("Packet Crouch", true, description = "Send the mount packet with the crouch flag false")
5558
var debug by setting("Debug", false, description = "Print debug messages")
5659

5760
val intervalTimer = Timer()
5861
var lastEntity: Entity? = null
5962

6063
init {
61-
setDefaultAutomationConfig("AutoMount")
64+
setDefaultAutomationConfig("AutoMount") {
65+
applyEdits {
66+
hideAllGroupsExcept(rotationConfig, interactConfig)
67+
}
68+
}
69+
6270
onEnable {
6371
intervalTimer.reset()
6472
lastEntity = null
@@ -74,7 +82,6 @@ class AutoMount : Module(
7482
autoMountEntityList.contains(it.type) && canRide(it) && it.findRotation(range, player.eyePos) != null
7583
}.sortedBy { it.squaredDistanceTo(player.pos) }
7684
entity.firstOrNull()?.let {
77-
intervalTimer.reset()
7885
interactEntity(it)
7986
if (debug) info("Mounting ${it.name}")
8087
}
@@ -92,30 +99,36 @@ class AutoMount : Module(
9299
return@let
93100
}
94101
if (canRide(it)) {
95-
intervalTimer.reset()
96-
interactEntity(it)
102+
runSafeAutomated {
103+
interactEntity(it)
104+
}
97105
}
98106
}
99107
}
100108
}
101109

102-
private fun SafeContext.interactEntity(entity: Entity) {
110+
private fun AutomatedSafeContext.interactEntity(entity: Entity) {
111+
intervalTimer.reset()
103112
if (rotate) {
104-
runSafeAutomated {
105-
var hit: VisibilityChecker.CheckedHit? = null
106-
rotationRequest {
107-
hit = lookAtEntity(entity)
108-
}.submit()
109-
hit?.let {
110-
val hitResult = it.hit as? EntityHitResult ?: return@let
111-
interaction.interactEntityAtLocation(player, entity, hitResult, Hand.MAIN_HAND)
112-
return@runSafeAutomated
113-
} ?: run {
114-
if (debug) debug("Not rotation found to mount entity")
115-
return@runSafeAutomated
113+
lookAtEntity(entity)?.let {
114+
val done = rotationRequest {
115+
lookAtHit(it.hit)
116+
}.submit().done
117+
if (!done) {
118+
if (debug) debug("Rotation request failed to submit")
119+
return
116120
}
117-
if (debug) debug("Invalid entity rotation")
121+
val hitResult = it.hit as? EntityHitResult ?: return@let
122+
// Send packet to manually set sneak state
123+
val vec3d = hitResult.getPos().subtract(entity.x, entity.y, entity.z)
124+
val crouch = if (packetUnCrouch) false else player.isSneaking
125+
connection.sendPacket(PlayerInteractEntityC2SPacket.interactAt(entity, crouch, Hand.MAIN_HAND, vec3d))
126+
return
127+
} ?: run {
128+
if (debug) debug("Not rotation found to mount entity")
129+
return
118130
}
131+
if (debug) debug("Invalid entity rotation")
119132
} else {
120133
connection.sendPacket(PlayerInteractEntityC2SPacket.interactAt(entity, false, Hand.MAIN_HAND, Vec3d(0.5, 0.5, 0.5)))
121134
connection.sendPacket(PlayerInteractEntityC2SPacket.interact(entity, false, Hand.MAIN_HAND))

src/main/resources/lambda.accesswidener

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ transitive-accessible field net/minecraft/entity/Entity world Lnet/minecraft/wor
6262
transitive-accessible class net/minecraft/screen/slot/ArmorSlot
6363
transitive-accessible field net/minecraft/screen/slot/ArmorSlot equipmentSlot Lnet/minecraft/entity/EquipmentSlot;
6464
transitive-accessible field net/minecraft/entity/Entity FLAGS Lnet/minecraft/entity/data/TrackedData;
65-
accessible method net/minecraft/entity/Entity canAddPassenger (Lnet/minecraft/entity/Entity;)Z
65+
transitive-accessible method net/minecraft/entity/Entity canAddPassenger (Lnet/minecraft/entity/Entity;)Z
6666

6767
# Camera
6868
transitive-accessible method net/minecraft/client/render/Camera setPos (DDD)V

0 commit comments

Comments
 (0)