From 9e329ac2f92d1b8cbacbd297eb389a47b4c5a820 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 25 Mar 2024 19:57:21 +0000 Subject: [PATCH] #314 Reduce camera motion and apply the client setting for fov scale to the flight camera --- .../unicopia/entity/player/PlayerCamera.java | 40 ++++++++++--------- .../mixin/client/MixinGameRenderer.java | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java index 26c6d4c7..61effece 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java @@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.ability.magic.SpellPredicate; import com.minelittlepony.unicopia.ability.magic.spell.AbstractDisguiseSpell; import com.minelittlepony.unicopia.client.render.spell.DarkVortexSpellRenderer; +import net.minecraft.client.MinecraftClient; import net.minecraft.util.math.Vec3d; public class PlayerCamera extends MotionCompositor { @@ -18,30 +19,28 @@ public class PlayerCamera extends MotionCompositor { } public float calculateRoll() { + return player.getInterpolator().interpolate("roll", (float)applyModifiers(-getMotionRoll()), 15); + } - double roll = 0; + public float calculateFirstPersonRoll() { + return player.getInterpolator().interpolate("roll_fp", (float)applyModifiers(-getMotionRoll() * getFovScale() * 0.25F), 25); + } - if (player.getMotion().isFlying()) { - Vec3d vel = player.asEntity().getVelocity(); - - roll -= calculateRoll(player.asEntity(), vel.x, vel.y, vel.z); - } - - if (player.getPhysics().isGravityNegative()) { - roll *= -1; - roll += 180; - } - - if (player.asEntity().age > 10) { - roll = player.getInterpolator().interpolate("roll", (float)roll, 15); + private double getMotionRoll() { + if (!player.getMotion().isFlying() || player.asEntity().hasVehicle() || player.asEntity().isOnGround()) { + return 0; } + Vec3d vel = player.asEntity().getVelocity(); + return calculateRoll(player.asEntity(), vel.x, vel.y, vel.z); + } + private double applyModifiers(double motionRoll) { if (player.getAcrobatics().isFloppy()) { - roll += 90; + motionRoll += 90; } - return (float)roll; + return player.getPhysics().isGravityNegative() ? 180 - motionRoll : motionRoll; } public float calculatePitch(float pitch) { @@ -61,13 +60,16 @@ public class PlayerCamera extends MotionCompositor { } public double calculateFieldOfView(double fov) { - fov += player.getMagicalReserves().getExertion().get() / 5F; - fov += getEnergyAddition(); + fov += (player.getMagicalReserves().getExertion().get() / 5F) * getFovScale(); + fov += getEnergyAddition() * getFovScale(); fov += DarkVortexSpellRenderer.getCameraDistortion() * 2.5F; - return fov; } + private float getFovScale() { + return MinecraftClient.getInstance().options.getFovEffectScale().getValue().floatValue(); + } + protected float getEnergyAddition() { int maxE = (int)Math.floor(player.getMagicalReserves().getEnergy().get() * 100); diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java index d71373fb..2fe4abe2 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java @@ -36,7 +36,7 @@ abstract class MixinGameRenderer implements AutoCloseable, SynchronousResourceRe @Inject(method = "renderWorld(FJLnet/minecraft/client/util/math/MatrixStack;)V", at = @At("HEAD")) private void beforeRenderWorld(float tickDelta, long limitTime, MatrixStack matrices, CallbackInfo info) { - UnicopiaClient.getCamera().ifPresent(c -> matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(c.calculateRoll()))); + UnicopiaClient.getCamera().ifPresent(c -> matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(c.calculateFirstPersonRoll()))); BatEyesApplicator.INSTANCE.enable(); }