Fix decay animation and improve rendering a little

This commit is contained in:
Sollace 2024-04-08 17:49:44 +01:00
parent b84f1f046b
commit 978b5e9854
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 28 additions and 33 deletions

View file

@ -98,7 +98,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS
@Override @Override
public boolean isDead() { public boolean isDead() {
return dead && deathTicks <= 0; return dead && deathTicks <= 0 && super.isDead();
} }
@Override @Override

View file

@ -164,7 +164,7 @@ public class DarkVortexSpell extends AbstractSpell implements ProjectileDelegate
} }
}); });
if (!source.subtractEnergyCost(accumulatedMass * 0.001)) { if (!source.subtractEnergyCost(0.01)) {
setDead(); setDead();
source.asWorld().createExplosion(source.asEntity(), origin.x, origin.y, origin.z, 3, ExplosionSourceType.NONE); source.asWorld().createExplosion(source.asEntity(), origin.x, origin.y, origin.z, 3, ExplosionSourceType.NONE);
} }
@ -175,7 +175,7 @@ public class DarkVortexSpell extends AbstractSpell implements ProjectileDelegate
@Override @Override
public void tickDying(Caster<?> source) { public void tickDying(Caster<?> source) {
accumulatedMass /= 2D; accumulatedMass *= 0.8F;
double mass = getMass() * 0.1; double mass = getMass() * 0.1;
double logarithm = 1 - (1D / (1 + (mass * mass))); double logarithm = 1 - (1D / (1 + (mass * mass)));
radius.update((float)Math.max(0.1, logarithm * source.asWorld().getGameRules().getInt(UGameRules.MAX_DARK_VORTEX_SIZE)), 200L); radius.update((float)Math.max(0.1, logarithm * source.asWorld().getGameRules().getInt(UGameRules.MAX_DARK_VORTEX_SIZE)), 200L);

View file

@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.DarkVortexSpell;
import com.minelittlepony.unicopia.client.render.RenderLayers; import com.minelittlepony.unicopia.client.render.RenderLayers;
import com.minelittlepony.unicopia.client.render.model.PlaneModel; import com.minelittlepony.unicopia.client.render.model.PlaneModel;
import com.minelittlepony.unicopia.client.render.model.SphereModel; import com.minelittlepony.unicopia.client.render.model.SphereModel;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera; import net.minecraft.client.render.Camera;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
@ -16,6 +17,7 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis; import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
public class DarkVortexSpellRenderer extends SpellRenderer<DarkVortexSpell> { public class DarkVortexSpellRenderer extends SpellRenderer<DarkVortexSpell> {
@ -38,12 +40,15 @@ public class DarkVortexSpellRenderer extends SpellRenderer<DarkVortexSpell> {
public void render(MatrixStack matrices, VertexConsumerProvider vertices, DarkVortexSpell spell, Caster<?> caster, int light, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) { public void render(MatrixStack matrices, VertexConsumerProvider vertices, DarkVortexSpell spell, Caster<?> caster, int light, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
Camera camera = MinecraftClient.getInstance().gameRenderer.getCamera(); Camera camera = MinecraftClient.getInstance().gameRenderer.getCamera();
Vec3d ray = camera.getPos().subtract(spell.getOrigin(caster));
float radius = (float)spell.getEventHorizonRadius(); float radius = (float)spell.getEventHorizonRadius();
float absDistance = (float)camera.getPos().distanceTo(spell.getOrigin(caster)); float absDistance = (float)ray.length();
matrices.push(); matrices.push();
matrices.translate(0, spell.getYOffset(), 0); matrices.translate(0, spell.getYOffset(), 0);
matrices.multiply(RotationAxis.NEGATIVE_Y.rotationDegrees(-caster.asEntity().getYaw()));
float visualRadius = Math.min(radius * 0.8F, absDistance - 1F); float visualRadius = Math.min(radius * 0.8F, absDistance - 1F);
@ -53,11 +58,6 @@ public class DarkVortexSpellRenderer extends SpellRenderer<DarkVortexSpell> {
SphereModel.SPHERE.render(matrices, vertices.getBuffer(RenderLayers.getMagicColored()), light, 1, visualRadius + 0.15F, 0, 0, 0, 0.9F); SphereModel.SPHERE.render(matrices, vertices.getBuffer(RenderLayers.getMagicColored()), light, 1, visualRadius + 0.15F, 0, 0, 0, 0.9F);
matrices.push(); matrices.push();
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(90));
matrices.multiply(RotationAxis.NEGATIVE_X.rotationDegrees(90 + camera.getYaw()));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-camera.getPitch()));
matrices.scale(0.7F, 1, 1);
float distance = 1F / MathHelper.clamp(absDistance / (radius + 7), 0.0000001F, 1); float distance = 1F / MathHelper.clamp(absDistance / (radius + 7), 0.0000001F, 1);
distance *= distance; distance *= distance;
@ -67,46 +67,41 @@ public class DarkVortexSpellRenderer extends SpellRenderer<DarkVortexSpell> {
SphereModel.DISK.render(matrices, vertices.getBuffer(RenderLayers.getEndPortal()), light, 1, radius * 0.5F, 0, 0, 0, 0); SphereModel.DISK.render(matrices, vertices.getBuffer(RenderLayers.getEndPortal()), light, 1, radius * 0.5F, 0, 0, 0, 0);
matrices.push();
matrices.scale(distance, distance, distance);
if (absDistance > radius) {
matrices.push();
matrices.translate(0, -0.1F, 0);
for (int i = 0; i < 10; i++) {
float brightness = i / 10F;
SphereModel.DISK.render(matrices, vertices.getBuffer(RenderLayers.getMagicNoColor()), light, 1, radius * (1 + (0.25F * i)) * 0.7F, brightness, brightness, brightness, 0.2F);
}
matrices.pop();
}
matrices.pop();
if (radius > 0.3F && absDistance > radius) { if (radius > 0.3F && absDistance > radius) {
double g = Math.sqrt(ray.x * ray.x + ray.z * ray.z);
float pitch = MathHelper.wrapDegrees((float)(-(MathHelper.atan2(ray.y, g) * 180.0F / (float)Math.PI)));
float yaw = MathHelper.wrapDegrees((float)(MathHelper.atan2(ray.z, ray.x) * 180.0F / (float)Math.PI) - 90.0F);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(caster.asEntity().getYaw()));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-yaw));
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-pitch));
radius *= Math.min(2, 3 + radius); radius *= Math.min(2, 3 + radius);
float processionSpeed = animationProgress * 0.02F; float processionSpeed = animationProgress * 0.02F;
float maxProcessionAngle = 15; float maxProcessionAngle = 15;
float cosProcession = MathHelper.cos(processionSpeed);
float sinProcession = MathHelper.sin(processionSpeed);
float range = (float)spell.getDrawDropOffRange() / 8F; float range = (float)spell.getDrawDropOffRange() / 8F;
matrices.scale(range, range, range); matrices.scale(range, range, range);
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(90 + MathHelper.cos(processionSpeed) * maxProcessionAngle));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(MathHelper.sin(processionSpeed) * maxProcessionAngle)); matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(cosProcession * maxProcessionAngle));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(sinProcession * maxProcessionAngle));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(animationProgress * 18)); matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(animationProgress * 18));
VertexConsumer buffer = vertices.getBuffer(RenderLayer.getEntityTranslucent(ACCRETION_DISK_TEXTURE)); VertexConsumer buffer = vertices.getBuffer(RenderLayer.getEntityTranslucent(ACCRETION_DISK_TEXTURE));
PlaneModel.INSTANCE.render(matrices, buffer, light, 0, 1, 1, 1, 1, 1); PlaneModel.INSTANCE.render(matrices, buffer, light, 0, 1, 1, 1, 1, 1);
float secondaryScale = 0.9F + cosProcession * 0.3F;
matrices.translate(0, 0, 0.0001F);
matrices.scale(secondaryScale, secondaryScale, secondaryScale);
matrices.scale(0.9F, 0.9F, 0.9F);
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(33)); matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(33));
PlaneModel.INSTANCE.render(matrices, buffer, light, 0, 1, 1, 1, 1, 1); PlaneModel.INSTANCE.render(matrices, buffer, light, 0, 1, 1, 1, 1, 1);
matrices.translate(0, 0, 0.0001F);
matrices.scale(0.9F, 0.9F, 0.9F); matrices.scale(0.9F, 0.9F, 0.9F);
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(33)); matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(33));
PlaneModel.INSTANCE.render(matrices, buffer, light, 0, 1, 1, 1, 1, 1); PlaneModel.INSTANCE.render(matrices, buffer, light, 0, 1, 1, 1, 1, 1);