@@ -30,6 +30,8 @@ import com.lambda.interaction.request.rotating.visibilty.lookAt
3030import com.lambda.interaction.request.rotating.visibilty.lookAtHit
3131import com.lambda.module.Module
3232import com.lambda.module.tag.ModuleTag
33+ import com.lambda.util.Describable
34+ import com.lambda.util.NamedEnum
3335import com.lambda.util.extension.rotation
3436import com.lambda.util.math.interpolate
3537import com.lambda.util.math.plus
@@ -45,6 +47,10 @@ import com.lambda.util.player.MovementUtils.roundedStrafing
4547import com.lambda.util.player.MovementUtils.verticalMovement
4648import com.lambda.util.world.raycast.RayCastUtils.orMiss
4749import net.minecraft.client.option.Perspective
50+ import net.minecraft.util.hit.BlockHitResult
51+ import net.minecraft.util.hit.HitResult
52+ import net.minecraft.util.math.BlockPos
53+ import net.minecraft.util.math.Direction
4854import net.minecraft.util.math.Vec3d
4955
5056object Freecam : Module(
@@ -57,9 +63,9 @@ object Freecam : Module(
5763 private val sprint by setting(" Sprint Multiplier" , 3.0 , 0.1 .. 10.0 , 0.1 , description = " Set below 1.0 to fly slower on sprint." )
5864 private val reach by setting(" Reach" , 10.0 , 1.0 .. 100.0 , 1.0 , " Freecam reach distance" )
5965 private val rotateMode by setting(" Rotate Mode" , FreecamRotationMode .None , " Rotation mode" )
60- private val relative by setting( " Relative " , false , " Moves freecam relative to player position " ).onValueChange { _, it ->
61- if (it) lastPlayerPosition = player.pos
62- }
66+ .onValueChange { _, it -> if (it == FreecamRotationMode . LookAtTarget ) mc.crosshairTarget = BlockHitResult .createMissed( Vec3d . ZERO , Direction . UP , BlockPos . ORIGIN ) }
67+ private val relative by setting( " Relative " , false , " Moves freecam relative to player position " )
68+ .onValueChange { _, it -> if (it) lastPlayerPosition = player.pos }
6369 private val keepYLevel by setting(" Keep Y Level" , false , " Don't change the camera y-level on player movement" ) { relative }
6470
6571 override val rotationConfig = RotationConfig .Instant (RotationMode .Lock )
@@ -107,7 +113,14 @@ object Freecam : Module(
107113 when (rotateMode) {
108114 FreecamRotationMode .None -> return @listen
109115 FreecamRotationMode .KeepRotation -> lookAt(rotation).requestBy(this @Freecam)
110- FreecamRotationMode .LookAtTarget -> mc.crosshairTarget?.let { lookAtHit(it)?.requestBy(this @Freecam) }
116+ FreecamRotationMode .LookAtTarget ->
117+ mc.crosshairTarget?.let {
118+ when (it) {
119+ is BlockHitResult -> lookAt(it.pos).requestBy(this @Freecam)
120+ else -> lookAtHit(it)?.requestBy(this @Freecam)
121+
122+ }
123+ }
111124 }
112125 }
113126
@@ -150,12 +163,12 @@ object Freecam : Module(
150163 }
151164 }
152165
153- listen<RenderEvent .UpdateTarget > {
154- it.cancel()
155-
166+ listen<RenderEvent .UpdateTarget >(priority = 1 ) { event -> // Higher priority then RotationManager to run before RotationManager modifies mc.crosshairTarget
156167 mc.crosshairTarget = rotation
157168 .rayCast(reach, lerpPos)
158169 .orMiss // Can't be null (otherwise mc will spam "Null returned as 'hitResult', this shouldn't happen!")
170+
171+ mc.crosshairTarget?.let { if (it.type != HitResult .Type .MISS ) event.cancel() }
159172 }
160173 }
161174
0 commit comments