1818package com.lambda.module.modules.movement
1919
2020import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
21+ import com.lambda.config.applyEdits
22+ import com.lambda.context.AutomatedSafeContext
2123import com.lambda.context.SafeContext
2224import com.lambda.event.events.TickEvent
2325import com.lambda.event.listener.SafeListener.Companion.listen
2426import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest
25- import com.lambda.interaction.managers.rotating.visibilty.VisibilityChecker
2627import com.lambda.interaction.managers.rotating.visibilty.VisibilityChecker.findRotation
2728import com.lambda.interaction.managers.rotating.visibilty.lookAtEntity
29+ import com.lambda.interaction.managers.rotating.visibilty.lookAtHit
2830import com.lambda.module.Module
2931import com.lambda.module.tag.ModuleTag
3032import 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 ))
0 commit comments