From 6567d48ea203f69ff7166c034817fcfadf3d4645 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 18 Sep 2024 18:02:59 +0100 Subject: [PATCH] Fixed rendering wackyness when the timer is displayed for timed spells --- .../client/render/spell/SpellRenderer.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/spell/SpellRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/spell/SpellRenderer.java index a1171b7c..be29e501 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/spell/SpellRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/spell/SpellRenderer.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.client.render.spell; +import org.joml.Quaternionf; + import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.Spell; @@ -13,6 +15,8 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.EntityPose; +import net.minecraft.entity.LivingEntity; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RotationAxis; @@ -37,6 +41,8 @@ public class SpellRenderer { private void renderGemstone(MatrixStack matrices, VertexConsumerProvider vertices, T spell, Caster caster, int light, float tickDelta, float animationProgress) { matrices.push(); + float scale = 1/8F; + matrices.scale(scale, scale, scale); transformGemstone(matrices, vertices, spell, caster, animationProgress); matrices.push(); @@ -46,6 +52,22 @@ public class SpellRenderer { matrices.pop(); if (spell instanceof TimedSpell timed) { + if (caster.asEntity() instanceof LivingEntity l && !l.isInPose(EntityPose.SLEEPING)) { + float bodyYaw = MathHelper.lerpAngleDegrees(tickDelta, l.prevBodyYaw, l.bodyYaw); + float headYaw = MathHelper.lerpAngleDegrees(tickDelta, l.prevHeadYaw, l.headYaw); + float yawDifference = headYaw - bodyYaw; + if (l.hasVehicle() && l.getVehicle() instanceof LivingEntity vehicle) { + bodyYaw = MathHelper.lerpAngleDegrees(tickDelta, vehicle.prevBodyYaw, vehicle.bodyYaw); + yawDifference = headYaw - bodyYaw; + float clampedYawDifference = MathHelper.clamp(MathHelper.wrapDegrees(yawDifference), -85, 85); + bodyYaw = headYaw - clampedYawDifference; + if (clampedYawDifference * clampedYawDifference > 2500) { + bodyYaw += clampedYawDifference * 0.2F; + } + yawDifference = headYaw - bodyYaw; + } + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180 - bodyYaw)); + } renderCountdown(matrices, timed, tickDelta); } @@ -53,7 +75,7 @@ public class SpellRenderer { } protected void renderCountdown(MatrixStack matrices, TimedSpell spell, float tickDelta) { - matrices.multiply(client.getEntityRenderDispatcher().getRotation().invert()); + matrices.multiply(client.getEntityRenderDispatcher().getRotation().invert(new Quaternionf())); float radius = 0.6F; float timeRemaining = spell.getTimer().getPercentTimeRemaining(tickDelta); @@ -67,6 +89,6 @@ public class SpellRenderer { if (caster.asEntity() instanceof CastSpellEntity) { y = 1F; } - matrices.translate(0, y + MathHelper.sin(animationProgress / 3F) * 0.2F, 0); + matrices.translate(0, y * 8 + MathHelper.sin(animationProgress / 3F) * 0.2F, 0); } }