From bbe9eb00680897089e46fe6f690c6a83c2191598 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 25 Jan 2024 22:58:40 +0000 Subject: [PATCH] Fix shields not rendering in first person and change shields to be a semi-circle (since the rest will just clip into the ground) --- .../magic/spell/effect/ShieldSpell.java | 15 ++++++++++++- .../render/AccessoryFeatureRenderer.java | 4 ++++ .../render/spell/ShieldSpellRenderer.java | 21 ++++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java index 023da1c7..5ad19d2d 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java @@ -49,6 +49,9 @@ public class ShieldSpell extends AbstractSpell { private float rangeMultiplier; private float targetRangeMultiplier; + private int prevTicksDying; + private int ticksDying; + protected ShieldSpell(CustomisedSpellType type) { super(type); } @@ -102,6 +105,14 @@ public class ShieldSpell extends AbstractSpell { return !isDead(); } + @Override + public void tickDying(Caster caster) { + prevTicksDying = ticksDying; + if (ticksDying++ > 25) { + super.tickDying(caster); + } + } + protected void consumeManage(Caster source, long costMultiplier, float knowledge) { double cost = 2 - source.getLevel().getScaled(2); @@ -115,7 +126,9 @@ public class ShieldSpell extends AbstractSpell { } public float getRadius(float tickDelta) { - return MathHelper.lerp(tickDelta, prevRadius, radius); + float base = MathHelper.lerp(tickDelta, prevRadius, radius); + float scale = MathHelper.clamp(MathHelper.lerp(tickDelta, prevTicksDying, ticksDying), 0, 1); + return base * scale; } /** diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/AccessoryFeatureRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/AccessoryFeatureRenderer.java index 857e4c96..16261ff6 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/AccessoryFeatureRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/AccessoryFeatureRenderer.java @@ -57,6 +57,10 @@ public class AccessoryFeatureRenderer< } public boolean beforeRenderArms(ArmRenderer sender, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, T entity, int light) { + Caster caster = Caster.of(entity).orElse(null); + if (caster != null) { + SpellEffectsRenderDispatcher.INSTANCE.render(matrices, vertexConsumers, light, caster, 0, 0, tickDelta, entity.age + tickDelta, 0, 0); + } boolean cancelled = false; for (var feature : features) { cancelled |= feature.beforeRenderArms(sender, tickDelta, matrices, vertexConsumers, entity, light); diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/spell/ShieldSpellRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/spell/ShieldSpellRenderer.java index 8ce41089..260b322c 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/spell/ShieldSpellRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/spell/ShieldSpellRenderer.java @@ -3,16 +3,21 @@ package com.minelittlepony.unicopia.client.render.spell; import com.minelittlepony.common.util.Color; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.effect.ShieldSpell; +import com.minelittlepony.unicopia.client.gui.DrawableUtil; import com.minelittlepony.unicopia.client.render.RenderLayers; import com.minelittlepony.unicopia.client.render.model.SphereModel; import com.minelittlepony.unicopia.util.ColorHelper; +import net.minecraft.client.option.Perspective; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.RotationAxis; public class ShieldSpellRenderer extends SpellRenderer { + private final SphereModel model = new SphereModel(40, 40, DrawableUtil.PI); + @Override public void render(MatrixStack matrices, VertexConsumerProvider vertices, ShieldSpell spell, Caster caster, int light, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) { super.render(matrices, vertices, spell, caster, light, limbAngle, limbDistance, tickDelta, animationProgress, headYaw, headPitch); @@ -27,11 +32,21 @@ public class ShieldSpellRenderer extends SpellRenderer { VertexConsumer buffer = vertices.getBuffer(RenderLayers.getMagicShield()); + boolean firstPerson = caster.asEntity() == client.player && client.options.getPerspective() == Perspective.FIRST_PERSON; + float thickness = 0.02F * MathHelper.sin(animationProgress / 30F); float alpha = 1 - Math.abs(MathHelper.sin(animationProgress / 20F)) * 0.2F; - SphereModel.SPHERE.render(matrices, buffer, light, 1, radius + thickness, colors[0], colors[1], colors[2], alpha * 0.08F); - SphereModel.SPHERE.render(matrices, buffer, light, 1, radius - thickness, colors[0], colors[1], colors[2], alpha * 0.05F); - SphereModel.SPHERE.render(matrices, buffer, light, 1, radius + thickness * 2, colors[0], colors[1], colors[2], alpha * 0.05F); + + if (firstPerson) { + matrices.translate(0, -1.75F, 0); + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(client.cameraEntity.getPitch(tickDelta))); + model.render(matrices, buffer, light, 1, radius, colors[0], colors[1], colors[2], alpha * 0.2F); + } else { + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(180)); + model.render(matrices, buffer, light, 1, radius + thickness, colors[0], colors[1], colors[2], alpha * 0.08F); + model.render(matrices, buffer, light, 1, radius - thickness, colors[0], colors[1], colors[2], alpha * 0.05F); + model.render(matrices, buffer, light, 1, radius + thickness * 2, colors[0], colors[1], colors[2], alpha * 0.05F); + } matrices.pop(); }