From 7b78cbc49c905ace8c8e806cca5ad77430f46d3b Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 7 Feb 2024 12:54:23 +0000 Subject: [PATCH] Magic shields now use the pony's horn colour and change shape when extending --- .../ability/magic/spell/effect/ShieldSpell.java | 11 +++++++++-- .../unicopia/client/minelittlepony/Main.java | 6 ++++++ .../client/minelittlepony/MineLPDelegate.java | 4 ++++ .../client/render/spell/ShieldSpellRenderer.java | 14 +++++++++++--- 4 files changed, 30 insertions(+), 5 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 22fd5b47..23ceb121 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 @@ -11,11 +11,13 @@ import com.minelittlepony.unicopia.ability.magic.spell.Situation; import com.minelittlepony.unicopia.ability.magic.spell.Spell; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; +import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.particle.LightningBoltParticleEffect; import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.particle.ParticleUtils; import com.minelittlepony.unicopia.projectile.ProjectileUtil; +import com.minelittlepony.unicopia.util.ColorHelper; import com.minelittlepony.unicopia.util.Lerp; import com.minelittlepony.unicopia.util.shape.Sphere; @@ -67,13 +69,18 @@ public class ShieldSpell extends AbstractSpell { protected void generateParticles(Caster source) { Vec3d origin = getOrigin(source); - source.spawnParticles(origin, new Sphere(true, radius.getValue()), (int)(radius.getValue() * 6), pos -> { - source.addParticle(new MagicParticleEffect(getType().getColor()), pos, Vec3d.ZERO); + source.spawnParticles(origin, new Sphere(true, radius.getValue()), (int)(radius.getValue() * 2), pos -> { + int hornColor = MineLPDelegate.getInstance().getMagicColor(source.getOriginatingCaster().asEntity()); + source.addParticle(new MagicParticleEffect(ColorHelper.lerp(0.6F, getType().getColor(), hornColor)), pos, Vec3d.ZERO); if (source.asWorld().random.nextInt(10) == 0 && source.asWorld().random.nextFloat() < source.getCorruption().getScaled(1)) { ParticleUtils.spawnParticle(source.asWorld(), new LightningBoltParticleEffect(true, 3, 2, 0.1F, Optional.empty()), pos, Vec3d.ZERO); } }); + + if (source.asWorld().random.nextInt(20) == 0 || !rangeMultiplier.isFinished() || !radius.isFinished()) { + source.asEntity().playSound(USounds.SPELL_CAST_SUCCESS, 0.05F, 1.5F); + } } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java index 4757d7a3..1f6537c3 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java @@ -10,6 +10,7 @@ import com.minelittlepony.api.model.*; import com.minelittlepony.api.model.fabric.PonyModelPrepareCallback; import com.minelittlepony.api.model.gear.IGear; import com.minelittlepony.api.pony.IPony; +import com.minelittlepony.api.pony.IPonyData; import com.minelittlepony.unicopia.*; import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation; import com.minelittlepony.unicopia.compat.trinkets.TrinketsDelegate; @@ -93,6 +94,11 @@ public class Main extends MineLPDelegate implements ClientModInitializer { } + @Override + public int getMagicColor(Entity entity) { + return IPony.getManager().getPony(entity).map(IPony::metadata).map(IPonyData::getGlowColor).orElse(0); + } + @Override public Race getPlayerPonyRace(PlayerEntity player) { return toUnicopiaRace(IPony.getManager().getPony(player).race()); diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPDelegate.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPDelegate.java index 24de4ba0..366ef579 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPDelegate.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPDelegate.java @@ -31,4 +31,8 @@ public class MineLPDelegate { public Race getRace(Entity entity) { return Race.HUMAN; } + + public int getMagicColor(Entity entity) { + return 0; + } } 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 c3f2e7fb..aa96a28f 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 @@ -4,6 +4,7 @@ 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.minelittlepony.MineLPDelegate; import com.minelittlepony.unicopia.client.render.RenderLayers; import com.minelittlepony.unicopia.client.render.model.SphereModel; import com.minelittlepony.unicopia.util.ColorHelper; @@ -26,8 +27,14 @@ public class ShieldSpellRenderer extends SpellRenderer { double height = caster.asEntity().getEyeY() - caster.getOriginVector().y; matrices.translate(0, height, 0); - int color = ColorHelper.lerp(caster.getCorruption().getScaled(1) * (tickDelta / (1 + caster.asWorld().random.nextFloat())), spell.getType().getColor(), 0xFF000); - float[] colors = ColorHelper.changeSaturation(Color.r(color), Color.g(color), Color.b(color), 4); + int typeColor = spell.getType().getColor(); + int ponyColor = MineLPDelegate.getInstance().getMagicColor(caster.getOriginatingCaster().asEntity()); + + int color = ColorHelper.lerp(caster.getCorruption().getScaled(1) * (tickDelta / (1 + caster.asWorld().random.nextFloat())), + ponyColor == 0 ? typeColor : ColorHelper.lerp(0.6F, ponyColor, typeColor), + 0xFF000 + ); + float[] colors = ColorHelper.changeSaturation(Color.r(color), Color.g(color), Color.b(color), 2); float radius = 0.35F + spell.getRadius(tickDelta) + MathHelper.sin(animationProgress / 30F) * 0.01F; VertexConsumer buffer = vertices.getBuffer(RenderLayers.getMagicShield()); @@ -35,7 +42,7 @@ public class ShieldSpellRenderer extends SpellRenderer { 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; + float alpha = 1 - Math.abs(MathHelper.sin(animationProgress / 20F)) * 0.1F; alpha *= MathHelper.clamp(radius - 1, 0, 1); if (firstPerson) { @@ -44,6 +51,7 @@ public class ShieldSpellRenderer extends SpellRenderer { model.render(matrices, buffer, light, 1, radius, colors[0], colors[1], colors[2], alpha * 0.2F); } else { matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(180)); + matrices.scale(1, radius == 0 ? 1 : 2.6F / radius, 1); 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);