11package com.lambda.module.modules.player
22
3- import baritone.utils.PlayerMovementInput
43import com.lambda.Lambda.mc
5- import com.lambda.config.groups.RotationSettings
4+ import com.lambda.config.groups.IRotationConfig
65import com.lambda.event.events.*
76import com.lambda.event.listener.SafeListener.Companion.listener
87import com.lambda.interaction.rotation.Rotation
@@ -11,32 +10,37 @@ import com.lambda.interaction.rotation.RotationContext
1110import com.lambda.interaction.rotation.RotationMode
1211import com.lambda.module.Module
1312import com.lambda.module.tag.ModuleTag
13+ import com.lambda.util.math.VecUtils.plus
14+ import com.lambda.util.math.VecUtils.times
15+ import com.lambda.util.player.MovementUtils.calcMoveRad
1416import com.lambda.util.player.MovementUtils.cancel
17+ import com.lambda.util.player.MovementUtils.handledByBaritone
18+ import com.lambda.util.player.MovementUtils.isInputting
19+ import com.lambda.util.player.MovementUtils.movementVector
20+ import com.lambda.util.player.MovementUtils.newMovementInput
21+ import com.lambda.util.player.MovementUtils.roundedForward
22+ import com.lambda.util.player.MovementUtils.roundedStrafing
1523import com.lambda.util.player.MovementUtils.verticalMovement
1624import com.lambda.util.primitives.extension.interpolate
1725import com.lambda.util.primitives.extension.partialTicks
1826import com.lambda.util.primitives.extension.rotation
1927import com.lambda.util.world.raycast.RayCastUtils.orMiss
2028import com.lambda.util.world.raycast.RayCastUtils.orNull
21- import net.minecraft.client.input.KeyboardInput
2229import net.minecraft.client.option.Perspective
23- import net.minecraft.entity.Entity
2430import net.minecraft.util.math.Vec3d
2531
2632object Freecam : Module(
2733 name = " Freecam" ,
2834 description = " Move your camera freely" ,
2935 defaultTags = setOf(ModuleTag .PLAYER )
3036) {
31- private val speed by setting(" Speed" , 0.5f , 0.1f .. 1.0f , 0.1f )
32- private val sprint by setting(" Sprint Multiplier" , 3.0f , 0.1f .. 10.0f , 0.1f , description = " Set below 1.0 to fly slower on sprint." )
37+ private val speed by setting(" Speed" , 0.5 , 0.1 .. 1.0 , 0.1 )
38+ 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." )
3339 private val reach by setting(" Reach" , 10.0 , 1.0 .. 100.0 , 1.0 , " Freecam reach distance" )
3440 private val rotateToTarget by setting(" Rotate to target" , true )
3541
36- private val rotationConfig = RotationSettings (this ) {
37- rotateToTarget
38- }.apply {
39- rotationMode = RotationMode .LOCK
42+ private val rotationConfig = object : IRotationConfig .Instant {
43+ override val rotationMode = RotationMode .LOCK
4044 }
4145
4246 private var lastPerspective = Perspective .FIRST_PERSON
@@ -64,7 +68,6 @@ object Freecam : Module(
6468 init {
6569 onEnable {
6670 lastPerspective = mc.options.perspective
67- mc.options.perspective = Perspective .FIRST_PERSON
6871 position = player.eyePos
6972 rotation = player.rotation
7073 velocity = Vec3d .ZERO
@@ -74,12 +77,12 @@ object Freecam : Module(
7477 mc.options.perspective = lastPerspective
7578 }
7679
77- listener<RotationEvent .Update >(Int .MAX_VALUE ) {
80+ listener<RotationEvent .Update >(Int .MAX_VALUE ) { event ->
7881 if (! rotateToTarget) return @listener
7982 val target = mc.crosshairTarget?.orNull ? : return @listener
8083
8184 val rotation = player.eyePos.rotationTo(target.pos)
82- it .context = RotationContext (rotation, rotationConfig)
85+ event .context = RotationContext (rotation, rotationConfig)
8386 }
8487
8588 listener<EntityEvent .ChangeLookDirection > {
@@ -91,37 +94,35 @@ object Freecam : Module(
9194 }
9295
9396 listener<MovementEvent .InputUpdate > { event ->
97+ mc.options.perspective = Perspective .FIRST_PERSON
98+
9499 // Don't block baritone from working
95- if (event.input !is PlayerMovementInput ) {
100+ if (! event.input.handledByBaritone ) {
96101 // Reset actual input
97102 event.input.cancel()
98103 }
99104
100105 // Create new input for freecam
101- val input = KeyboardInput (mc.options).apply {
102- tick(false , 1f )
103- }
104-
105- val inputVec = Vec3d (
106- input.movementSideways.toDouble(),
107- input.verticalMovement.toDouble(),
108- input.movementForward.toDouble()
109- )
106+ val input = newMovementInput(assumeBaritoneUsage = false , slowDownCheck = false )
107+ val sprintModifier = if (mc.options.sprintKey.isPressed) sprint else 1.0
108+ val moveDir = calcMoveRad(rotation.yawF, input.roundedForward, input.roundedStrafing)
109+ var moveVec = movementVector(moveDir, input.verticalMovement) * speed * sprintModifier
110+ if (! input.isInputting) moveVec * = Vec3d (0.0 , 1.0 , 0.0 )
110111
111- val endSpeed = speed * if (mc.options.sprintKey.isPressed) sprint else 1.0f
112- val velocityDelta = Entity .movementInputToVelocity(inputVec, endSpeed, rotation.yawF)
112+ // Apply movement
113+ velocity + = moveVec
114+ velocity * = 0.6
113115
114- // Move freecam
115- velocity = velocity.add(velocityDelta).multiply(0.6 )
116+ // Update position
116117 prevPosition = position
117- position = position.add( velocity)
118+ position + = velocity
118119 }
119120
120121 listener<RenderEvent .UpdateTarget > {
121122 it.cancel()
122123
123124 mc.crosshairTarget = rotation
124- .rayCast(reach, eye = interpolatedPosition)
125+ .rayCast(reach, interpolatedPosition)
125126 .orMiss // Can't be null (otherwise mc will spam "Null returned as 'hitResult', this shouldn't happen!")
126127 }
127128
0 commit comments