1+ /*
2+ * Copyright 2025 Lambda
3+ *
4+ * This program is free software: you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation, either version 3 of the License, or
7+ * (at your option) any later version.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+ package com.lambda.module.modules.render
19+
20+ import com.lambda.Lambda
21+ import com.lambda.event.events.PlayerEvent
22+ import com.lambda.event.listener.SafeListener.Companion.listen
23+ import com.lambda.interaction.request.rotation.Rotation
24+ import com.lambda.module.Module
25+ import com.lambda.util.extension.rotation
26+ import net.minecraft.client.MinecraftClient
27+ import net.minecraft.client.option.Perspective
28+
29+ object FreeLook : Module(
30+ name = " FreeLook" ,
31+ description = " Allows you to look around freely while moving" ,
32+ defaultTags = setOf(com.lambda.module.tag.ModuleTag .RENDER , com.lambda.module.tag.ModuleTag .MOVEMENT )
33+ ) {
34+ val enableYaw by setting(" Enable Yaw" , true , " Don't effect pitch if enabled" )
35+ val enablePitch by setting(" Enable Pitch" , false , " Don't effect yaw if enabled" )
36+ val togglePerspective by setting(" Toggle Perspective" , true , " Toggle perspective when enabling FreeLook" )
37+
38+ var camera: Rotation = Rotation .ZERO
39+ var previousPerspective: Perspective = Perspective .FIRST_PERSON
40+
41+ /* *
42+ * @see net.minecraft.entity.Entity.changeLookDirection
43+ */
44+ private const val SENSITIVITY_FACTOR = 0.15
45+
46+ @JvmStatic
47+ fun updateCam () {
48+ Lambda .mc.gameRenderer.apply {
49+ camera.setRotation(FreeLook .camera.yawF, FreeLook .camera.pitchF)
50+ }
51+ }
52+
53+ init {
54+ previousPerspective = MinecraftClient .getInstance().options.perspective
55+
56+ onEnable {
57+ camera = player.rotation
58+ previousPerspective = mc.options.perspective
59+ if (togglePerspective) mc.options.perspective = Perspective .THIRD_PERSON_BACK
60+ }
61+
62+ onDisable {
63+ updateCam()
64+ mc.options.perspective = previousPerspective
65+ }
66+
67+ listen<PlayerEvent .ChangeLookDirection > {
68+ if (! isEnabled) return @listen
69+ camera = camera.withDelta(
70+ it.deltaYaw * SENSITIVITY_FACTOR ,
71+ it.deltaPitch * SENSITIVITY_FACTOR
72+ )
73+ if (enablePitch) {
74+ player.pitch = camera.pitchF
75+ }
76+ if (enableYaw) {
77+ player.yaw = camera.yawF
78+ }
79+ it.cancel()
80+ }
81+ }
82+ }
0 commit comments