Skip to content

Commit 503d2d2

Browse files
committed
set player yaw and pitch through rotation manager to check it isn't locked
1 parent dd8de12 commit 503d2d2

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import net.minecraft.block.enums.CameraSubmersionType;
2626
import net.minecraft.client.render.Camera;
2727
import net.minecraft.entity.Entity;
28-
import net.minecraft.world.BlockView;
2928
import net.minecraft.world.World;
3029
import org.spongepowered.asm.mixin.Mixin;
3130
import org.spongepowered.asm.mixin.Shadow;
@@ -42,6 +41,12 @@ public abstract class CameraMixin {
4241
@Shadow
4342
public abstract void setRotation(float yaw, float pitch);
4443

44+
@Shadow
45+
public abstract float getPitch();
46+
47+
@Shadow
48+
public abstract float getYaw();
49+
4550
@Inject(method = "update", at = @At("TAIL"))
4651
private void onUpdate(World area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickProgress, CallbackInfo ci) {
4752
if (!Freecam.INSTANCE.isEnabled()) return;
@@ -59,22 +64,23 @@ private void onUpdate(World area, Entity focusedEntity, boolean thirdPerson, boo
5964
* );
6065
* }</pre>
6166
*/
62-
@Inject(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setPos(DDD)V", shift = At.Shift.AFTER))
67+
@Inject(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V", shift = At.Shift.AFTER))
6368
private void injectQuickPerspectiveSwap(World area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickProgress, CallbackInfo ci) {
6469
var rot = RotationManager.getLockRotation();
6570
if (rot == null) return;
66-
setRotation(rot.getYawF(), rot.getPitchF());
71+
if (FreeLook.INSTANCE.isEnabled()) {
72+
if (FreeLook.getEnableYaw()) setRotation(rot.getYawF(), getPitch());
73+
if (FreeLook.getEnablePitch()) setRotation(getYaw(), rot.getPitchF());
74+
} else setRotation(rot.getYawF(), rot.getPitchF());
6775
}
6876

6977
/**
7078
* Allows camera to clip through blocks in third person
7179
*/
7280
@Inject(method = "clipToSpace", at = @At("HEAD"), cancellable = true)
73-
private void onClipToSpace(float desiredCameraDistance, CallbackInfoReturnable<Float> info) {
81+
private void onClipToSpace(float distance, CallbackInfoReturnable<Float> cir) {
7482
if (CameraTweaks.INSTANCE.isEnabled() && CameraTweaks.getNoClipCam()) {
75-
info.setReturnValue(desiredCameraDistance);
76-
} else if (FreeLook.INSTANCE.isEnabled()) {
77-
info.setReturnValue(desiredCameraDistance);
83+
cir.setReturnValue(distance);
7884
}
7985
}
8086

@@ -91,14 +97,12 @@ private void onClipToSpace(float desiredCameraDistance, CallbackInfoReturnable<F
9197
* }</pre>
9298
*/
9399
@ModifyArg(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;clipToSpace(F)F"))
94-
private float onDistanceUpdate(float desiredCameraDistance) {
100+
private float onDistanceUpdate(float distance) {
95101
if (CameraTweaks.INSTANCE.isEnabled()) {
96102
return CameraTweaks.getCamDistance();
97-
} else if (FreeLook.INSTANCE.isEnabled()) {
98-
return 4.0F;
99103
}
100104

101-
return desiredCameraDistance;
105+
return distance;
102106
}
103107

104108
/**

src/main/kotlin/com/lambda/interaction/managers/rotating/Rotation.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ data class Rotation(val yaw: Double, val pitch: Double) {
9595
var Entity.rotation
9696
get() = Rotation(yaw, pitch)
9797
set(value) {
98-
yaw = value.yawF
99-
pitch = value.pitchF
98+
runSafe {
99+
RotationManager.setPlayerYaw(value.yaw)
100+
RotationManager.setPlayerPitch(value.pitch)
101+
}
100102
}
101103

102104
fun wrap(deg: Double) = wrapDegrees(deg)

src/main/kotlin/com/lambda/interaction/managers/rotating/RotationManager.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ object RotationManager : Manager<RotationRequest>(
7474

7575
private var changedThisTick = false
7676

77+
private val IRotationRequest.overridable get() = age >= 1
78+
7779
override fun load(): String {
7880
super.load()
7981

@@ -161,7 +163,15 @@ object RotationManager : Manager<RotationRequest>(
161163
else -> false
162164
}
163165

164-
private val IRotationRequest.overridable get() = age >= 1
166+
context(safeContext: SafeContext)
167+
fun setPlayerYaw(yaw: Double) {
168+
if (lockYaw == null) safeContext.player.yaw = yaw.toFloat()
169+
}
170+
171+
context(safeContext: SafeContext)
172+
fun setPlayerPitch(pitch: Double) {
173+
if (lockPitch == null) safeContext.player.pitch = pitch.toFloat()
174+
}
165175

166176
/**
167177
* If the rotation has not been changed this tick, the [activeRequest]'s target rotation is updated, and

src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.lambda.Lambda.mc
2121
import com.lambda.event.events.PlayerEvent
2222
import com.lambda.event.listener.SafeListener.Companion.listen
2323
import com.lambda.interaction.managers.rotating.Rotation
24+
import com.lambda.interaction.managers.rotating.RotationManager
2425
import com.lambda.module.Module
2526
import com.lambda.module.tag.ModuleTag
2627
import com.lambda.util.extension.rotation
@@ -32,8 +33,8 @@ object FreeLook : Module(
3233
description = "Allows you to look around freely while moving",
3334
tag = ModuleTag.PLAYER,
3435
) {
35-
val enableYaw by setting("Enable Yaw", false, "Don't effect pitch if enabled")
36-
val enablePitch by setting("Enable Pitch", false, "Don't effect yaw if enabled")
36+
@JvmStatic val enableYaw by setting("Enable Yaw", false, "Don't effect pitch if enabled")
37+
@JvmStatic val enablePitch by setting("Enable Pitch", false, "Don't effect yaw if enabled")
3738
val togglePerspective by setting("Toggle Perspective", true, "Toggle perspective when enabling FreeLook")
3839

3940
var camera: Rotation = Rotation.ZERO
@@ -73,8 +74,8 @@ object FreeLook : Module(
7374
it.deltaPitch * SENSITIVITY_FACTOR
7475
)
7576

76-
if (enablePitch) player.pitch = camera.pitchF
77-
if (enableYaw) player.yaw = camera.yawF
77+
if (enableYaw) RotationManager.setPlayerYaw(camera.yaw)
78+
if (enablePitch) RotationManager.setPlayerPitch(camera.pitch)
7879

7980
it.cancel()
8081
}

0 commit comments

Comments
 (0)