Skip to content

Commit d111c75

Browse files
committed
Add FreeLook Module
1 parent 507c375 commit d111c75

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

common/src/main/java/com/lambda/mixin/render/CameraMixin.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.lambda.interaction.request.rotation.RotationManager;
2121
import com.lambda.module.modules.player.Freecam;
2222
import com.lambda.module.modules.render.CameraTweaks;
23+
import com.lambda.module.modules.render.FreeLook;
2324
import net.minecraft.client.render.Camera;
2425
import net.minecraft.entity.Entity;
2526
import net.minecraft.world.BlockView;
@@ -28,8 +29,10 @@
2829
import org.spongepowered.asm.mixin.injection.At;
2930
import org.spongepowered.asm.mixin.injection.Inject;
3031
import org.spongepowered.asm.mixin.injection.ModifyArg;
32+
import org.spongepowered.asm.mixin.injection.ModifyArgs;
3133
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3234
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
35+
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
3336

3437
@Mixin(Camera.class)
3538
public abstract class CameraMixin {
@@ -74,6 +77,8 @@ private void injectQuickPerspectiveSwap(BlockView area, Entity focusedEntity, bo
7477
private void onClipToSpace(float desiredCameraDistance, CallbackInfoReturnable<Float> info) {
7578
if (CameraTweaks.INSTANCE.isEnabled() && CameraTweaks.getNoClipCam()) {
7679
info.setReturnValue(desiredCameraDistance);
80+
} else if (FreeLook.INSTANCE.isEnabled()) {
81+
info.setReturnValue(desiredCameraDistance);
7782
}
7883
}
7984

@@ -93,8 +98,18 @@ private void onClipToSpace(float desiredCameraDistance, CallbackInfoReturnable<F
9398
private float onDistanceUpdate(float desiredCameraDistance) {
9499
if (CameraTweaks.INSTANCE.isEnabled()) {
95100
return CameraTweaks.getCamDistance();
101+
} else if (FreeLook.INSTANCE.isEnabled()) {
102+
return 4.0F;
96103
}
97104

98105
return desiredCameraDistance;
99106
}
107+
108+
@ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V"))
109+
private void onUpdateSetRotationArgs(Args args) {
110+
if (FreeLook.INSTANCE.isEnabled()) {
111+
args.set(0, FreeLook.INSTANCE.getCamera().getYawF());
112+
args.set(1, FreeLook.INSTANCE.getCamera().getPitchF());
113+
}
114+
}
100115
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

Comments
 (0)