From d111c75fabf62f1e60944552030449df611babbd Mon Sep 17 00:00:00 2001 From: Ic3Tank <61137113+IceTank@users.noreply.github.com> Date: Wed, 25 Jun 2025 22:57:25 +0200 Subject: [PATCH 1/5] Add FreeLook Module --- .../com/lambda/mixin/render/CameraMixin.java | 15 ++++ .../lambda/module/modules/render/FreeLook.kt | 82 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 common/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt diff --git a/common/src/main/java/com/lambda/mixin/render/CameraMixin.java b/common/src/main/java/com/lambda/mixin/render/CameraMixin.java index 9c8167947..b30fe1bf8 100644 --- a/common/src/main/java/com/lambda/mixin/render/CameraMixin.java +++ b/common/src/main/java/com/lambda/mixin/render/CameraMixin.java @@ -20,6 +20,7 @@ import com.lambda.interaction.request.rotation.RotationManager; import com.lambda.module.modules.player.Freecam; import com.lambda.module.modules.render.CameraTweaks; +import com.lambda.module.modules.render.FreeLook; import net.minecraft.client.render.Camera; import net.minecraft.entity.Entity; import net.minecraft.world.BlockView; @@ -28,8 +29,10 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @Mixin(Camera.class) public abstract class CameraMixin { @@ -74,6 +77,8 @@ private void injectQuickPerspectiveSwap(BlockView area, Entity focusedEntity, bo private void onClipToSpace(float desiredCameraDistance, CallbackInfoReturnable info) { if (CameraTweaks.INSTANCE.isEnabled() && CameraTweaks.getNoClipCam()) { info.setReturnValue(desiredCameraDistance); + } else if (FreeLook.INSTANCE.isEnabled()) { + info.setReturnValue(desiredCameraDistance); } } @@ -93,8 +98,18 @@ private void onClipToSpace(float desiredCameraDistance, CallbackInfoReturnable. + */ + +package com.lambda.module.modules.render + +import com.lambda.Lambda +import com.lambda.event.events.PlayerEvent +import com.lambda.event.listener.SafeListener.Companion.listen +import com.lambda.interaction.request.rotation.Rotation +import com.lambda.module.Module +import com.lambda.util.extension.rotation +import net.minecraft.client.MinecraftClient +import net.minecraft.client.option.Perspective + +object FreeLook : Module( + name = "FreeLook", + description = "Allows you to look around freely while moving", + defaultTags = setOf(com.lambda.module.tag.ModuleTag.RENDER, com.lambda.module.tag.ModuleTag.MOVEMENT) +) { + val enableYaw by setting("Enable Yaw", true, "Don't effect pitch if enabled") + val enablePitch by setting("Enable Pitch", false, "Don't effect yaw if enabled") + val togglePerspective by setting("Toggle Perspective", true, "Toggle perspective when enabling FreeLook") + + var camera: Rotation = Rotation.ZERO + var previousPerspective: Perspective = Perspective.FIRST_PERSON + + /** + * @see net.minecraft.entity.Entity.changeLookDirection + */ + private const val SENSITIVITY_FACTOR = 0.15 + + @JvmStatic + fun updateCam() { + Lambda.mc.gameRenderer.apply { + camera.setRotation(FreeLook.camera.yawF, FreeLook.camera.pitchF) + } + } + + init { + previousPerspective = MinecraftClient.getInstance().options.perspective + + onEnable { + camera = player.rotation + previousPerspective = mc.options.perspective + if (togglePerspective) mc.options.perspective = Perspective.THIRD_PERSON_BACK + } + + onDisable { + updateCam() + mc.options.perspective = previousPerspective + } + + listen { + if (!isEnabled) return@listen + camera = camera.withDelta( + it.deltaYaw * SENSITIVITY_FACTOR, + it.deltaPitch * SENSITIVITY_FACTOR + ) + if (enablePitch) { + player.pitch = camera.pitchF + } + if (enableYaw) { + player.yaw = camera.yawF + } + it.cancel() + } + } +} \ No newline at end of file From f8f0f608060e33b096b4236d2a02052238ee47b9 Mon Sep 17 00:00:00 2001 From: Ic3Tank <61137113+IceTank@users.noreply.github.com> Date: Wed, 25 Jun 2025 23:00:40 +0200 Subject: [PATCH 2/5] Change default Enable Yaw setting to false to not confuse people --- .../main/kotlin/com/lambda/module/modules/render/FreeLook.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt b/common/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt index 992116a0e..36db7c1b7 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt @@ -31,7 +31,7 @@ object FreeLook : Module( description = "Allows you to look around freely while moving", defaultTags = setOf(com.lambda.module.tag.ModuleTag.RENDER, com.lambda.module.tag.ModuleTag.MOVEMENT) ) { - val enableYaw by setting("Enable Yaw", true, "Don't effect pitch if enabled") + val enableYaw by setting("Enable Yaw", false, "Don't effect pitch if enabled") val enablePitch by setting("Enable Pitch", false, "Don't effect yaw if enabled") val togglePerspective by setting("Toggle Perspective", true, "Toggle perspective when enabling FreeLook") From d9712779dbe11b44d61a79467215310b705bbbe4 Mon Sep 17 00:00:00 2001 From: Ic3Tank <61137113+IceTank@users.noreply.github.com> Date: Wed, 25 Jun 2025 23:14:16 +0200 Subject: [PATCH 3/5] Code cleanup --- .../kotlin/com/lambda/module/modules/render/FreeLook.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt b/common/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt index 36db7c1b7..d89e3efa4 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt @@ -22,14 +22,15 @@ import com.lambda.event.events.PlayerEvent import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.request.rotation.Rotation import com.lambda.module.Module +import com.lambda.module.tag.ModuleTag import com.lambda.util.extension.rotation -import net.minecraft.client.MinecraftClient import net.minecraft.client.option.Perspective + object FreeLook : Module( name = "FreeLook", description = "Allows you to look around freely while moving", - defaultTags = setOf(com.lambda.module.tag.ModuleTag.RENDER, com.lambda.module.tag.ModuleTag.MOVEMENT) + defaultTags = setOf(ModuleTag.PLAYER) ) { val enableYaw by setting("Enable Yaw", false, "Don't effect pitch if enabled") val enablePitch by setting("Enable Pitch", false, "Don't effect yaw if enabled") @@ -51,7 +52,7 @@ object FreeLook : Module( } init { - previousPerspective = MinecraftClient.getInstance().options.perspective + previousPerspective = Lambda.mc.options.perspective onEnable { camera = player.rotation From 04802dcba2bd072b0d5738aeb3b634302421ef89 Mon Sep 17 00:00:00 2001 From: Ic3Tank <61137113+IceTank@users.noreply.github.com> Date: Fri, 27 Jun 2025 18:37:39 +0200 Subject: [PATCH 4/5] Update CameraMixin documentation --- .../com/lambda/mixin/render/CameraMixin.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/common/src/main/java/com/lambda/mixin/render/CameraMixin.java b/common/src/main/java/com/lambda/mixin/render/CameraMixin.java index b30fe1bf8..5a269a13d 100644 --- a/common/src/main/java/com/lambda/mixin/render/CameraMixin.java +++ b/common/src/main/java/com/lambda/mixin/render/CameraMixin.java @@ -105,6 +105,39 @@ private float onDistanceUpdate(float desiredCameraDistance) { return desiredCameraDistance; } + /** + * Modifies the arguments for setting the camera rotation. + * Mixes into 4 arguments: + *

Experimental Minecart Controller:

+ *
+     * if (experimentalMinecartController.hasCurrentLerpSteps()) {
+     *     Vec3d vec3d = minecartEntity.getPassengerRidingPos(focusedEntity).subtract(minecartEntity.getPos()).subtract(focusedEntity.getVehicleAttachmentPos(minecartEntity)).add(new Vec3d(0.0, (double)MathHelper.lerp(tickProgress, this.lastCameraY, this.cameraY), 0.0));
+     *     this.setRotation(focusedEntity.getYaw(tickProgress), focusedEntity.getPitch(tickProgress));
+     *     this.setPos(experimentalMinecartController.getLerpedPosition(tickProgress).add(vec3d));
+     *     break label39;
+     * }
+     * 
+ *

Default Camera:

+ *
+     * this.setRotation(focusedEntity.getYaw(tickProgress), focusedEntity.getPitch(tickProgress));
+     * this.setPos(MathHelper.lerp((double)tickProgress, focusedEntity.lastX, focusedEntity.getX()), MathHelper.lerp((double)tickProgress, focusedEntity.lastY, focusedEntity.getY()) + (double)MathHelper.lerp(tickProgress, this.lastCameraY, this.cameraY), MathHelper.lerp((double)tickProgress, focusedEntity.lastZ, focusedEntity.getZ()));
+     * 
+ *

Third person camera:

+ *
+     * if (thirdPerson) {
+     *     if (inverseView) {
+     *         this.setRotation(this.yaw + 180.0F, -this.pitch);
+     *     }
+     *     // ...
+     * }
+     * 
+ *

When the player is focused on another Living Entity:

+ *
+     * Direction direction = ((LivingEntity)focusedEntity).getSleepingDirection();
+     * this.setRotation(direction != null ? direction.getPositiveHorizontalDegrees() - 180.0F : 0.0F, 0.0F);
+     * this.moveBy(0.0F, 0.3F, 0.0F);
+     * 
+ */ @ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V")) private void onUpdateSetRotationArgs(Args args) { if (FreeLook.INSTANCE.isEnabled()) { From af0f4aaf9ac79a66d3c796ede1c0d176acf9aa02 Mon Sep 17 00:00:00 2001 From: Edouard127 <46357922+Edouard127@users.noreply.github.com> Date: Thu, 24 Jul 2025 16:00:59 -0400 Subject: [PATCH 5/5] nit --- .../lambda/module/modules/render/FreeLook.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt b/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt index eaca4768a..f7163f9a3 100644 --- a/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt +++ b/src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt @@ -18,6 +18,7 @@ package com.lambda.module.modules.render import com.lambda.Lambda +import com.lambda.Lambda.mc import com.lambda.event.events.PlayerEvent import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.request.rotation.Rotation @@ -46,13 +47,13 @@ object FreeLook : Module( @JvmStatic fun updateCam() { - Lambda.mc.gameRenderer.apply { - camera.setRotation(FreeLook.camera.yawF, FreeLook.camera.pitchF) + mc.gameRenderer.apply { + camera.setRotation(this@FreeLook.camera.yawF, this@FreeLook.camera.pitchF) } } init { - previousPerspective = Lambda.mc.options.perspective + previousPerspective = mc.options.perspective onEnable { camera = player.rotation @@ -67,16 +68,15 @@ object FreeLook : Module( listen { if (!isEnabled) return@listen + camera = camera.withDelta( it.deltaYaw * SENSITIVITY_FACTOR, it.deltaPitch * SENSITIVITY_FACTOR ) - if (enablePitch) { - player.pitch = camera.pitchF - } - if (enableYaw) { - player.yaw = camera.yawF - } + + if (enablePitch) player.pitch = camera.pitchF + if (enableYaw) player.yaw = camera.yawF + it.cancel() } }