From 411eaa4ca8bb5f4975d90e94ed79fc0573fd5e81 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Tue, 17 Aug 2021 19:10:48 +0200 Subject: [PATCH] Fix spectator hand jumping when rotating across 0 yaw boundary The `yaw` value of non-client-players is constraint to [0; 360), so when that boundary is crossed, the `renderYaw` starts interpolating to its goal the incorrect way round (instead of crossing the 360 boundary as well). Instead we now use the `headYaw` value, which does not wrap around and as such does not have this issue. --- .../com/replaymod/replay/camera/CameraEntity.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/replaymod/replay/camera/CameraEntity.java b/src/main/java/com/replaymod/replay/camera/CameraEntity.java index bb00ae1e..ba1b59e3 100644 --- a/src/main/java/com/replaymod/replay/camera/CameraEntity.java +++ b/src/main/java/com/replaymod/replay/camera/CameraEntity.java @@ -22,6 +22,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.entity.player.PlayerEntity; @@ -248,6 +249,14 @@ public class CameraEntity this.lastRenderX = to.lastRenderX; this.lastRenderY = to.lastRenderY + yOffset; this.lastRenderZ = to.lastRenderZ; + if (to instanceof LivingEntity) { + LivingEntity toLiving = (LivingEntity) to; + this.headYaw = toLiving.headYaw; + this.prevHeadYaw = toLiving.prevHeadYaw; + } else { + this.headYaw = to.yaw; + this.prevHeadYaw = to.prevYaw; + } updateBoundingBox(); } @@ -256,7 +265,7 @@ public class CameraEntity public float getYaw(float tickDelta) { Entity view = this.client.getCameraEntity(); if (view != null && view != this) { - return this.prevYaw + (this.yaw - this.prevYaw) * tickDelta; + return this.prevHeadYaw + (this.headYaw - this.prevHeadYaw) * tickDelta; } return super.getYaw(tickDelta); } @@ -698,7 +707,7 @@ public class CameraEntity this.lastRenderYaw = this.renderYaw; this.lastRenderPitch = this.renderPitch; this.renderPitch = this.renderPitch + (this.pitch - this.renderPitch) * 0.5f; - this.renderYaw = this.renderYaw + (this.yaw - this.renderYaw) * 0.5f; + this.renderYaw = this.renderYaw + (this.headYaw - this.renderYaw) * 0.5f; } public boolean canSpectate(Entity e) {