1
+ package com.lambda.client.module.modules.render
2
+
3
+ import com.lambda.client.event.SafeClientEvent
4
+ import com.lambda.client.module.Category
5
+ import com.lambda.client.module.Module
6
+ import com.lambda.client.util.threads.runSafe
7
+ import com.lambda.client.util.threads.safeListener
8
+ import net.minecraft.entity.Entity
9
+ import net.minecraft.util.math.MathHelper
10
+ import net.minecraftforge.client.event.EntityViewRenderEvent
11
+ import net.minecraftforge.client.event.InputUpdateEvent
12
+ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo
13
+
14
+ object FreeLook : Module(
15
+ name = " FreeLook" ,
16
+ description = " Look Freely" ,
17
+ category = Category .RENDER
18
+ ) {
19
+ private val arrowKeyYawAdjust by setting(" Arrow Key Yaw Adjust" , false )
20
+ private val arrowKeyYawAdjustIncrement by setting(" Yaw Adjust Increment" , 1.0f , 0.001f .. 10.0f , 0.001f ,
21
+ visibility = { arrowKeyYawAdjust });
22
+
23
+ private var cameraYaw: Float = 0f
24
+ private var cameraPitch: Float = 0f
25
+ private var thirdPersonBefore: Int = 0
26
+
27
+ init {
28
+ onEnable {
29
+ runSafe {
30
+ thirdPersonBefore = mc.gameSettings.thirdPersonView
31
+ mc.gameSettings.thirdPersonView = 1 ;
32
+ cameraYaw = player.rotationYaw + 180.0f
33
+ cameraPitch = player.rotationPitch
34
+ }
35
+ }
36
+
37
+ onDisable {
38
+ mc.gameSettings.thirdPersonView = thirdPersonBefore
39
+ }
40
+
41
+ safeListener<EntityViewRenderEvent .CameraSetup > {
42
+ if (mc.gameSettings.thirdPersonView <= 0 ) return @safeListener
43
+
44
+ it.yaw = cameraYaw
45
+ it.pitch = cameraPitch
46
+ }
47
+
48
+ safeListener<InputUpdateEvent > {
49
+ if (! arrowKeyYawAdjust) return @safeListener
50
+
51
+ if (it.movementInput.leftKeyDown) {
52
+ // shift cam and player rot left by x degrees
53
+ updateYaw(- arrowKeyYawAdjustIncrement)
54
+ it.movementInput.leftKeyDown = false
55
+ }
56
+ if (it.movementInput.rightKeyDown) {
57
+ // shift cam and player rot right by x degrees
58
+ updateYaw(arrowKeyYawAdjustIncrement)
59
+ it.movementInput.rightKeyDown = false
60
+ }
61
+ it.movementInput.moveStrafe = 0.0f
62
+ }
63
+ }
64
+
65
+ private fun SafeClientEvent.updateYaw (dYaw : Float ) {
66
+ cameraYaw + = dYaw
67
+ player.rotationYaw + = dYaw
68
+ }
69
+
70
+ @JvmStatic
71
+ fun handleTurn (entity : Entity , yaw : Float , pitch : Float , ci : CallbackInfo ): Boolean {
72
+ if (isDisabled || mc.player == null ) return false
73
+ return if (entity == mc.player) {
74
+ this .cameraYaw + = yaw * 0.15f
75
+ this .cameraPitch - = pitch * 0.15f
76
+ this .cameraPitch = MathHelper .clamp(this .cameraPitch, - 180.0f , 180.0f )
77
+ ci.cancel()
78
+ true
79
+ } else {
80
+ false
81
+ }
82
+ }
83
+ }
0 commit comments