@@ -21,17 +21,22 @@ import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
2121import com.lambda.context.SafeContext
2222import com.lambda.event.events.TickEvent
2323import com.lambda.event.listener.SafeListener.Companion.listen
24+ import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest
25+ import com.lambda.interaction.managers.rotating.visibilty.VisibilityChecker
2426import com.lambda.interaction.managers.rotating.visibilty.VisibilityChecker.findRotation
27+ import com.lambda.interaction.managers.rotating.visibilty.lookAtEntity
2528import com.lambda.module.Module
2629import com.lambda.module.tag.ModuleTag
2730import com.lambda.threading.runSafeAutomated
31+ import com.lambda.util.Communication.debug
2832import com.lambda.util.Communication.info
2933import com.lambda.util.Timer
3034import com.lambda.util.world.fastEntitySearch
3135import net.minecraft.entity.Entity
3236import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket
3337import net.minecraft.registry.Registries
3438import net.minecraft.util.Hand
39+ import net.minecraft.util.hit.EntityHitResult
3540import net.minecraft.util.math.Vec3d
3641import kotlin.time.Duration.Companion.milliseconds
3742
@@ -46,6 +51,7 @@ class AutoMount : Module(
4651
4752 var interval by setting(" Interval" , 50 , 1 .. 200 , 1 , unit = " ms" , description = " Interact interval" )
4853 var range by setting(" Range" , 4.0 , 1.0 .. 20.0 , 0.1 , description = " Mount range" )
54+ var rotate by setting(" Rotate" , false , description = " Rotate to the entity when mounting" )
4955 var debug by setting(" Debug" , false , description = " Print debug messages" )
5056
5157 val intervalTimer = Timer ()
@@ -77,12 +83,9 @@ class AutoMount : Module(
7783 if (! autoRemount) {
7884 return @listen
7985 }
80- if (player.vehicle != null ) {
86+ if (player.vehicle?.isRemoved == false ) {
8187 lastEntity = player.vehicle
8288 }
83- if (lastEntity == null ) {
84- return @listen
85- }
8689 lastEntity?.let {
8790 if (it.isRemoved || it.distanceTo(player) > range) {
8891 lastEntity = null
@@ -97,8 +100,26 @@ class AutoMount : Module(
97100 }
98101
99102 private fun SafeContext.interactEntity (entity : Entity ) {
100- mc.networkHandler?.sendPacket(PlayerInteractEntityC2SPacket .interactAt(entity, false , Hand .MAIN_HAND , Vec3d (0.5 , 0.5 , 0.5 )))
101- mc.networkHandler?.sendPacket(PlayerInteractEntityC2SPacket .interact(entity, false , Hand .MAIN_HAND ))
103+ 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
116+ }
117+ if (debug) debug(" Invalid entity rotation" )
118+ }
119+ } else {
120+ connection.sendPacket(PlayerInteractEntityC2SPacket .interactAt(entity, false , Hand .MAIN_HAND , Vec3d (0.5 , 0.5 , 0.5 )))
121+ connection.sendPacket(PlayerInteractEntityC2SPacket .interact(entity, false , Hand .MAIN_HAND ))
122+ }
102123 }
103124
104125 private fun SafeContext.canRide (entity : Entity ) = entity.canAddPassenger(player)
0 commit comments