Skip to content

Commit 20afb4e

Browse files
committed
setPlayerRotation in RotationManager
1 parent 503d2d2 commit 20afb4e

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public abstract class CameraMixin {
4747
@Shadow
4848
public abstract float getYaw();
4949

50+
@Shadow
51+
public float yaw;
52+
53+
@Shadow
54+
public float pitch;
55+
5056
@Inject(method = "update", at = @At("TAIL"))
5157
private void onUpdate(World area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickProgress, CallbackInfo ci) {
5258
if (!Freecam.INSTANCE.isEnabled()) return;
@@ -64,18 +70,21 @@ private void onUpdate(World area, Entity focusedEntity, boolean thirdPerson, boo
6470
* );
6571
* }</pre>
6672
*/
67-
@Inject(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V", shift = At.Shift.AFTER))
73+
@Inject(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setPos(DDD)V", shift = At.Shift.AFTER))
6874
private void injectQuickPerspectiveSwap(World area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickProgress, CallbackInfo ci) {
6975
var rot = RotationManager.getLockRotation();
7076
if (rot == null) return;
7177
if (FreeLook.INSTANCE.isEnabled()) {
72-
if (FreeLook.getEnableYaw()) setRotation(rot.getYawF(), getPitch());
73-
if (FreeLook.getEnablePitch()) setRotation(getYaw(), rot.getPitchF());
78+
var newYaw = yaw;
79+
var newPitch = pitch;
80+
if (FreeLook.getEnableYaw()) newYaw = rot.getYawF();
81+
if (FreeLook.getEnablePitch()) newPitch = rot.getPitchF();
82+
setRotation(newYaw, newPitch);
7483
} else setRotation(rot.getYawF(), rot.getPitchF());
7584
}
7685

7786
/**
78-
* Allows camera to clip through blocks in third person
87+
* Allows the camera to clip through blocks in third person
7988
*/
8089
@Inject(method = "clipToSpace", at = @At("HEAD"), cancellable = true)
8190
private void onClipToSpace(float distance, CallbackInfoReturnable<Float> cir) {

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

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

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

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ object RotationManager : Manager<RotationRequest>(
173173
if (lockPitch == null) safeContext.player.pitch = pitch.toFloat()
174174
}
175175

176+
context(safeContext: SafeContext)
177+
fun setPlayerRotation(rotation: Rotation) {
178+
setPlayerYaw(rotation.yaw)
179+
setPlayerPitch(rotation.pitch)
180+
}
181+
176182
/**
177183
* If the rotation has not been changed this tick, the [activeRequest]'s target rotation is updated, and
178184
* likewise the [activeRotation]. The [activeRequest] is then updated, ticking the [RotationRequest.keepTicks]

0 commit comments

Comments
 (0)