Skip to content

Commit

Permalink
Fix shields not rendering in first person and change shields to be a …
Browse files Browse the repository at this point in the history
…semi-circle (since the rest will just clip into the ground)
  • Loading branch information
Sollace committed Jan 25, 2024
1 parent 885bf6d commit bbe9eb0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -102,6 +105,14 @@ public boolean tick(Caster<?> source, Situation situation) {
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);

Expand All @@ -115,7 +126,9 @@ protected void consumeManage(Caster<?> source, long costMultiplier, float knowle
}

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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public void renderArm(MatrixStack matrices, VertexConsumerProvider vertexConsume
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
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<ShieldSpell> {
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);
Expand All @@ -27,11 +32,21 @@ public void render(MatrixStack matrices, VertexConsumerProvider vertices, Shield

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();
}
Expand Down

0 comments on commit bbe9eb0

Please sign in to comment.