From 4e0d9710090bf527a6fec3766a0f0ebf731a3268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 13:05:12 -0700 Subject: [PATCH] Fix: incorrect roll on certain axis --- .../create/trainperspective/PlayerPerspectiveBehavior.java | 1 + .../minecraft/create/trainperspective/mixin/CameraMixin.java | 4 ++-- .../create/trainperspective/mixin/PlayerRendererMixin.java | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java index 1b39cfc..c20ce51 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java @@ -6,4 +6,5 @@ public interface PlayerPerspectiveBehavior { void setLean(float lean); void setYaw(float yaw); float getLean(); + float getYaw(); } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java index eac46d6..60fdd59 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java @@ -50,8 +50,8 @@ public void modifyRotationsPrimary(Camera instance, float y, float x) { if(entity instanceof LocalPlayer player) { var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); ctp$setRotation3D(y, - x + persp.getLean() * Mth.cos(y * Mth.DEG_TO_RAD), - 360.0f - (persp.getLean() * Mth.sin(y * Mth.DEG_TO_RAD))); + x - persp.getLean() * Mth.sin((persp.getYaw() - y) * Mth.DEG_TO_RAD), + persp.getLean() * Mth.cos((persp.getYaw() - y) * Mth.DEG_TO_RAD)); } else setRotation(y, x); } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java index e35508f..f9c0dd9 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java @@ -43,6 +43,10 @@ public class PlayerRendererMixin { return ctp$lean; } + public float ctp$getYaw() { + return ctp$yaw; + } + @Inject( method = "setupRotations(Lnet/minecraft/client/player/AbstractClientPlayer;Lcom/mojang/blaze3d/vertex/PoseStack;FFF)V", at = @At(